@@ -6,7 +6,11 @@ import { loadJsonFileSync } from "load-json-file";
66import { writeJsonFileSync } from "write-json-file" ;
77import { truncate } from "@turf/truncate" ;
88import { destination } from "@turf/destination" ;
9- import { featureCollection , point } from "@turf/helpers" ;
9+ import {
10+ calculatePolygonCircumRadiusToBestApproximateEqualAreaCircle ,
11+ featureCollection ,
12+ point ,
13+ } from "@turf/helpers" ;
1014import { lineArc } from "./index.js" ;
1115
1216const __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