Skip to content

Commit c0ba1b8

Browse files
committed
fix: improved isLocationOnPath
1 parent b052b25 commit c0ba1b8

File tree

2 files changed

+16
-2
lines changed
  • packages/ui-carto/platforms

2 files changed

+16
-2
lines changed

packages/ui-carto/platforms/android/java/com/akylas/carto/additions/Utils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ static public long isLocationOnPath(MapPos point, MapPosVector poly, boolean clo
275275
double y1 = mercator(lat1);
276276
double y3 = mercator(lat3);
277277
double[] xTry = new double[3];
278+
double lastHavDist = -1;
278279
for (int index = 0; index < size; index++) {
279280
MapPos point2 = poly.get(index);
280281
double lat2 = toRadians(point2.getY());
@@ -298,7 +299,13 @@ static public long isLocationOnPath(MapPos point, MapPosVector poly, boolean clo
298299
double latClosest = inverseMercator(yClosest);
299300
double havDist = havDistance(lat3, latClosest, x3 - xClosest);
300301
if (havDist < havTolerance) {
301-
return index;
302+
if (lastHavDist = -1) {
303+
lastHavDist = havDist;
304+
} else if (havDist < lastHavDist){
305+
lastHavDist = havDist;
306+
} else {
307+
return index;
308+
}
302309
}
303310
}
304311
}

packages/ui-carto/platforms/ios/src/Utils.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ + (long)isLocationOn:(NTMapPos *)point
198198
double y1 = mercator(lat1);
199199
double y3 = mercator(lat3);
200200
NSMutableArray *xTry = [NSMutableArray array];
201+
double lastHavDist = -1;
201202
for (int index = 0; index < size; index++) {
202203
NTMapPos *point2 = ([poly get:index]);
203204
double lat2 = toRadians([point2 getY]);
@@ -219,7 +220,13 @@ + (long)isLocationOn:(NTMapPos *)point
219220
double latClosest = inverseMercator(yClosest);
220221
double havDist = havDistance(lat3, latClosest, x3 - xClosest);
221222
if (havDist < havTolerance) {
222-
return index;
223+
if (lastHavDist = -1) {
224+
lastHavDist = havDist;
225+
} else if (havDist < lastHavDist){
226+
lastHavDist = havDist;
227+
} else {
228+
return index;
229+
}
223230
}
224231
}
225232
}

0 commit comments

Comments
 (0)