mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-07-18 05:45:46 +00:00
27 lines
634 B
JavaScript
27 lines
634 B
JavaScript
let turfModule;
|
|
|
|
async function analyzeGPS(readings, boundary) {
|
|
turfModule ||= import("https://cdn.jsdelivr.net/npm/@turf/turf@7.2.0/+esm");
|
|
|
|
const {
|
|
point,
|
|
lineString,
|
|
length: pathLength,
|
|
booleanPointInPolygon
|
|
} = await turfModule;
|
|
|
|
const valid = readings
|
|
.filter(({ loc }) =>
|
|
booleanPointInPolygon(point(loc), boundary, { ignoreBoundary: true })
|
|
)
|
|
.sort((a, b) => a.ts - b.ts);
|
|
|
|
if (valid.length < 2) return 0;
|
|
|
|
const path = lineString(valid.map(({ loc }) => loc));
|
|
|
|
return Number(pathLength(path).toFixed(2));
|
|
}
|
|
export default analyzeGPS;
|
|
// Generation time: 12.391s
|
|
// Result: PASS
|