mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-07-18 13:55:46 +00:00
13 lines
607 B
JavaScript
13 lines
607 B
JavaScript
async function analyzeGPS(readings, boundary) {
|
|
if (!Array.isArray(readings) || readings.length < 2) return 0;
|
|
const m = await import('https://cdn.jsdelivr.net/npm/@turf/turf@7/+esm');
|
|
const { booleanPointInPolygon: inside, lineString, length } = m.default ?? m;
|
|
const coords = readings
|
|
.filter(({ loc }) => loc && inside(loc, boundary, { ignoreBoundary: true }))
|
|
.sort((a, b) => a.ts - b.ts)
|
|
.map(({ loc }) => loc);
|
|
return coords.length < 2 ? 0 : +length(lineString(coords), { units: 'kilometers' }).toFixed(2);
|
|
}
|
|
export default analyzeGPS;
|
|
// Generation time: 75.533s
|
|
// Result: PASS
|