mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
first stats fixes
This commit is contained in:
@@ -91,8 +91,8 @@ export class GPXFile extends GPXTreeNode<Track>{
|
||||
super();
|
||||
this.attributes = cloneJSON(gpx.attributes);
|
||||
this.metadata = cloneJSON(gpx.metadata);
|
||||
this.wpt = gpx.wpt.map((waypoint) => new Waypoint(waypoint));
|
||||
this.trk = gpx.trk.map((track) => new Track(track));
|
||||
this.wpt = gpx.wpt ? gpx.wpt.map((waypoint) => new Waypoint(waypoint)) : [];
|
||||
this.trk = gpx.trk ? gpx.trk.map((track) => new Track(track)) : [];
|
||||
|
||||
this.statistics = this.computeStatistics();
|
||||
}
|
||||
@@ -132,7 +132,7 @@ export class Track extends GPXTreeNode<TrackSegment> {
|
||||
this.src = track.src;
|
||||
this.link = cloneJSON(track.link);
|
||||
this.type = track.type;
|
||||
this.trkseg = track.trkseg.map((seg) => new TrackSegment(seg));
|
||||
this.trkseg = track.trkseg ? track.trkseg.map((seg) => new TrackSegment(seg)) : [];
|
||||
this.extensions = cloneJSON(track.extensions);
|
||||
}
|
||||
|
||||
@@ -261,6 +261,10 @@ export class TrackSegment extends GPXTreeLeaf {
|
||||
let left = i - j, right = i + j + 1;
|
||||
let contributed = false;
|
||||
for (let k of [left, right]) {
|
||||
if (k < 0 || k >= points.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let dist = distance(points[i].getCoordinates(), points[k].getCoordinates());
|
||||
if (dist > ELEVATION_SMOOTHING_DISTANCE_THRESHOLD) {
|
||||
break;
|
||||
@@ -338,7 +342,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
||||
type: "Feature",
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
coordinates: this.trkpt.map((point) => [point.attributes.lng, point.attributes.lat])
|
||||
coordinates: this.trkpt.map((point) => [point.attributes.lon, point.attributes.lat])
|
||||
},
|
||||
properties: {}
|
||||
};
|
||||
@@ -464,7 +468,7 @@ function distance(coord1: Coordinates, coord2: Coordinates): number {
|
||||
const rad = Math.PI / 180;
|
||||
const lat1 = coord1.lat * rad;
|
||||
const lat2 = coord2.lat * rad;
|
||||
const a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((coord2.lng - coord1.lng) * rad);
|
||||
const a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((coord2.lon - coord1.lon) * rad);
|
||||
const maxMeters = earthRadius * Math.acos(Math.min(a, 1));
|
||||
return maxMeters;
|
||||
}
|
@@ -42,7 +42,7 @@ export type WaypointType = {
|
||||
|
||||
export type Coordinates = {
|
||||
lat: number;
|
||||
lng: number;
|
||||
lon: number;
|
||||
};
|
||||
|
||||
export type TrackType = {
|
||||
|
@@ -48,7 +48,7 @@ describe('GPX operations', () => {
|
||||
const reversedPoint = reversedSegment.trkpt[originalSegment.trkpt.length - k - 1];
|
||||
|
||||
expect(reversedPoint.attributes.lat).toBe(originalPoint.attributes.lat);
|
||||
expect(reversedPoint.attributes.lng).toBe(originalPoint.attributes.lng);
|
||||
expect(reversedPoint.attributes.lon).toBe(originalPoint.attributes.lon);
|
||||
expect(reversedPoint.ele).toBe(originalPoint.ele);
|
||||
|
||||
expect(reversed.getEndTimestamp().getTime() - reversedPoint.time.getTime()).toBe(originalPoint.time.getTime() - original.getStartTimestamp().getTime());
|
||||
|
@@ -32,7 +32,7 @@ describe("Parsing", () => {
|
||||
}
|
||||
|
||||
expect(segment.trkpt[0].attributes.lat).toBe(50.790867);
|
||||
expect(segment.trkpt[0].attributes.lng).toBe(4.404968);
|
||||
expect(segment.trkpt[0].attributes.lon).toBe(4.404968);
|
||||
expect(segment.trkpt[0].ele).toBe(109.0);
|
||||
});
|
||||
|
||||
@@ -76,7 +76,7 @@ describe("Parsing", () => {
|
||||
|
||||
const waypoint = result.wpt[0];
|
||||
expect(waypoint.attributes.lat).toBe(50.7836710064975);
|
||||
expect(waypoint.attributes.lng).toBe(4.410764082658738);
|
||||
expect(waypoint.attributes.lon).toBe(4.410764082658738);
|
||||
expect(waypoint.ele).toBe(122.0);
|
||||
expect(waypoint.name).toBe("Waypoint");
|
||||
expect(waypoint.cmt).toBe("Comment");
|
||||
|
Reference in New Issue
Block a user