turf icon indicating copy to clipboard operation
turf copied to clipboard

along with negative distance

Open leiflinse-trivector opened this issue 1 year ago • 4 comments

While porting the along method to dart_turf, I noticed that if you pass a negative distance to it, it will not return the first point in a line.

It is possible to solve this by a special condition at the start of the method, just after coords has been obtained. If distance is negative, then return the first coordinate.

Dart port: https://github.com/dartclub/turf_dart/pull/153

leiflinse-trivector avatar Jan 11 '24 18:01 leiflinse-trivector

Hi @leiflinse-trivector. Thanks for raising this. Could you please read #2148 and let us know how that compares to your request? It sounds like we have two requests for different behaviour from a negative offset.

smallsaucepan avatar Jan 11 '24 23:01 smallsaucepan

I think either clamping or a documented "from end" behavior is fine. But as it is now, it doesn't neither forbid negative input nor define what happens.

My reasoning is that when you input a distance that is longer then the total length of the line string, then it currently returns the last point, so in analogy of that was that if you "undershoot" the start by giving a negative value, it would clamp to the start.

But I also can see that the count from end behavior can be useful in some cases.

leiflinse-trivector avatar Jan 12 '24 09:01 leiflinse-trivector

My take on it would be, if the user passes an along value longer than the length of the line, it's probably accidental, and returning the farthest point on the line seems reasonable. If the user passes a negative value it's probably intentional and they are signalling they're specifically expecting different behaviour.

My gut feel is we would fix this according to #2148, so the behaviour is defined and no error is thrown. Is that a behaviour you'd be happy to align dart_turf with?

smallsaucepan avatar Jan 13 '24 05:01 smallsaucepan

I am not the maintainer of dart_turf, but if turf.js does go with #2148, I am in favor for dart_turf to use the same behavior to make transition between the two libraries easy for developers. Depending on the time frame, if it makes sense for my project, I may help on updating dart_turf.

leiflinse-trivector avatar Jan 16 '24 13:01 leiflinse-trivector