Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2059 turf-boolean-within returning false positive when line ends outside poly #2599

Merged
merged 1 commit into from Apr 23, 2024

Conversation

kudlav
Copy link
Contributor

@kudlav kudlav commented Apr 23, 2024

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Have read How To Contribute.
  • Run npm test at the sub modules where changes have occurred.
  • Run npm run lint to ensure code style at the turf module level.

In boolean-within check if the LineString ends outside of the Polygon.
This PR fixes issue #2059.

Tested by the following two test cases:

// should return false
const resRobertOrthofer = turf.booleanWithin({
  "type": "LineString",
  "coordinates": [
    [ -26.19140625, 46.800059446787316 ],
    [ -38.14453125, 45.82879925192134 ],
    [-35.15625, 39.90973623453719]
  ]
}, {
  "type": "Polygon",
  "coordinates": [[
    [ -54.84375, 43.70759350405294 ],
    [ -55.1953125, 29.53522956294847 ],
    [ -39.375, 30.14512718337613 ],
    [ -43.59375, 41.11246878918088 ],
    [ -25.48828125, 43.32517767999296 ],
    [ -21.796875, 34.30714385628804 ],
    [ -15.468749999999998, 36.59788913307022 ],
    [ -19.16015625, 49.26780455063753 ],
    [ -54.84375, 43.70759350405294 ]
  ]]
});

// should return false
const resKudlav = turf.booleanWithin({
  "type": "LineString",
  "coordinates": [
    [9.15, 32.46],
    [12.33, 41.6]
  ]
}, {
  "type": "Polygon",
  "coordinates": [[
    [ -0.64, 23.73 ],
    [ 2.22, 24.89 ],
    [ 7.13, 31.6 ],
    [ 14.9, 33.93 ],
    [ 23.41, 32.26 ],
    [ 23.99, 34.46 ],
    [ 27.12, 34.89 ],
    [ 28.56, 38.13 ],
    [ 33.68, 41.6 ],
    [ 13.6, 41.36 ],
    [ 2.53, 38.38 ],
    [ -0.3, 36.01 ],
    [ -0.64, 23.73 ]
  ]]
});

Copy link
Collaborator

@twelch twelch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @kudlav! This looks correct in that it now ensures to check the last point in the linestring, and then is sure to only calculate midpoint after if it's not the last point. Adding a test case to the PR to demonstrate is helpful, but I don't see reason to hold this up.

A new v7 prerelease should be published to npm after merge if you'd like to verify the fix.

@twelch twelch merged commit c76e6e9 into Turfjs:master Apr 23, 2024
3 checks passed
@kudlav kudlav deleted the patch-1 branch April 23, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants