Skip to content

Commit 7511687

Browse files
committed
Fix: @turf/nearest-point-on-line failing test
After changes, tests in @turf/point-to-polygon-distance were failing. Issue confirmed to be due to single bit floating point difference and updated to new output value. Also fixed partially missing comment.
1 parent a80a828 commit 7511687

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/turf-nearest-point-on-line/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ function lngLatToVector(a: Position): Vector {
171171
function vectorToLngLat(v: Vector): Position {
172172
const [x, y, z] = v;
173173
// Clamp the z-value to ensure that is inside the [-1, 1] domain as required
174-
// by asin. Note that
174+
// by asin. Note therefore that this function should only be applied to unit
175+
// vectors so z > 1 should not exist
175176
const zClamp = Math.min(Math.max(z, -1), 1);
176177
const lat = radiansToDegrees(Math.asin(zClamp));
177178
const lng = radiansToDegrees(Math.atan2(y, x));

packages/turf-point-to-polygon-distance/test_fixtures/multi-polygon.geojson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "Feature",
66
"properties": {
77
"name": "outer",
8-
"expected_distance": 22.10311139107688,
8+
"expected_distance": 22.10311139186459,
99
"units": "meters"
1010
},
1111
"geometry": {
@@ -53,7 +53,7 @@
5353
"type": "Feature",
5454
"properties": {
5555
"name": "in-hole-close-to-poly-in-hole",
56-
"expected_distance": 16.36078019912375,
56+
"expected_distance": 16.360780198687877,
5757
"units": "meters"
5858
},
5959
"geometry": {

0 commit comments

Comments
 (0)