Added special handling to booleanPointOnLine for zero length lines#2751
Conversation
…urning false positives for points on the same longitude as zero length lines.
|
Merging this will clear the way to getting a couple of cleanCoords bugs fixed as well. |
|
@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) { |
There was a problem hiding this comment.
Does this math need to be done with some small epsilon for the float comparison instead of ===?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…er with lines that retrace or pass back through their origin. Note depends on PR Turfjs#2751 to be merged first as part of the problem was booleanPointOnLine misbehaving.
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