Skip to content

Commit 281acbb

Browse files
committed
chore: trying to improve isLocationOnPath
1 parent 9d714b8 commit 281acbb

File tree

1 file changed

+10
-5
lines changed
  • packages/ui-carto/platforms/android/java/com/akylas/carto/additions

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ static public long isLocationOnPath(MapPos point, MapPosVector poly, boolean clo
289289
// Also explore wrapping of x3Base around the world in both directions.
290290
xTry[1] = x3Base + 2 * Math.PI;
291291
xTry[2] = x3Base - 2 * Math.PI;
292+
boolean found = false;
292293
for (int index2 = 0; index2 < xTry.length; index2++) {
293294
double x3 = xTry[index2];
294295
double dy = y2 - y1;
@@ -299,20 +300,24 @@ static public long isLocationOnPath(MapPos point, MapPosVector poly, boolean clo
299300
double latClosest = inverseMercator(yClosest);
300301
double havDist = havDistance(lat3, latClosest, x3 - xClosest);
301302
if (havDist < havTolerance) {
302-
if (lastHavDist == -1) {
303+
if (lastHavDist == -1 || havDist < lastHavDist) {
303304
lastHavDist = havDist;
304-
} else if (havDist < lastHavDist){
305-
lastHavDist = havDist;
306-
} else {
307-
return index;
305+
found = true;
306+
break;
308307
}
309308
}
310309
}
310+
if (!found && lastHavDist != -1) {
311+
return index - 1;
312+
}
311313
}
312314
lat1 = lat2;
313315
lng1 = lng2;
314316
y1 = y2;
315317
}
318+
if (lastHavDist != -1) {
319+
return size - 1;
320+
}
316321
}
317322
return -1;
318323
}

0 commit comments

Comments
 (0)