Skip to content

Commit

Permalink
Merge pull request #1895 from Turfjs/transform-translate-fix
Browse files Browse the repository at this point in the history
Fix handling of negative distances in transform-translate
  • Loading branch information
rowanwins authored May 7, 2020
2 parents 26d213d + d8668b9 commit 0f97326
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/turf-transform-translate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function transformTranslate(geojson, distance, direction, options) {
// Invert with negative distances
if (distance < 0) {
distance = -distance;
direction = -direction;
direction = direction + 180;
}

// Clone geojson to avoid side effects
Expand Down
8 changes: 8 additions & 0 deletions packages/turf-transform-translate/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ test('translate -- throws', t => {
t.end();
});

test('negative distance handling', t => {
const result = translate(point([0,0]), 10, 0);
const result2 = translate(point([0,0]), -10, 0);
t.deepEqual(result, {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0,0.08993203637245381]}})
t.deepEqual(result2, {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0,-0.08993203637245381]}})
t.end()
})

test('rotate -- mutated input', t => {
const line = lineString([[10, 10], [12, 15]]);
const lineBefore = JSON.parse(JSON.stringify(line));
Expand Down

0 comments on commit 0f97326

Please sign in to comment.