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