mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(places): keep two different tracks of the same name apart on import
Two GPX tracks a watch named alike (two "Afternoon Hike"s) were taken for one: the import compared a track only by its name, so the second was skipped as already in the trip. A track now matches a track of that name only when it also starts, ends and reaches as far as that one, to about a hundred metres, so the same file imported again is still skipped. The GPX, KML and tour imports and the tour preview all read the same rule. Closes #2870
This commit is contained in:
@@ -33,7 +33,9 @@ describe('isPlaceDuplicate / trackInsertedInDedupSet', () => {
|
||||
{ name: ' 008 ', lat: 1, lng: 2, route_geometry: '[[1,2],[3,4]]' },
|
||||
]);
|
||||
expect(isPlaceDuplicate({ name: 'hokitika gorge', lat: -42.9, lng: 171.0, track: true }, dedup)).toBe(false);
|
||||
expect(isPlaceDuplicate({ name: '008', lat: 1, lng: 2, track: true }, dedup)).toBe(true);
|
||||
expect(isPlaceDuplicate({ name: '008', lat: 1, lng: 2, track: true, routeGeometry: '[[1,2],[3,4]]' }, dedup)).toBe(
|
||||
true,
|
||||
);
|
||||
// A pin still matches every place of its name, a track included.
|
||||
expect(isPlaceDuplicate({ name: 'Hokitika Gorge', lat: null, lng: null }, dedup)).toBe(true);
|
||||
expect(isPlaceDuplicate({ name: '008', lat: null, lng: null }, dedup)).toBe(true);
|
||||
@@ -46,7 +48,37 @@ describe('isPlaceDuplicate / trackInsertedInDedupSet', () => {
|
||||
trackInsertedInDedupSet({ name: 'Ridge', lat: 1, lng: 2 }, bare);
|
||||
expect(isPlaceDuplicate({ name: 'Ridge', lat: 1, lng: 2, track: true }, bare)).toBe(false);
|
||||
trackInsertedInDedupSet({ name: 'Lake', lat: 1, lng: 2, track: true }, bare);
|
||||
expect([...(bare.trackNames ?? [])]).toEqual(['lake']);
|
||||
expect([...(bare.tracks ?? [])]).toEqual(['lake\u0000']);
|
||||
});
|
||||
|
||||
it('keeps two tracks of one name apart when they run differently (#2870)', () => {
|
||||
// Two watch hikes, both called "Afternoon Hike": one up the valley, one along the coast.
|
||||
const valley = '[[46.5,8.0,1200],[46.52,8.03,1500],[46.55,8.06,1900]]';
|
||||
const coast = '[[43.7,7.25],[43.72,7.3],[43.74,7.35]]';
|
||||
const dedup = dedupSetOf([{ name: 'Afternoon Hike', lat: 46.5, lng: 8.0, route_geometry: valley }]);
|
||||
expect(
|
||||
isPlaceDuplicate({ name: 'afternoon hike', lat: 43.7, lng: 7.25, track: true, routeGeometry: coast }, dedup),
|
||||
).toBe(false);
|
||||
// The same file again is still the same track, its points rounded or thinned as they may be.
|
||||
const valleyAgain = '[[46.50001,8.00002],[46.55,8.06]]';
|
||||
expect(
|
||||
isPlaceDuplicate({ name: 'Afternoon Hike', lat: 46.5, lng: 8.0, track: true, routeGeometry: valleyAgain }, dedup),
|
||||
).toBe(true);
|
||||
|
||||
// Within one file: the first of the two goes in, the second is not taken for it.
|
||||
const batch = emptyDedup();
|
||||
const first = { name: 'Day 1', lat: 46.5, lng: 8.0, track: true, routeGeometry: valley };
|
||||
const second = { name: 'Day 1', lat: 43.7, lng: 7.25, track: true, routeGeometry: coast };
|
||||
expect(isPlaceDuplicate(first, batch)).toBe(false);
|
||||
trackInsertedInDedupSet(first, batch);
|
||||
expect(isPlaceDuplicate(second, batch)).toBe(false);
|
||||
trackInsertedInDedupSet(second, batch);
|
||||
expect(isPlaceDuplicate({ ...second }, batch)).toBe(true);
|
||||
|
||||
// A line that does not parse falls back to the name alone, on both sides.
|
||||
const broken = dedupSetOf([{ name: 'Loop', lat: 1, lng: 2, route_geometry: 'not json' }]);
|
||||
expect(isPlaceDuplicate({ name: 'Loop', lat: 1, lng: 2, track: true, routeGeometry: '{}' }, broken)).toBe(true);
|
||||
expect(isPlaceDuplicate({ name: 'Loop', lat: 1, lng: 2, track: true, routeGeometry: coast }, broken)).toBe(false);
|
||||
});
|
||||
|
||||
it('matches a named place case- and whitespace-insensitively', () => {
|
||||
|
||||
Reference in New Issue
Block a user