Skip to content

Commit

Permalink
Distance conversion tests (#687)
Browse files Browse the repository at this point in the history
* adds distance conversion tests

* Change latitude to zero
Consider using cheap-ruler for calculations based on latitudes
  • Loading branch information
DenisCarriere authored Apr 25, 2017
1 parent e7b7fcd commit fd299ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/turf-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"@turf/distance": "^4.1.0",
"benchmark": "^2.1.3",
"tape": "^3.5.0"
},
Expand Down
26 changes: 25 additions & 1 deletion packages/turf-helpers/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const test = require('tape');
const helpers = require('.');
const distance = require('@turf/distance');
const {
point,
polygon,
Expand All @@ -11,8 +12,11 @@ const {
multiPolygon,
geometryCollection,
radiansToDistance,
distanceToRadians,
distanceToDegrees,
bearingToAngle
} = helpers;
}
= helpers;

test('point', t => {
const ptArray = point([5, 10], {name: 'test point'});
Expand Down Expand Up @@ -306,6 +310,26 @@ test('radiansToDistance', t => {
t.end();
});

// the higher/lower in latitude, the greater the distortion (curvature of the earth)
const dx = distance(point([-120, 0]), point([-120.5, 0]));
const dy = distance(point([-120, 0]), point([-120, 0.5]));

test('distanceToRadians', t => {
t.equal(distanceToRadians(dx), distanceToRadians(dy), 'radiance conversion');
t.equal(distanceToRadians(1, 'radians'), 1);
t.equal(distanceToRadians(6373, 'kilometers'), 1);
t.equal(distanceToRadians(3960, 'miles'), 1);

t.end();
});

test('distanceToDegrees', t => {
t.equal(Number(distanceToDegrees(dx).toFixed(6)), 0.5, 'degrees conversion');
t.equal(Number(distanceToDegrees(dy).toFixed(6)), 0.5, 'degrees conversion');

t.end();
});

test('bearingToAngle', t => {
t.equal(bearingToAngle(40), 40);
t.equal(bearingToAngle(-105), 255);
Expand Down

0 comments on commit fd299ad

Please sign in to comment.