From f6d7dbd2ac6938526b1023d1bc571d562b4625cf Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期四, 17 九月 2020 15:16:51 +0800 Subject: [PATCH] minditance --- test/test_right_walk3 | 0 test/Makefile | 2 +- algorithm/include/graph.h | 7 +++++++ test/test_right_walk3.c | 15 ++++++++------- algorithm/include/IndirectAlg.h | 9 ++++++--- Makefile | 1 + algorithm/IndirectAlg.c | 12 +++++++----- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index ab4678d..409457f 100755 --- a/Makefile +++ b/Makefile @@ -34,3 +34,4 @@ cp README.md basic_pack cp test/test_right_walk2.c basic_pack tar -czvf $(tarname) basic_pack + rm -rf basic_pack diff --git a/algorithm/IndirectAlg.c b/algorithm/IndirectAlg.c index f9a3d51..f0bc6a4 100644 --- a/algorithm/IndirectAlg.c +++ b/algorithm/IndirectAlg.c @@ -1,6 +1,7 @@ #include "usg_common.h" #include "IndirectAlg.h" #include "graph.h" + #define PI 3.14159265 @@ -32,15 +33,15 @@ IndirectAlg::IndirectAlg() {} -IndirectAlg::IndirectAlg(const initializer_list<Edge> & edges, const time_t & _keepTime, const Vector2 & _direction): - frame(edges), keepTime(_keepTime), direction(_direction), mterminate(false) { +IndirectAlg::IndirectAlg(const initializer_list<Edge> & edges,const Vector2 & _direction, const time_t & _keepTime, const double _minDistance): + frame(edges), keepTime(_keepTime), minDistance(_minDistance), direction(_direction), mterminate(false) { mthread = std::thread(std::bind(&IndirectAlg::threadRoutine, this)); } -IndirectAlg::IndirectAlg(const initializer_list<Point> & points, const time_t & _keepTime, const Vector2 & _direction): - keepTime(_keepTime), direction(_direction), mterminate(false) { +IndirectAlg::IndirectAlg(const initializer_list<Point> & points, const Vector2 & _direction, const time_t & _keepTime, const double _minDistance): + keepTime(_keepTime), minDistance(_minDistance), direction(_direction), mterminate(false) { if (points.size() > 0) { std::vector<Edge> edges; initializer_list<Point>::iterator iter; @@ -151,7 +152,8 @@ status->lastCoordinate = record.coordinate; } - if (currentDirection.x == 0 && currentDirection.y == 0) { + + if (getVecor2Len(currentDirection) <= minDistance) { //娌″姩 printRecord(3, record); return false; diff --git a/algorithm/include/IndirectAlg.h b/algorithm/include/IndirectAlg.h index 5d9beba..e16caff 100644 --- a/algorithm/include/IndirectAlg.h +++ b/algorithm/include/IndirectAlg.h @@ -15,8 +15,11 @@ Figure frame; - //閫嗚鎸佺画鏃堕棿锛岃瓒呰繃杩欎釜鏃堕棿鎵嶇畻閫嗚 + + // 閫嗚鎸佺画鏃堕棿锛岃瓒呰繃杩欎釜鏃堕棿鎵嶇畻閫嗚 time_t keepTime; + // 鏈�灏忕Щ鍔ㄨ窛绂伙紝瑕佽秴杩囪繖涓窛绂绘墠绠楃Щ鍔� + double minDistance; // 浠h〃姝g‘琛岃蛋鏂瑰悜鐨勫悜閲� Vector2 direction; // 鐘舵�佺紦瀛� @@ -29,13 +32,13 @@ public: IndirectAlg(); - IndirectAlg(const std::initializer_list<Edge> & edges, const time_t & _keepTime, const Vector2 & _direction); + IndirectAlg(const std::initializer_list<Edge> & edges, const Vector2 & _directionconst , const time_t & _keepTime, const double _minDistance); /** * @points 缁勬垚瑙傛祴鍖哄煙鐨勫郊姝ょ浉閭荤殑鐐� * @_keepTime 淇濇寔鏃堕棿 * @_direction 姝g‘琛岃繘鐨勬柟鍚戞柟鍚� */ - IndirectAlg(const std::initializer_list<Point> & points, const time_t & _keepTime, const Vector2 & _direction); + IndirectAlg(const std::initializer_list<Point> & points, const Vector2 & _direction, const time_t & _keepTime, const double _minDistance); ~IndirectAlg(); diff --git a/algorithm/include/graph.h b/algorithm/include/graph.h index 4d35724..9c5682b 100644 --- a/algorithm/include/graph.h +++ b/algorithm/include/graph.h @@ -2,6 +2,7 @@ #define __USG_GRAPH_H__ #include "usg_common.h" +#include <cmath> struct Point { //public: @@ -62,4 +63,10 @@ return {b.x - a.x, b.y - a.y}; } +static inline double getVecor2Len(Vector2& v) { + return sqrt(v.x * v.x + v.y * v.y); +} + + + #endif diff --git a/test/Makefile b/test/Makefile index 692c838..b19d5c5 100755 --- a/test/Makefile +++ b/test/Makefile @@ -8,7 +8,7 @@ include $(ROOT)/Make.defines.$(PLATFORM) -PROGS = test_right_walk test_right_walk3 +PROGS = test_right_walk3 diff --git a/test/test_right_walk3 b/test/test_right_walk3 index 245a40d..f97cc80 100755 --- a/test/test_right_walk3 +++ b/test/test_right_walk3 Binary files differ diff --git a/test/test_right_walk3.c b/test/test_right_walk3.c index 9b97b1c..5fbd59b 100644 --- a/test/test_right_walk3.c +++ b/test/test_right_walk3.c @@ -45,11 +45,13 @@ 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 姝g‘琛岃繘鐨勬柟鍚戞柟鍚� + * @points 缁勬垚瑙傛祴鍖哄煙鐨勫郊姝ょ浉閭荤殑鐐� + * @_direction 姝g‘琛岃繘鐨勬柟鍚戞柟鍚� + * @_keepTime 淇濇寔鏃堕棿 + * @ minDistance 鏈�灏忕Щ鍔ㄨ窛绂� */ - 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}); + IndirectAlg indirectAlg((std::initializer_list<Point>){{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 1000.0}, {0.0, 1000.0} }, + {1, 1}, 5, 1); int i = 0; // time_t start_time; @@ -94,7 +96,7 @@ void test3() { - std::ifstream fin("test3.txt"); + std::ifstream fin("test.txt"); char line[1024]; //std::string line; char *targetIdStr; @@ -107,7 +109,7 @@ //{"x":148,"y":45},{"x":148,"y":539},{"x":769,"y":539},{"x":769,"y":45} //{148, 45}, {148, 539}, {769, 539}, {769, 45} Record record; - IndirectAlg indirectAlg((std::initializer_list<Point>){}, 3, {621, 0}); + IndirectAlg indirectAlg((std::initializer_list<Point>){}, {621, 0}, 3, 0); // const char *delim = " "; while(fin.getline(line, 1024)) { @@ -152,7 +154,6 @@ // printf("key = %s, value=%s\n", key, value); } fin.close(); - sleep(30); } -- Gitblit v1.8.0