编辑 | blame | 历史 | 原始文档

逆行算法调用说明

1. 代码调用

 /**
 * 第一个参数@points  组成观测区域的彼此相邻的点
 * 第二个参数@_keepTime 保持时间
 * 第三个参数@_direction 正确行进的方向方向
 */
IndirectAlg indirectAlg((std::initializer_list<Point>){{0.0, 0.0}, {1000.0, 0.0},  {1000.0, 1000.0}, {0.0, 1000.0} }, 5, {1, 1});

//因为数据时流数据,下面的调用应该时在一个循环里面,处理完一条接着处理下一条
//构建传入的数据
Record record;
record.id = 1; //目标ID 
record.timestamp = time(0); //时间戳
record.coordinate = {2.0, 3.0}; // 坐标
//判断是否逆行
indirectAlg.isRetrograde(record)
    

2 测试用例

test_right_walk2.c

#include <usg_common.h>        /* cos */
#include <graph.h>
#include <IndirectAlg.h>
using namespace std;

int test2() {
    // IndirectAlg indirectAlg({  {{0.0, 0.0}, {1000.0, 0.0}}, {{1000.0, 0.0}, {1000.0, 1000.0}}, {{1000.0, 1000.0}, {0.0, 1000.0}}, {{0.0, 1000.0}, {0.0, 0.0}} }, 5, {1, 1});
    /**
     * 第一个参数@points  组成观测区域的彼此相邻的点
     * 第二个参数@_keepTime 保持时间
     * 第三个参数@_direction 正确行进的方向方向
     */
    IndirectAlg indirectAlg((std::initializer_list<Point>){{0.0, 0.0}, {1000.0, 0.0},  {1000.0, 1000.0}, {0.0, 1000.0} }, 5, {1, 1});
    
    int i = 0;
    // time_t start_time;
    srand((unsigned) time(0));

    double rx, ry;
    bool isRetrograde;
    //起点
    Point start = {0, 0};
    //传入的流数据记录信息Record 
    Record record;
    record.id = 1; //目标ID 
    record.timestamp = time(0); //时间戳
    record.coordinate = start; // 坐标
    // time(&start_time);
    //判断是否逆行
    while(!(isRetrograde = indirectAlg.isRetrograde(record)) ) {
        rx = ((double)(rand()%10))/100000;
        ry = ((double)(rand()%10))/100000;

        //std::cout << timestamp << ":" <<  << "isRetrograde" << isRetrograde;
       // err_msg(0, "%ld : {%f, %f}  %d\n", record.timestamp, record.coordinate.x, record.coordinate.y, isRetrograde);
        record.timestamp = time(0);
        
        //if (difftime(time(0), start_time) > 1)
        if (i > 10)
        {
            record.coordinate = {record.coordinate.x - rx , record.coordinate.y - ry};
        } else {
            record.coordinate = {record.coordinate.x + rx , record.coordinate.y + ry};
        }

        if (i > 100)
            break;

        sleep(1);
        i++;
    }
    printf("return %ld : {%f, %f}  %d\n", record.timestamp, record.coordinate.x, record.coordinate.y, isRetrograde);
    return 0;
}


int main() {
    test2();

}

3 编译

安装好so包后,用如下的方式编译,alg是逆行算法包,usgcommon是算法用的的公共包,pthread是系统的线程包
g++ -std=c++11 test_right_walk2.c -o test_right_walk2 -lalg -lusgcommon -lpthread

README 3 KB
test/test 4 KB
test/test2 3 KB
test/test3 71 b