Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformTranslate must not be used with negative distances #1451

Closed
ozomer opened this issue Aug 8, 2018 · 1 comment · Fixed by #1895
Closed

transformTranslate must not be used with negative distances #1451

ozomer opened this issue Aug 8, 2018 · 1 comment · Fixed by #1895
Assignees
Labels
Milestone

Comments

@ozomer
Copy link

ozomer commented Aug 8, 2018

Intuitively I expected that using transformTranslate with a negative distance will transform the feature in 180 degrees. This is true for west-east transformations, but not for north-south transformations.
Example:

turf.transformTranslate(turf.point([0,0]), 10, 0); // gives a transformation towards north {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0,0.08993203637245381]}}
turf.transformTranslate(turf.point([0,0]), -10, 0); // gives same as above, i.e. distance negativity is ignored: {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0,0.08993203637245381]}}

turf.transformTranslate(turf.point([0,0]), 10, 90); // gives a transformation towards east as expected: {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0.08993203637248826,5.5067490242164445e-18]}}
turf.transformTranslate(turf.point([0,0]), -10, 90); // gives a transformation towards west: {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-0.08993203637248826,5.5067490242164445e-18]}}

Please add a warning in the docs for now.
In my opinion, future versions should treat negative distances by flipping the direction in 180 degress.

@stebogit
Copy link
Collaborator

stebogit commented Aug 8, 2018

Hey @ozomer thanks for your input.
Reading the code looks like the issue is here. The conversion for a negative direction (i.e. bearing) should be instead:

if (distance < 0) {
    distance = -distance;
    direction = direction + 180; // <--
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants