Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

along with negative distance

leiflinse-trivector opened this issue · 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: dartclub/turf_dart#153

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.

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.

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?

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.