From 6b136af26a51b3d53051cd3e0e7d467ed2ab8a6b Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期四, 05 三月 2020 13:33:21 +0800
Subject: [PATCH] 更新地图

---
 lib/src/main/cpp/driver_test.cpp |   57 ++++++++++++++++++++++++++-------------------------------
 1 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/lib/src/main/cpp/driver_test.cpp b/lib/src/main/cpp/driver_test.cpp
index 321f3c5..443a303 100644
--- a/lib/src/main/cpp/driver_test.cpp
+++ b/lib/src/main/cpp/driver_test.cpp
@@ -878,40 +878,16 @@
 //            }
 //        }
         if (mapList[i].type == MAP_TYPE_CURVE) {
-            const int step = 10;
-            Polygon map;
-            bool enter = false;
+            Line startLine;
+            Line carAxial;
 
-            map.num = 1 + mapList[i].map.num / step + ((mapList[i].map.num % step == 0) ? 0 : 1);
-            map.num += 1 + mapList[i].map2.num / step + ((mapList[i].map2.num % step == 0) ? 0 : 1);
-            map.point = (PointF *) malloc(map.num * sizeof(PointF));
+            MakeLine(&startLine, &mapList[i].map.point[0], &mapList[i].map2.point[0]);
+            MakeLine(&carAxial, &car->carXY[car->axial[AXIAL_FRONT]], &car->carXY[car->axial[AXIAL_REAR]]);
 
-            int n = 0, m = 0;
-            while (n < mapList[i].map.num - 1) {
-                map.point[m++] = mapList[i].map.point[n];
-                n += step;
+            if (IntersectionOf(startLine, carAxial) == GM_Intersection) {
+                if (DistanceOf(car->carXY[car->axial[AXIAL_FRONT]], startLine) > 0.1)
+                    return i;
             }
-            map.point[m++] = mapList[i].map.point[mapList[i].map.num - 1];
-
-            n = mapList[i].map2.num - 1;
-            while (n > 0) {
-                map.point[m++] = mapList[i].map2.point[n];
-                n -= step;
-            }
-            map.point[m++] = mapList[i].map2.point[0];
-
-            if (IntersectionOf(car->carXY[ car->axial[AXIAL_FRONT] ], &map) == GM_Containment) {
-                Line enterLine1;
-
-                MakeLine(&enterLine1, &(mapList[i].map.point[0]), &(mapList[i].map2.point[0]));
-
-                if (DistanceOf(car->carXY[car->axial[AXIAL_FRONT]], enterLine1) > 0.1)
-                    enter = true;
-            }
-
-            free(map.point);
-
-            if (enter) return i;
         }
     }
     return -1;
@@ -979,6 +955,25 @@
             free(carBody.point);
             free(map.point);
     }
+    if (mapList[index].type == MAP_TYPE_CURVE) {
+        Line carAxial;
+        Line scanLine;
+
+        MakeLine(&carAxial, &car->carXY[car->axial[AXIAL_FRONT]], &car->carXY[car->axial[AXIAL_REAR]]);
+
+        int startL = 0, startR = 0;
+        while (startL < mapList[index].map.num || startR < mapList[index].map2.num) {
+            MakeLine(&scanLine, &mapList[index].map.point[startL], &mapList[index].map.point[startR]);
+            if (IntersectionOf(scanLine, carAxial) == GM_Intersection) {
+                break;
+            }
+            if (startL < mapList[index].map.num)
+                startL++;
+            if (startR < mapList[index].map2.num)
+                startR++;
+        }
+        ret = true;
+    }
 
     return ret;
 }

--
Gitblit v1.8.0