mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-03 17:12:31 +00:00
back to current elevation smoothing
This commit is contained in:
@@ -278,35 +278,24 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
let smoothed = [];
|
let smoothed = [];
|
||||||
|
|
||||||
const points = this.trkpt;
|
const points = this.trkpt;
|
||||||
|
|
||||||
|
let start = 0, end = -1, cumul = 0;
|
||||||
for (var i = 0; i < points.length; i++) {
|
for (var i = 0; i < points.length; i++) {
|
||||||
let weightedSum = 0;
|
while (start < i && distance(points[start].getCoordinates(), points[i].getCoordinates()) > ELEVATION_SMOOTHING_DISTANCE_THRESHOLD) {
|
||||||
let totalWeight = 0;
|
cumul -= points[start].ele;
|
||||||
|
start++;
|
||||||
for (let j = 0; ; j++) {
|
}
|
||||||
let left = i - j, right = i + j + 1;
|
while (end + 1 < points.length && distance(points[i].getCoordinates(), points[end + 1].getCoordinates()) <= ELEVATION_SMOOTHING_DISTANCE_THRESHOLD) {
|
||||||
let contributed = false;
|
cumul += points[end + 1].ele;
|
||||||
for (let k of [left, right]) {
|
end++;
|
||||||
if (k < 0 || k >= points.length) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let dist = distance(points[i].getCoordinates(), points[k].getCoordinates());
|
|
||||||
if (dist > ELEVATION_SMOOTHING_DISTANCE_THRESHOLD) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
let weight = ELEVATION_SMOOTHING_DISTANCE_THRESHOLD - dist;
|
|
||||||
weightedSum += points[j].ele * weight;
|
|
||||||
totalWeight += weight;
|
|
||||||
contributed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!contributed) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
smoothed.push(weightedSum / totalWeight);
|
smoothed.push(cumul / (end - start + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (points.length > 0) {
|
||||||
|
smoothed[0] = points[0].ele;
|
||||||
|
smoothed[points.length - 1] = points[points.length - 1].ele;
|
||||||
}
|
}
|
||||||
|
|
||||||
return smoothed;
|
return smoothed;
|
||||||
@@ -430,7 +419,7 @@ export class Waypoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GPXStatistics {
|
export class GPXStatistics {
|
||||||
distance: {
|
distance: {
|
||||||
moving: number;
|
moving: number;
|
||||||
total: number;
|
total: number;
|
||||||
@@ -482,7 +471,7 @@ class GPXStatistics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrackPointStatistics = {
|
export type TrackPointStatistics = {
|
||||||
distance: number[],
|
distance: number[],
|
||||||
time: number[],
|
time: number[],
|
||||||
speed: number[],
|
speed: number[],
|
||||||
|
Reference in New Issue
Block a user