From 0820c9f0ffa19ba234bcc6858961c9e824f0ffa9 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期四, 16 四月 2020 18:10:26 +0800 Subject: [PATCH] 科目三 --- lib/src/main/cpp/test_items2/road_exam.cpp | 209 +++++++++++++++++++++++++++++++++++++++++ lib/src/main/cpp/driver_test.h | 47 +++++++++ lib/src/main/cpp/test_common/Geometry.cpp | 4 lib/src/main/java/com/anyun/exam/lib/RemoteService.java | 2 4 files changed, 259 insertions(+), 3 deletions(-) diff --git a/lib/src/main/cpp/driver_test.h b/lib/src/main/cpp/driver_test.h index acdb6c2..3ca9f19 100644 --- a/lib/src/main/cpp/driver_test.h +++ b/lib/src/main/cpp/driver_test.h @@ -125,6 +125,53 @@ typedef vector<struct road_exam_map> LIST_ROAD_MAP; +#define ROAD_DOTTED_LINE 0 +#define ROAD_SOLID_LINE 1 + +typedef struct { + int character; // 灞炴�э紙瀹炵嚎銆佽櫄绾匡紝鏈変簺鍙互鎺夊ご鐨勮矾娈碉級 + std::vector<PointF> points; // +} edge_t; + +typedef struct { + int character; // 灞炴�с�婂疄绾裤�佽櫄绾裤�� + std::vector<Polygon> line; // 姣忎竴鏉$嚎 +} separate_t; + +struct road_t { + int id; + Line startLine; + Line stopLine; + int active; // 鍒拌揪璺彛灏鹃儴鐨勮杩涙柟鍚� + string tts; + Polygon area; + std::vector<edge_t> leftEdge; + std::vector<edge_t> rightEdge; + std::vector<separate_t> separate; +}; + +struct special_area_t { + int id; + int road; + int character; + Line startLine; + Polygon area; +}; + +struct trigger2_line_t { + int id; + int road; + int active; + string tts; + Line line; +}; + +struct road_exam2_map { + std::vector<struct road_t> roads; + std::vector<struct special_area_t> specialAreas; + std::vector<struct trigger2_line_t> triggerLines; +}; + struct area_exam_map { int id; int type; diff --git a/lib/src/main/cpp/test_common/Geometry.cpp b/lib/src/main/cpp/test_common/Geometry.cpp index 3b80f09..ca4cd36 100644 --- a/lib/src/main/cpp/test_common/Geometry.cpp +++ b/lib/src/main/cpp/test_common/Geometry.cpp @@ -427,9 +427,9 @@ { double lr = (p1.X-p3.X)*(p2.Y-p3.Y) - (p1.Y-p3.Y)*(p2.X-p3.X); - if (fabs(lr) <= EPSILON) { + if (fabs(lr) <= EPSILON2) { double fb = (p2.X-p1.X)*(p3.X-p1.X) + (p2.Y-p1.Y)*(p3.Y-p1.Y); - if (fabs(fb) <= EPSILON) + if (fabs(fb) <= EPSILON2) return 0; else if (fb > 0) return 2; diff --git a/lib/src/main/cpp/test_items2/road_exam.cpp b/lib/src/main/cpp/test_items2/road_exam.cpp index 1a86093..ee1456b 100644 --- a/lib/src/main/cpp/test_items2/road_exam.cpp +++ b/lib/src/main/cpp/test_items2/road_exam.cpp @@ -33,6 +33,8 @@ START_CAR_DONE }; +static const int INVALID_ROAD = -1; + static const int TURN_THRESHOLD = 1; static const int TURN_CHECK_INTERVAL = 500; const double SLIDE_DISTANCE_THRESHOLD_RED = 0.3; @@ -981,5 +983,212 @@ } return -1; } +#if 0 +void TestRoadGeneral(struct road_exam2_map &map, const car_model *car, LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime) +{ +} +/************************************************** + * 杞﹁締褰撳墠鎵�鍦ㄨ矾娈碉紝杞﹀ご闇�瓒婅繃璧峰绾夸竴瀹氳窛绂� + * @param currIndex + * @param map + * @param car + */ +static void EnterRoad(int &currIndex, struct road_exam2_map &map, const car_model *car) +{ + Polygon carBody; + + carBody.num = car->bodyNum; + carBody.point = (PointF *)malloc(carBody.num * sizeof(PointF)); + for (int i = 0; i < carBody.num; ++i) { + carBody.point[i] = car->carXY[car->body[i]]; + } + + Polygon roadArea; + roadArea.num = 0; + roadArea.point = NULL; + + for (int i = 0; i < map.roads.size(); ++i) { + if (roadArea.point != NULL) { + free(roadArea.point); + } + + for (int x = 0; x < map.roads[i].leftEdge.size(); ++x) { + roadArea.num += map.roads[i].leftEdge[x].points.size(); + } + for (int x = 0; x < map.roads[i].rightEdge.size(); ++x) { + roadArea.num += map.roads[i].rightEdge[x].points.size(); + } + roadArea.point = (PointF *) malloc(roadArea.num * sizeof(PointF)); + + int n = 0; + for (int j = 0; j < map.roads[i].leftEdge.size(); j++) { + for (int x = 0; x < map.roads[i].leftEdge[j].points.size(); ++x) { + if (n > 0 && x == 0 && isEqual2(roadArea.point[n-1].X, map.roads[i].leftEdge[j].points[x].X) && + isEqual2(roadArea.point[n-1].Y, map.roads[i].leftEdge[j].points[x].Y)) { + // 绗竴涓偣宸茬粡瀛樺湪浜庝笂涓�鏉$嚎 + } else { + roadArea.point[n++] = map.roads[i].leftEdge[j].points[x]; + } + } + } + for (int j = map.roads[i].rightEdge.size(); j > 0; j--) { + for (int x = map.roads[i].rightEdge[j].points.size(); x > 0; --x) { + if (n > 0 && x == map.roads[i].rightEdge[j].points.size() && + isEqual2(roadArea.point[n-1].X, map.roads[i].rightEdge[j - 1].points[x-1].X) && + isEqual2(roadArea.point[n-1].Y, map.roads[i].rightEdge[j - 1].points[x-1].Y)) { + // 绗竴涓偣宸茬粡瀛樺湪浜庝笂涓�鏉$嚎 + } else { + roadArea.point[n++] = map.roads[i].rightEdge[j - 1].points[x - 1]; + } + } + } + roadArea.num = n; + + if (IntersectionOf(car->carXY[car->axial[AXIAL_FRONT]], &roadArea) == GM_Containment) { + currIndex = i; + goto CHECK_CAR_ON_ROAD_END; + } + } + currIndex = INVALID_ROAD; + + CHECK_CAR_ON_ROAD_END: + if (roadArea.point != NULL) { + free(roadArea.point); + } + free(carBody.point); +} + +/****************************************************** + * 鍏ㄨ溅閮介渶绂诲紑杩欎釜鍖哄煙 + * @param currIndex + * @param map + * @param car + * @return + */ +static bool ExitRoad(int currIndex, struct road_exam2_map &map, const car_model *car) +{ + // 鍏ㄨ溅閮介渶涓嶅湪鍦板浘涓� + bool ret = false; + + if (currIndex == INVALID_ROAD || currIndex >= map.roads.size()) + return ret; + + Polygon roadArea; + + roadArea.num = map.roads[currIndex].leftEdge.size() + map.roads[currIndex].rightEdge.size();; + roadArea.point = (PointF *) malloc(roadArea.num * sizeof(PointF));; + + int n = 0; + for (int j = 0; j < map.roads[currIndex].leftEdge.size(); j++) { + roadArea.point[n++] = map.roads[i].leftEdge[j]; + } + for (int j = map.roads[currIndex].rightEdge.size(); j > 0; j--) { + roadArea.point[n++] = map.roads[i].rightEdge[j - 1]; + } + + Polygon carBody; + + carBody.num = car->bodyNum; + carBody.point = (PointF *)malloc(carBody.num * sizeof(PointF)); + for (int i = 0; i < carBody.num; ++i) { + carBody.point[i] = car->carXY[car->body[i]]; + } + + if (IntersectionOf(&carBody, &roadArea) == GM_None) { + ret = true; + } + + free(carBody.point); + free(roadArea.point); + return ret; +} + +static bool CrashSeparateLine(int currIndex, struct road_exam2_map &map, const car_model *car) +{ + Line frontAxle, rearAxle; + + if (currIndex == INVALID_ROAD || currIndex >= map.roads.size()) + return false; + + MakeLine(&frontAxle, &car->carXY[car->left_front_tire[TIRE_OUTSIDE]], &car->carXY[car->right_front_tire[TIRE_OUTSIDE]]); + MakeLine(&rearAxle, &car->carXY[car->left_rear_tire[TIRE_OUTSIDE]], &car->carXY[car->right_rear_tire[TIRE_OUTSIDE]]); + + // 鍒嗘 + for (int i = 0; i < map.roads[currIndex].separate.size(); i++) { + // 鍒嗘涓殑姣忔潯绾� + for (int j = 0; j < map.roads[currIndex].separate[i].line.size(); j++) { + Line theLine; + int p1 = 0; + for (int p2 = 1; p2 < map.roads[currIndex].separate[i].line[j].num; ++p2) { + MakeLine(&theLine, &map.roads[currIndex].separate[i].line[j].point[p1], &map.roads[currIndex].separate[i].line[j].point[p2]); + if (IntersectionOf(theLine, frontAxle) == GM_Intersection || + IntersectionOf(theLine, rearAxle) == GM_Intersection) { + return true; + } + p1 = p2; + } + } + } + return false; +} + +struct { + int road; + int segment; + int track; +} CarOnTrackInfo; + +static void DetectSeparate(int currIndex, struct road_exam2_map &map, const car_model *car) +{ + int segment; + int track = -1; + + if (currIndex == INVALID_ROAD || currIndex >= map.roads.size()) + return; + + for (int i = 0; i < map.roads[currIndex].separate.size(); i++) { + if (map.roads[currIndex].separate[i].character == 0) { + int separate_line_num = map.roads[currIndex].separate[i].line.size(); + + // 閬嶅巻褰撳墠鍒嗘鐨勬瘡涓�鏉$嚎 + for (int j = 0; j < separate_line_num; ++j) { + Line theLine; + int p1 = 0; + bool match_line = false; + // 鍗曠嫭鐨勪竴鏉¤櫄绾� + for (int p2 = 1; p2 < map.roads[currIndex].separate[i].line[j].num; ++p2) { + MakeLine(&theLine, &map.roads[currIndex].separate[i].line[j].point[p1], &map.roads[currIndex].separate[i].line[j].point[p2]); + if (p1 == 0 || p2 == map.roads[currIndex].separate[i].line[j].num - 1) { + // 棣栧熬涓ょ锛屽簲閲囩敤寤堕暱绾跨殑鏂瑰紡 + } + if (VerticalPointOnLine(car->basePoint, theLine)) { + match_line = true; + int rel = IntersectionOfLine(map.roads[currIndex].separate[i].line[j].point[p1], + map.roads[currIndex].separate[i].line[j].point[p2], + car->basePoint); + // 璁板綍鎵�鍦ㄩ亾璺紝鍒嗛亾娈碉紝鍒嗛亾鎯呭喌 + if (rel == 1) { // 鍦ㄥ乏渚� + segment = i; + track = j; + goto DETECT_SEPARATE_END; + } else if (rel != -1) { // 鍦ㄧ嚎涓� + segment = i; + track = j; + goto DETECT_SEPARATE_END; + } + break; + } + p1 = p2; + } + + track = separate_line_num; + } + } + } + + DETECT_SEPARATE_END: + ; +} +#endif diff --git a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java index 383c44a..a349d85 100644 --- a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java +++ b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java @@ -98,7 +98,7 @@ public void PlayRing(Context context) { RingtoneManager ringtoneManager= new RingtoneManager(context); // 閾冨0绠$悊鍣� - + ringtoneManager.setType(RingtoneManager.TYPE_NOTIFICATION); for (int i = 0; i < ringtoneManager.getCursor().getCount(); i++) { Log.i(TAG, "閾冨0鍚嶇О " + ringtoneManager.getRingtone(i).getTitle(context)); -- Gitblit v1.8.0