Skip to content

Commit 3a5da78

Browse files
committed
fixing turf-line-arc -- reaches bearing2 despite floating-point drift test. Use correct last coordinate.
1 parent 664f3dd commit 3a5da78

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

packages/turf-line-arc/test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { loadJsonFileSync } from "load-json-file";
66
import { writeJsonFileSync } from "write-json-file";
77
import { truncate } from "@turf/truncate";
88
import { destination } from "@turf/destination";
9-
import { featureCollection, point } from "@turf/helpers";
9+
import {
10+
calculatePolygonCircumRadiusToBestApproximateEqualAreaCircle,
11+
featureCollection,
12+
point,
13+
} from "@turf/helpers";
1014
import { lineArc } from "./index.js";
1115

1216
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -88,14 +92,21 @@ test("turf-line-arc -- reaches bearing2 despite floating-point drift", (t) => {
8892
// dropped the final vertex, returning `steps` points instead of `steps + 1`
8993
// and ending the arc a full step short of bearing2.
9094
const center = point([-75, 40]);
91-
const arc = lineArc(center, 5, 0, 29, { steps: 7 });
95+
const steps = 7;
96+
const radius = 5;
97+
const bearing1 = 0;
98+
const bearing2 = 29;
99+
const arc = lineArc(center, radius, bearing1, bearing2, { steps });
92100
const coords = arc.geometry.coordinates;
93101

94102
t.equals(coords.length, 7 + 1, "arc has steps + 1 vertices");
95103

96104
// The final vertex must sit on bearing2 (29°). destination(center, r, 29)
97105
// gives the reference coordinate; the old code stopped at bearing ~24.857°.
98-
const expectedLast = destination(center, 5, 29).geometry.coordinates;
106+
const circumRadius =
107+
calculatePolygonCircumRadiusToBestApproximateEqualAreaCircle(radius, steps);
108+
const expectedLast = destination(center, circumRadius, bearing2).geometry
109+
.coordinates;
99110
t.deepEquals(
100111
truncate(point(coords[coords.length - 1])).geometry.coordinates,
101112
truncate(point(expectedLast)).geometry.coordinates,

0 commit comments

Comments
 (0)