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

Added special handling to booleanPointOnLine for zero length lines #2751

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

smallsaucepan
Copy link
Member

In cases where the point was on the same longitude as a zero length line, even if the point was far away, booleanPointOnLine would return true.

Resolves #2750

@smallsaucepan
Copy link
Member Author

Merging this will clear the way to getting a couple of cleanCoords bugs fixed as well.

@smallsaucepan
Copy link
Member Author

@JamesLMilner or @mfedderly could I please request someone cast an eye over this? There are a couple of other issues - cleanCoords and simplify - that can proceed once this is merged.


// Special cases for zero length lines
// https://github.com/Turfjs/turf/issues/2750
if (Math.abs(dxl) === Math.abs(dyl) && Math.abs(dxl) === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this math need to be done with some small epsilon for the float comparison instead of ===?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be ok without. The new section is guarding against the old (lower) code getting too many 0s for dxl, etc. They don't seem to behave if they do.

If they get any value above zero, no matter how small, they cope. For example, did some experiments changing the test line string to:

lineString([
  [1, 1],
  [1 + Number.EPSILON, 1],
])

and all is well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could try incorporating additional checks into the existing return dxl > 0 ? x1 <= x && x <= x2 : x2 <= x && x <= x1; type code but keeping them separate seemed neater.

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.

@turf/boolean-point-on-line incorrectly returns true in some cases when line is of zero length
2 participants