turf
turf copied to clipboard
Adding tolerance to @turf/boolean-point-on-line
A couple of days ago @DenisCarriere raised the possibility of adding a tolerance threshold to @turf/boolean-point-on-line. Currently the point has to be exactly on the line, there is 0 margin for error.
A few finds from my investigations
- As far as I can work out the current algorithm doesn't really support adding in a tolerance check
- I did find a pretty neat algorithm for finding the distance between a point and a line here
- we don't really have a module for this currently, is this something we'd like to package up @DenisCarriere ?
- this is quite a bit slower than the current algorithm (eg half the number of ops per sec) but if it only got called when the tolerance threshold was set that might be acceptable...
- there are a couple of other potential options that I'd like to explore still that would be an entire replacement
I knew I should've paid more attention in maths!
Both my other options are a no go, they were more about using an epsilon value to round float point precision which isn't really what we're wanting from this tolerance type setting.
So I'm thinking the distance measurement is the best bet at the moment...
Will keep mulling it over
👍 @rowanwins great findings, I wouldn't sweat it if we don't get this implemented, the pointOnLine does seem to do the job at the moment.
Very interesting links you provided, I also should of paid more attention to math 😄
we don't really have a module for this ['finding the distance between a point and a line'] currently
@rowanwins @turf/point-on-line does actually calculate that distance (probably not in the fastest way) and returns the point on the line at the closest distance (from the input point).
It might be useful to create a module for that calculation, and maybe make sure we use the fastest algorithm in there.
BTW, in this issue we are talking about @turf/boolean-point-on-line right?
Quite confusing that we have two different modules almost with the same name 😅
maybe make sure we use the fastest algorithm in there.
👍 That would be handy!
Quite confusing that we have two different modules almost with the same name
Agreed, it can get confusing at times 😢
Adding another reference to this jsfiddle which looks pretty close to what we want. Had a brief go at getting it going with no joy so needs a bit more thought
That JSFiddle is really cool! 😄 so fun!
This ticket is pretty old, but has anymore progress been made for this issue?
We have a use case where we're using the nearestPointOnLine method in our UI to keep a point on a line string & then using the booleanPointOnLine method in our api to validate the point from the UI is actually on the line string, but because it's expecting such an exact number, the validation pretty much always returns false.
We're looking into the jsfiddle above as maybe a potential solution. Thanks for sharing that.