fix wpt to segment matching

This commit is contained in:
vcoppe
2025-12-24 13:07:22 +01:00
parent 2e171dfbee
commit 51c85e4cd5
2 changed files with 22 additions and 22 deletions

View File

@@ -473,13 +473,11 @@ export const fileActions = {
newFile.replaceWaypoints(
0,
file.wpt.length - 1,
closest
.filter((c) =>
c.some(
([trackIndex, segmentIndex]) => trackIndex === index
)
file.wpt.filter((wpt, wptIndex) =>
closest[wptIndex].some(
([trackIndex, segmentIndex]) => trackIndex === index
)
.map((c, wptIndex) => file.wpt[wptIndex])
)
);
newFile._data.id = fileIds[index];
newFile.metadata.name =
@@ -499,14 +497,11 @@ export const fileActions = {
newFile.replaceWaypoints(
0,
file.wpt.length - 1,
closest
.filter((c) =>
c.some(
([trackIndex, segmentIndex]) =>
segmentIndex === index
)
file.wpt.filter((wpt, wptIndex) =>
closest[wptIndex].some(
([trackIndex, segmentIndex]) => segmentIndex === index
)
.map((c, wptIndex) => file.wpt[wptIndex])
)
);
newFile._data.id = fileIds[index];
newFile.metadata.name = `${file.trk[0].name ?? file.metadata.name} (${index + 1})`;

View File

@@ -62,15 +62,20 @@ export function getClosestTrackSegments(
let segmentBounds = segmentStatistics.global.bounds;
let northEast = segmentBounds.northEast;
let southWest = segmentBounds.southWest;
let northWest: Coordinates = { lat: northEast.lat, lon: southWest.lon };
let southEast: Coordinates = { lat: southWest.lat, lon: northEast.lon };
let distanceToSegment = Math.min(
crossarcDistance(northWest, northEast, point),
crossarcDistance(northEast, southEast, point),
crossarcDistance(southEast, southWest, point),
crossarcDistance(southWest, northWest, point)
);
segmentBoundsDistances.push([distanceToSegment, trackIndex, segmentIndex]);
let bounds = new mapboxgl.LngLatBounds(southWest, northEast);
if (bounds.contains(point)) {
segmentBoundsDistances.push([0, trackIndex, segmentIndex]);
} else {
let northWest: Coordinates = { lat: northEast.lat, lon: southWest.lon };
let southEast: Coordinates = { lat: southWest.lat, lon: northEast.lon };
let distanceToBounds = Math.min(
crossarcDistance(northWest, northEast, point),
crossarcDistance(northEast, southEast, point),
crossarcDistance(southEast, southWest, point),
crossarcDistance(southWest, northWest, point)
);
segmentBoundsDistances.push([distanceToBounds, trackIndex, segmentIndex]);
}
});
segmentBoundsDistances.sort((a, b) => a[0] - b[0]);