minor simplification

main
Inga 🏳‍🌈 1 year ago
parent f804a44e41
commit bc98fda9d1
  1. 5
      src/routePlanner/total.tsx
  2. 9
      src/shared/routes.ts

@ -7,10 +7,7 @@ type TotalProps = {
}; };
export const TotalComponent = ({ markers }: TotalProps) => { export const TotalComponent = ({ markers }: TotalProps) => {
const routeLength = useMemo( const routeLength = useMemo(() => getRouteLength(markers), [markers]);
() => getRouteLength(markers.map(({ coordinates }) => coordinates)),
[markers],
);
return <>{`Total route length: ${routeLength.toFixed(0)}m`}</>; return <>{`Total route length: ${routeLength.toFixed(0)}m`}</>;
}; };

@ -1,7 +1,7 @@
import haversineDistance from 'haversine-distance'; import haversineDistance from 'haversine-distance';
import { Coordinates } from './types'; import { Waypoint } from './types';
export const getRouteLength = (points: Coordinates[]) => { export const getRouteLength = (points: Waypoint[]) => {
let result = 0; let result = 0;
for (let i = 0; i < points.length; i++) { for (let i = 0; i < points.length; i++) {
const currentPoint = points[i]; const currentPoint = points[i];
@ -9,7 +9,10 @@ export const getRouteLength = (points: Coordinates[]) => {
if (!currentPoint || !previousPoint) { if (!currentPoint || !previousPoint) {
continue; continue;
} }
result += haversineDistance(previousPoint, currentPoint); result += haversineDistance(
previousPoint.coordinates,
currentPoint.coordinates,
);
} }
return result; return result;

Loading…
Cancel
Save