fix freezed files bug

This commit is contained in:
vcoppe
2024-05-16 13:27:12 +02:00
parent 78d96e3097
commit db618b67b0
4 changed files with 18 additions and 15 deletions

View File

@@ -432,17 +432,18 @@ export class RoutingControls {
return false;
}
let start = anchors[0].point._data.index + 1;
let end = anchors[anchors.length - 1].point._data.index - 1;
if (anchors[0].point._data.index === 0) { // First anchor is the first point of the segment
anchors[0].point = response[0]; // Update the first anchor in case it was not on a road
start--; // Remove the original first point
anchors[0].point = response[0]; // Update the first anchor
anchors[0].point._data.index = 0;
} else {
response.splice(0, 0, anchors[0].point); // Keep the original start point
}
if (anchors[anchors.length - 1].point._data.index === segment.trkpt.length - 1) { // Last anchor is the last point of the segment
anchors[anchors.length - 1].point = response[response.length - 1]; // Update the last anchor in case it was not on a road
end++; // Remove the original last point
anchors[anchors.length - 1].point = response[response.length - 1]; // Update the last anchor
anchors[anchors.length - 1].point._data.index = segment.trkpt.length - 1;
} else {
response.push(anchors[anchors.length - 1].point); // Keep the original end point
}
for (let i = 1; i < anchors.length - 1; i++) {
@@ -465,7 +466,7 @@ export class RoutingControls {
anchor.point._data.zoom = 0; // Make these anchors permanent
});
dbUtils.applyToFile(this.fileId, (file) => file.replace(anchors[0].segmentIndex, start, end, response));
dbUtils.applyToFile(this.fileId, (file) => file.replace(anchors[0].segmentIndex, anchors[0].point._data.index, anchors[anchors.length - 1].point._data.index, response));
return true;
}

View File

@@ -26,7 +26,7 @@ export function computeAnchorPoints(segment: TrackSegment) {
segment._data.anchors = true;
}
export function ramerDouglasPeucker(points: TrackPoint[], epsilon: number = 50, start: number = 0, end: number = points.length - 1): SimplifiedTrackPoint[] {
export function ramerDouglasPeucker(points: readonly TrackPoint[], epsilon: number = 50, start: number = 0, end: number = points.length - 1): SimplifiedTrackPoint[] {
if (points.length == 0) {
return [];
} else if (points.length == 1) {
@@ -45,7 +45,7 @@ export function ramerDouglasPeucker(points: TrackPoint[], epsilon: number = 50,
return simplified;
}
function ramerDouglasPeuckerRecursive(points: TrackPoint[], epsilon: number, start: number, end: number, simplified: SimplifiedTrackPoint[]) {
function ramerDouglasPeuckerRecursive(points: readonly TrackPoint[], epsilon: number, start: number, end: number, simplified: SimplifiedTrackPoint[]) {
let largest = {
index: 0,
distance: 0