From 44fc1ab2eeb271b09f14ca1bfef427aee1fd0bd5 Mon Sep 17 00:00:00 2001 From: Bertold Van den Bergh Date: Fri, 13 Dec 2019 17:50:39 +0100 Subject: [PATCH] Fix edge case for points on border --- library/zonedetect.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/library/zonedetect.c b/library/zonedetect.c index 6f800f4..b34a486 100644 --- a/library/zonedetect.c +++ b/library/zonedetect.c @@ -691,13 +691,14 @@ static ZDLookupResult ZDPointInPolygon(const ZoneDetect *library, uint32_t polyg b = (float)pointLat - a * (float)pointLon; } + int onStraight = ZDPointInBox(pointLat, latFixedPoint, prevLat, pointLon, lonFixedPoint, prevLon); + if(lineIsStraight && (onStraight || windingNeedCompare)) { + if(distanceSqrMin) *distanceSqrMin = 0; + return ZD_LOOKUP_ON_BORDER_SEGMENT; + } + /* Jumped two quadrants. */ if(windingNeedCompare) { - if(lineIsStraight) { - if(distanceSqrMin) *distanceSqrMin = 0; - return ZD_LOOKUP_ON_BORDER_SEGMENT; - } - /* Check if the target is on the border */ const int32_t intersectLon = (int32_t)(((float)latFixedPoint - b) / a); if(intersectLon >= lonFixedPoint-1 && intersectLon <= lonFixedPoint+1) {