Add epsilon option to booleanPointOnLine#2051
Conversation
mfedderly
left a comment
There was a problem hiding this comment.
I'm a little bit concerned about just adding an epsilon here without really understanding the relationship between the cross product value and the accuracy in real terms. It looks like PostGIS actually takes a distance in meters instead of the epsilon or precision approach.
Additionally I'm a little bit concerned that this change also does not correctly impact the ignoreEndVerticies option.
Thoughts?
Are you speaking of ST_DWithin? I have very limited experience with PostGIS so I'm not sure what what the best approach would be here in terms of making the function signature here similar. I feel adding a parameter like this (precision/epsilon) gives the most control to the consumer of this function to do what they'd like and ideally you wouldn't even have to touch this parameter as it would Just Work™. I think the only reason I even ran into this problem is because all of the test cases within this package were using simple integers instead of of lng/lat points.
Yes I definitely skipped that bit of the function for my use case :P Let me explore that side a bit more and add some more test cases |
|
Yeah I spent some time today looking into ST_DWithin and that's where I got the idea about using distance here. I think the problem with the epsilon/precision approach is that you're using it here on the cross product. I don't actually know what units the cross product is in, so it is hard to reason about the what that value means for the potential error allowed. Its also a little bit awkward to change the behavior of this method in a way that isn't exactly backwards compatible, even though I agree that this probably needs to work in the way you're suggesting. |
So I found
Yeah definitely. It feels as though one would have to sort of guess what value they need for their specific use case. As mentioned above, is there any reason not to assume meters for this? One way to go about this is to default the precision value to that of the input. For example, a point like [1,0] would work as the module does now where there's no room for error ( In terms of backwards compatibility you're right in that this may "break" existing implementations. Originally I did have the Other than that, I will make these changes now. I'm also open to other suggestions here as I think there's room for improvement and I don't want to have to keep using a custom fork 😛 |
This also preserves backwards compatibility
77e6af7 to
c40afb7
Compare
|
Ok so I've opted for the more technical |
mfedderly
left a comment
There was a problem hiding this comment.
Sweet, thanks for making these changes!
Please fill in this template.
npm testat the sub modules where changes have occurred.npm run lintto ensure code style at the turf module level.I'm working on an algorithm that uses a few of the modules here. I used
turf.lineIntersectto find intersection points of two polygons. Naturally when checking which line of the polygon one of the points was on, I was surprised to find outbooleanPointOnLinewas returning false for all of the line strings of the polygon. I even usedpointToLineDistanceand that function was returning0as expected. Digging deeper into why, I noticed the cross product withinbooleanPointOnLinewas expected to be0. However when using lat/lng coordinates, the cross product ended up being something super small (ie 4e-17) which is basically0but obviously not=== 0. None of the tests contained numbers with the precision of lat/lng coordinates so this PR does just that.I've decided to give
precisiona default value because I think this function should have returnedtruein the first place for me. Even though I've made thedefault value 5 here(Updated this to 10 for even more confidence with lng/lat points), it could really be anything else (for my example less than 17 would suffice). As far as this function goes, a number that starts with 10 zeros could be considered 0 for most cases I think.