mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-05-18 04:32:12 +00:00
19 lines
541 B
JavaScript
19 lines
541 B
JavaScript
async function analyzeGPS(readings, boundary) {
|
|
const turf = await import("https://esm.sh/@turf/turf@7.2.0");
|
|
|
|
const valid = readings
|
|
.filter(({ loc }) =>
|
|
turf.booleanPointInPolygon(turf.point(loc), boundary, { ignoreBoundary: true })
|
|
)
|
|
.sort((a, b) => a.ts - b.ts);
|
|
|
|
if (valid.length < 2) return 0;
|
|
|
|
const line = turf.lineString(valid.map(({ loc }) => loc));
|
|
const km = turf.length(line, { units: "kilometers" });
|
|
|
|
return +km.toFixed(2);
|
|
}
|
|
export default analyzeGPS;
|
|
// Generation time: 13.413s
|
|
// Result: PASS
|