minor simplification

main
Inga 🏳‍🌈 6 months 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) => {
const routeLength = useMemo(
() => getRouteLength(markers.map(({ coordinates }) => coordinates)),
[markers],
);
const routeLength = useMemo(() => getRouteLength(markers), [markers]);
return <>{`Total route length: ${routeLength.toFixed(0)}m`}</>;
};

@ -1,7 +1,7 @@
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;
for (let i = 0; i < points.length; i++) {
const currentPoint = points[i];
@ -9,7 +9,10 @@ export const getRouteLength = (points: Coordinates[]) => {
if (!currentPoint || !previousPoint) {
continue;
}
result += haversineDistance(previousPoint, currentPoint);
result += haversineDistance(
previousPoint.coordinates,
currentPoint.coordinates,
);
}
return result;

Loading…
Cancel
Save