# gpx-parsing Specification ## Purpose Robust, lenient GPX parsing in `@trails-cool/gpx`: a file any mainstream app exports imports correctly, and a file with some broken points imports with those points discarded rather than corrupting stats or being rejected. Covers invalid-point skipping (no Null Island / NaN totals), `` route support, post-parse timestamp repair, metadata/`` fallback, and a fixture corpus as the regression mechanism — while `validateGpx` stays the strict backstop. ## Requirements ### Requirement: Invalid track points are skipped, not defaulted The GPX parser SHALL skip track and route points whose `lat` or `lon` attribute is missing or does not parse to a finite number, and SHALL treat an unparseable `` value as absent elevation. Skipped or repaired points SHALL never surface as `0,0` coordinates or `NaN` values in parsed output, distance, or elevation totals. Segments left with fewer than two points after skipping SHALL be dropped. #### Scenario: Point with missing coordinates is skipped - **WHEN** a track contains a `trkpt` without a `lat` attribute among otherwise valid points - **THEN** that point is absent from the parsed track and no `0,0` point appears #### Scenario: Garbage coordinates do not poison stats - **WHEN** a `trkpt` has a non-numeric `lat` value - **THEN** the point is skipped and the computed distance and elevation totals are finite numbers #### Scenario: Unparseable elevation treated as missing - **WHEN** a `trkpt` has `` content that does not parse to a finite number - **THEN** the point is kept with no elevation and gain/loss totals remain finite #### Scenario: Degenerate segment dropped - **WHEN** a `trkseg` has only one valid point after skipping - **THEN** that segment does not appear in the parsed tracks ### Requirement: Route elements parse as tracks The GPX parser SHALL parse each `` element as a track segment, handling `rtept` identically to `trkpt` (including elevation, time, and invalid-point skipping), appended after any `` segments. #### Scenario: Route-only GPX imports - **WHEN** a GPX file contains only a `` with valid `rtept` points and no `` - **THEN** the parsed data contains one track segment with those points - **AND** journal validation accepts the file #### Scenario: Mixed tracks and routes - **WHEN** a GPX file contains both `` and `` elements - **THEN** all appear as track segments with track segments first ### Requirement: Timestamp repair The GPX parser SHALL repair point timestamps per segment: when more than half of a segment's timestamps are invalid, all timestamps in that segment SHALL be dropped; otherwise invalid timestamps SHALL be linearly interpolated between the nearest valid neighbors, with leading and trailing invalid runs set to the nearest valid timestamp. Repaired timestamps SHALL be valid ISO 8601 strings. #### Scenario: Sparse invalid timestamps interpolated - **WHEN** a segment has a minority of unparseable `