mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
simplify slope segment
This commit is contained in:
@@ -692,10 +692,6 @@ export class TrackSegment extends GPXTreeLeaf {
|
||||
}
|
||||
|
||||
_computeSlopeSegments(statistics: GPXStatistics): [number[], number[]] {
|
||||
function canSplit(point1: TrackPoint, point2: TrackPoint, point3: TrackPoint): boolean {
|
||||
return statistics.local.distance.total[point3._data.index] - statistics.local.distance.total[point1._data.index] >= 0.5 && statistics.local.distance.total[point2._data.index] - statistics.local.distance.total[point3._data.index] >= 0.5;
|
||||
}
|
||||
|
||||
// x-coordinates are given by: statistics.local.distance.total[point._data.index] * 1000
|
||||
// y-coordinates are given by: point.ele
|
||||
// Compute the distance between point3 and the line defined by point1 and point2
|
||||
@@ -718,7 +714,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
||||
return Math.abs((y2 - y1) * x3 - (x2 - x1) * y3 + x2 * y1 - y2 * x1) / dist;
|
||||
}
|
||||
|
||||
let simplified = ramerDouglasPeucker(this.trkpt, 25, elevationDistance, canSplit);
|
||||
let simplified = ramerDouglasPeucker(this.trkpt, 20, elevationDistance);
|
||||
|
||||
let slope = [];
|
||||
let length = [];
|
||||
|
@@ -5,7 +5,7 @@ export type SimplifiedTrackPoint = { point: TrackPoint, distance?: number };
|
||||
|
||||
const earthRadius = 6371008.8;
|
||||
|
||||
export function ramerDouglasPeucker(points: readonly TrackPoint[], epsilon: number = 50, measure: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => number = computeCrossarc, canSplit: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => boolean = () => true): SimplifiedTrackPoint[] {
|
||||
export function ramerDouglasPeucker(points: readonly TrackPoint[], epsilon: number = 50, measure: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => number = computeCrossarc): SimplifiedTrackPoint[] {
|
||||
if (points.length == 0) {
|
||||
return [];
|
||||
} else if (points.length == 1) {
|
||||
@@ -17,33 +17,31 @@ export function ramerDouglasPeucker(points: readonly TrackPoint[], epsilon: numb
|
||||
let simplified = [{
|
||||
point: points[0]
|
||||
}];
|
||||
ramerDouglasPeuckerRecursive(points, epsilon, measure, canSplit, 0, points.length - 1, simplified);
|
||||
ramerDouglasPeuckerRecursive(points, epsilon, measure, 0, points.length - 1, simplified);
|
||||
simplified.push({
|
||||
point: points[points.length - 1]
|
||||
});
|
||||
return simplified;
|
||||
}
|
||||
|
||||
function ramerDouglasPeuckerRecursive(points: readonly TrackPoint[], epsilon: number, measure: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => number, canSplit: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => boolean, start: number, end: number, simplified: SimplifiedTrackPoint[]) {
|
||||
function ramerDouglasPeuckerRecursive(points: readonly TrackPoint[], epsilon: number, measure: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => number, start: number, end: number, simplified: SimplifiedTrackPoint[]) {
|
||||
let largest = {
|
||||
index: 0,
|
||||
distance: 0
|
||||
};
|
||||
|
||||
for (let i = start + 1; i < end; i++) {
|
||||
if (canSplit(points[start], points[end], points[i])) {
|
||||
let distance = measure(points[start], points[end], points[i]);
|
||||
if (distance > largest.distance) {
|
||||
largest.index = i;
|
||||
largest.distance = distance;
|
||||
}
|
||||
let distance = measure(points[start], points[end], points[i]);
|
||||
if (distance > largest.distance) {
|
||||
largest.index = i;
|
||||
largest.distance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if (largest.distance > epsilon && largest.index != 0) {
|
||||
ramerDouglasPeuckerRecursive(points, epsilon, measure, canSplit, start, largest.index, simplified);
|
||||
ramerDouglasPeuckerRecursive(points, epsilon, measure, start, largest.index, simplified);
|
||||
simplified.push({ point: points[largest.index], distance: largest.distance });
|
||||
ramerDouglasPeuckerRecursive(points, epsilon, measure, canSplit, largest.index, end, simplified);
|
||||
ramerDouglasPeuckerRecursive(points, epsilon, measure, largest.index, end, simplified);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -434,7 +434,7 @@
|
||||
let hue = ((0.5 - v) * 120).toString(10);
|
||||
let lightness = 90 - Math.abs(v) * 70;
|
||||
|
||||
return ['hsl(', hue, ',60%,', lightness, '%)'].join('');
|
||||
return ['hsl(', hue, ',70%,', lightness, '%)'].join('');
|
||||
}
|
||||
|
||||
function surfaceFillCallback(context) {
|
||||
|
Reference in New Issue
Block a user