From c037b88513087cf2b03559534dc0d5dc9d1a2e5e Mon Sep 17 00:00:00 2001 From: Armin Samii Date: Wed, 7 Dec 2022 23:30:32 -0500 Subject: [PATCH 1/2] Update PolygonUtils.cs --- .../Mapbox/Unity/Utilities/PolygonUtils.cs | 47 +++---------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Unity/Utilities/PolygonUtils.cs b/sdkproject/Assets/Mapbox/Unity/Utilities/PolygonUtils.cs index e8cddc6bf..415aac294 100644 --- a/sdkproject/Assets/Mapbox/Unity/Utilities/PolygonUtils.cs +++ b/sdkproject/Assets/Mapbox/Unity/Utilities/PolygonUtils.cs @@ -17,54 +17,21 @@ public static class PolygonUtils /// The point that is to be tested. public static bool PointInPolygon(Point2d p, List>> polygon) { - List> poly = polygon[0]; - - Point2d p1; - Point2d p2; bool inside = false; - - if (poly.Count < 3) - { - return inside; - } - - var oldPoint = new Point2d( - poly[poly.Count - 1].X - , poly[poly.Count - 1].Y - ); - + int j = poly.Count - 1; for (int i = 0; i < poly.Count; i++) { - var newPoint = new Point2d(poly[i].X, poly[i].Y); - - if (newPoint.X > oldPoint.X) - { - p1 = oldPoint; - p2 = newPoint; - } - else + if (poly[i].Y < p.Y && poly[j].Y >= p.Y || poly[j].Y < p.Y && poly[i].Y >= p.Y) { - p1 = newPoint; - p2 = oldPoint; + if (poly[i].X + (p.Y - poly[i].Y) / (poly[j].Y - poly[i].Y) * (poly[j].X - poly[i].X) < p.X) + { + inside = !inside; + } } - - if ( - (newPoint.X < p.X) == (p.X <= oldPoint.X) - && (p.Y - (long)p1.Y) * (p2.X - p1.X) < (p2.Y - (long)p1.Y) * (p.X - p1.X) - ) - { - inside = !inside; - } - - oldPoint = newPoint; + j = i; } return inside; } - - - } - } - From 8135fdca924bd9f9c2f394766f2ba9a4157e91dc Mon Sep 17 00:00:00 2001 From: Armin Samii Date: Wed, 7 Dec 2022 23:32:06 -0500 Subject: [PATCH 2/2] Updating changelog --- documentation/docs/05-changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/docs/05-changelog.md b/documentation/docs/05-changelog.md index ebba17aab..100820809 100644 --- a/documentation/docs/05-changelog.md +++ b/documentation/docs/05-changelog.md @@ -3,6 +3,7 @@ ### Bug Fixes - Fixes a bug where add collider feature didn't work for flat terrain mesh. - Fix a bug where vector tile processing fired multiple times depending on Terrain/Image data states +- Fixed incorrect computation of PointInPolygon when point was near center of polygon ### Improvements - Improves Directions factory and prefabs to provide better UX and support for all types of maps