parent
7f0ca80e54
commit
2b66d40a5d
@ -1,19 +1,8 @@ |
||||
import haversineDistance from 'haversine-distance'; |
||||
import { toPairs } from './collections'; |
||||
import { Waypoint } from './types'; |
||||
|
||||
export const getRouteLength = (points: Waypoint[]) => { |
||||
let result = 0; |
||||
for (let i = 0; i < points.length; i++) { |
||||
const currentPoint = points[i]; |
||||
const previousPoint = points[i - 1]; |
||||
if (!currentPoint || !previousPoint) { |
||||
continue; |
||||
} |
||||
result += haversineDistance( |
||||
previousPoint.coordinates, |
||||
currentPoint.coordinates, |
||||
); |
||||
} |
||||
|
||||
return result; |
||||
}; |
||||
export const getRouteLength = (points: Waypoint[]) => |
||||
toPairs(points) |
||||
.map(([a, b]) => haversineDistance(a.coordinates, b.coordinates)) |
||||
.reduce((sum, value) => sum + value, 0); |
||||
|
Loading…
Reference in new issue