mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-03 17:12:31 +00:00
prevent slope NaNs
This commit is contained in:
@@ -688,7 +688,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
_computeSlope(): number[] {
|
_computeSlope(): number[] {
|
||||||
const points = this.trkpt;
|
const points = this.trkpt;
|
||||||
|
|
||||||
return distanceWindowSmoothingWithDistanceAccumulator(points, 50, (accumulated, start, end) => 100 * (points[end].ele - points[start].ele) / accumulated);
|
return distanceWindowSmoothingWithDistanceAccumulator(points, 50, (accumulated, start, end) => 100 * ((points[end].ele ?? 0) - (points[start].ele ?? 0)) / (accumulated > 0 ? accumulated : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
getNumberOfTrackPoints(): number {
|
getNumberOfTrackPoints(): number {
|
||||||
@@ -1159,7 +1159,7 @@ function distanceWindowSmoothing(points: ReadonlyArray<Readonly<TrackPoint>>, di
|
|||||||
|
|
||||||
let start = 0, end = 0, accumulated = 0;
|
let start = 0, end = 0, accumulated = 0;
|
||||||
for (var i = 0; i < points.length; i++) {
|
for (var i = 0; i < points.length; i++) {
|
||||||
while (start < i && distance(points[start].getCoordinates(), points[i].getCoordinates()) > distanceWindow) {
|
while (start + 1 < i && distance(points[start].getCoordinates(), points[i].getCoordinates()) > distanceWindow) {
|
||||||
if (remove) {
|
if (remove) {
|
||||||
accumulated -= remove(start);
|
accumulated -= remove(start);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user