fix(boolean-crosses): a LineString that only touches a Polygon boundary does not cross it#3091
Open
spokodev wants to merge 2 commits into
Open
fix(boolean-crosses): a LineString that only touches a Polygon boundary does not cross it#3091spokodev wants to merge 2 commits into
spokodev wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
booleanCrossesreturnedtruefor a LineString that only touches a Polygonboundary without passing through the interior.
doLineStringAndPolygonCrosstreated any intersection between the line and thepolygon boundary as a crossing. Per the OGC definition a cross requires the line
to have parts both inside and outside the polygon. A line that merely touches the
boundary at a point (endpoint on a vertex or edge) has all of its interior on one
side, so it does not cross.
Concrete cases on the polygon
[[0,0],[0,10],[10,10],[10,0],[0,0]]:[[0,5],[5,5]]lies inside the polygon and touches the left edge. It isbooleanWithin === true, yet the old code also returnedbooleanCrosses === true,which is contradictory.
[[-5,-5],[0,0],[-5,5]]lies outside and touches a corner. The old codereturned
true.Both match the JSTS
Geometry.crossesreference, which returnsfalsefor them.The fix splits the line on the polygon boundary and checks the midpoint of each
resulting sub-segment. A cross is reported only when at least one sub-segment lies
strictly inside and another lies strictly outside. Genuine crossings still return
true.Added a false fixture for the inside-touching case.