turf icon indicating copy to clipboard operation
turf copied to clipboard

turf.booleanPointOnLine() returning false even though the point is generated by turf.along()

Open zharfanzahisham opened this issue 2 years ago • 3 comments

Hi, I am facing an issue where turf.booleanPointOnLine returns false even though the point is generated using turf.along. Steps to reproduce:

var p1 = turf.along(line_geojson, 0.01);
turf.booleanPointOnLine(p1, line_geojson);  // false

Version: 6.5.0 line_geojson gist file: https://gist.github.com/zharfanzahisham/b988e927f75336fe1dbde390e577c739

Is there anything I'm doing wrong or missing? Thanks in advance!

zharfanzahisham avatar Jan 20 '23 03:01 zharfanzahisham

Thanks for raising - I agree that the result of along should should probably pass booleanPointOnLine. As such I will flag this as a bug. Without investigating further it's hard to gauge which package is at fault here.

Here is the code as an example for anyone investigating:

https://codesandbox.io/s/zen-hooks-km5b4k?file=/src/index.ts

JamesLMilner avatar Jan 26 '23 07:01 JamesLMilner

@JamesLMilner I started investigating this and I think it's an issue of floating point comparisons? I took a look at isPointOnLineSegment, which is called by booleanPointOnLine. It's doing comparisons but I'm just not 100% sure what is being compared on L165 of that same file. I couldn't find a test for that particular function either. Would love your insight.

RaymondDashWu avatar Jun 08 '23 00:06 RaymondDashWu

turf.along returns a point on a great circle line, and turf.booleanPointOnLine checks if the point is on rhumb line so that's why they are not equal.

MatixYo avatar Aug 19 '23 17:08 MatixYo