From 7474f892ce051d0433df02b1290669bb2b1486a3 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Sun, 8 Nov 2026 15:32:12 +0100 Subject: [PATCH] cleaning --- gpx-rs/src/api/dto.rs | 20 ------ gpx-rs/src/api/queries.rs | 12 ---- gpx-rs/src/core/statistics/compute.rs | 8 --- gpx-rs/src/engine/derived/statistics_cache.rs | 1 + gpx-rs/src/engine/mod.rs | 18 +----- gpx-rs/src/engine/tests.rs | 18 ------ gpx-rs/src/storage/memory.rs | 8 ++- tauri/src/commands/queries.rs | 10 --- tauri/src/lib.rs | 1 - wasm/src/queries/files.rs | 12 ---- wasm/src/ts.rs | 10 --- website/src/lib/engine/backend/tauri.ts | 2 - website/src/lib/engine/backend/types.ts | 6 -- website/src/lib/engine/backend/wasm.ts | 1 - website/src/lib/engine/engine.ts | 21 ------- .../src/lib/engine/selection-helpers.test.ts | 7 --- website/src/lib/engine/selection-helpers.ts | 4 -- .../lib/engine/trackpoint-categories.test.ts | 62 ++++++------------- .../src/lib/engine/trackpoint-categories.ts | 27 +------- website/src/lib/engine/types.ts | 1 - 20 files changed, 28 insertions(+), 221 deletions(-) diff --git a/gpx-rs/src/api/dto.rs b/gpx-rs/src/api/dto.rs index af7224d3f..0915792ed 100644 --- a/gpx-rs/src/api/dto.rs +++ b/gpx-rs/src/api/dto.rs @@ -560,26 +560,6 @@ impl WaypointDetails { } } -#[derive(Serialize)] -pub struct TrackpointDetails { - lng: f64, - lat: f64, - ele: f64, - #[serde(skip_serializing_if = "Option::is_none")] - time: Option, -} - -impl TrackpointDetails { - pub fn new(pt: &engine::Trackpoint) -> Self { - Self { - lng: pt.coordinates.lng, - lat: pt.coordinates.lat, - ele: pt.ele, - time: pt.time.map(|t| t as f64), - } - } -} - /// A trackpoint of the selection: what the statistics buffers do not hold for each trackpoint. /// Absent fields are unknown. #[derive(Serialize)] diff --git a/gpx-rs/src/api/queries.rs b/gpx-rs/src/api/queries.rs index 5556e2296..b524aa45b 100644 --- a/gpx-rs/src/api/queries.rs +++ b/gpx-rs/src/api/queries.rs @@ -63,18 +63,6 @@ pub fn waypoint( .map(WaypointDetails::new) } -/// A trackpoint of a segment of a file, `None` if it does not exist. -pub fn trackpoint( - engine: &Engine, - file_id: Uuid, - segment_id: Uuid, - index: usize, -) -> Option { - engine - .trackpoint(&FileId(file_id), &engine::TrackSegmentId(segment_id), index) - .map(TrackpointDetails::new) -} - /// A file as GPX (UTF-8 bytes), `None` if it does not exist. The options say which data of the /// trackpoints to keep. pub fn export_file( diff --git a/gpx-rs/src/core/statistics/compute.rs b/gpx-rs/src/core/statistics/compute.rs index ac5270abf..d746adcec 100644 --- a/gpx-rs/src/core/statistics/compute.rs +++ b/gpx-rs/src/core/statistics/compute.rs @@ -24,14 +24,6 @@ pub struct Statistics { } impl Statistics { - pub fn total_speed(&self) -> Option { - self.global.total_speed() - } - - pub fn moving_speed(&self) -> Option { - self.global.moving_speed() - } - pub fn compute(trkseg: &TrackSegment) -> Self { let mut stats = Self::default(); if trkseg.is_empty() { diff --git a/gpx-rs/src/engine/derived/statistics_cache.rs b/gpx-rs/src/engine/derived/statistics_cache.rs index 9708bff3c..1c27a5797 100644 --- a/gpx-rs/src/engine/derived/statistics_cache.rs +++ b/gpx-rs/src/engine/derived/statistics_cache.rs @@ -36,6 +36,7 @@ impl StatisticsCache { } /// Statistics of the segments of the selection. + #[cfg(test)] pub fn get<'a>( &'a self, state: Option<&'a Files>, diff --git a/gpx-rs/src/engine/mod.rs b/gpx-rs/src/engine/mod.rs index 19386d960..73644fee0 100644 --- a/gpx-rs/src/engine/mod.rs +++ b/gpx-rs/src/engine/mod.rs @@ -11,7 +11,7 @@ pub use outcome::*; pub use state::*; use crate::{ - ExportOptions, FileId, GlobalStatistics, Restored, Snapshot, TrackSegmentId, Trackpoint, + ExportOptions, FileId, GlobalStatistics, Restored, Snapshot, TrackSegmentId, TrackpointCategories, Waypoint, WaypointId, reduction_distances, write, }; @@ -82,22 +82,6 @@ impl Engine { .find(|wpt| wpt.id == *id) } - /// A trackpoint of a segment (of a route or a track) of a file. `None` if it does not exist. - pub fn trackpoint( - &self, - file_id: &FileId, - segment_id: &TrackSegmentId, - index: usize, - ) -> Option<&Trackpoint> { - let segment = self - .history - .current()? - .get(file_id)? - .segments() - .find(|seg| seg.id == *segment_id)?; - (index < segment.len()).then(|| &segment[index]) - } - /// For each trackpoint of the selection (numbered as in the statistics), the tolerance up to /// which `Reduce` keeps it, see [`reduction_distances`]. pub fn reduction_distances(&self) -> Vec { diff --git a/gpx-rs/src/engine/tests.rs b/gpx-rs/src/engine/tests.rs index 516977def..2a9bbe98c 100644 --- a/gpx-rs/src/engine/tests.rs +++ b/gpx-rs/src/engine/tests.rs @@ -1169,24 +1169,6 @@ fn test_categories_are_shared_and_kept_by_the_history() { assert_eq!(expand(&engine.statistics().surface, 5), [1, 1, 0, 2, 2]); } -#[test] -fn test_trackpoint() { - let mut engine = TestEngine::default(); - load(&mut engine, "data/simple.gpx"); - let file = engine.order()[0]; - let structure = engine.file_structure(&file).unwrap(); - let seg = &structure.tracks[0].segments[0]; - let (seg_id, len) = (seg.id, seg.len); - let coordinates = engine.segment_coordinates(&seg_id).to_vec(); - let last = engine.trackpoint(&file, &seg_id, len - 1).unwrap(); - assert_eq!( - [last.coordinates.lng, last.coordinates.lat], - coordinates[(len - 1) * 2..] - ); - assert!(engine.trackpoint(&file, &seg_id, len).is_none()); - assert!(engine.trackpoint(&Default::default(), &seg_id, 0).is_none()); -} - #[test] fn test_export_writes_the_file_as_it_is() { let mut engine = TestEngine::default(); diff --git a/gpx-rs/src/storage/memory.rs b/gpx-rs/src/storage/memory.rs index 8395a8302..0594972e6 100644 --- a/gpx-rs/src/storage/memory.rs +++ b/gpx-rs/src/storage/memory.rs @@ -1,9 +1,9 @@ use std::cell::RefCell; use std::collections::HashMap; -use crate::{ - Batch, ChunkKey, ChunkKind, CommitError, FileId, Revision, Storage, StorageError, StoredData, -}; +#[cfg(test)] +use crate::ChunkKind; +use crate::{Batch, ChunkKey, CommitError, FileId, Revision, Storage, StorageError, StoredData}; /// A storage that lives as long as the session. It is what an engine without a host storage uses, /// and what the tests use. @@ -22,6 +22,7 @@ struct State { } /// How much there is in a storage. +#[cfg(test)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct StorageCounts { pub files: usize, @@ -29,6 +30,7 @@ pub struct StorageCounts { pub waypoint_chunks: usize, } +#[cfg(test)] impl MemoryStorage { /// How many files and chunks are stored. pub fn counts(&self) -> StorageCounts { diff --git a/tauri/src/commands/queries.rs b/tauri/src/commands/queries.rs index 95105e360..7b3b62e8d 100644 --- a/tauri/src/commands/queries.rs +++ b/tauri/src/commands/queries.rs @@ -57,16 +57,6 @@ pub fn waypoint( state.read(move |e| api::waypoint(e, file_id, waypoint_id)) } -#[tauri::command(async)] -pub fn trackpoint( - state: State, - file_id: Uuid, - segment_id: Uuid, - index: usize, -) -> Option { - state.read(move |e| api::trackpoint(e, file_id, segment_id, index)) -} - /// A file as GPX (UTF-8 bytes), the first byte telling whether the file exists. #[tauri::command(async)] #[allow(clippy::too_many_arguments)] diff --git a/tauri/src/lib.rs b/tauri/src/lib.rs index 743aa2fed..c98ded19c 100644 --- a/tauri/src/lib.rs +++ b/tauri/src/lib.rs @@ -173,7 +173,6 @@ pub fn register_commands(builder: tauri::Builder) -> tauri queries::can_redo, queries::can_paste, queries::waypoint, - queries::trackpoint, queries::export_file, queries::exportable_data, queries::reduction_distances, diff --git a/wasm/src/queries/files.rs b/wasm/src/queries/files.rs index 88fc1120f..a4ea1fdc2 100644 --- a/wasm/src/queries/files.rs +++ b/wasm/src/queries/files.rs @@ -101,18 +101,6 @@ pub fn waypoint(file_id: &str, waypoint_id: &str) -> WaypointDetails { optional_js(details).unchecked_into() } -/// A trackpoint of a segment of a file, `undefined` if it does not exist. -#[wasm_bindgen] -pub fn trackpoint(file_id: &str, segment_id: &str, index: usize) -> TrackpointDetails { - let details = - parse_uuid(file_id) - .zip(parse_uuid(segment_id)) - .and_then(|(file_id, segment_id)| { - with_engine(|e| api::trackpoint(e, file_id, segment_id, index)).flatten() - }); - optional_js(details).unchecked_into() -} - /// What was copied or cut and is waiting to be pasted, `undefined` if nothing: the kind of the /// elements and their ids (UUID strings). #[wasm_bindgen] diff --git a/wasm/src/ts.rs b/wasm/src/ts.rs index 73c0438ef..c2e567de6 100644 --- a/wasm/src/ts.rs +++ b/wasm/src/ts.rs @@ -59,14 +59,6 @@ export interface WaypointDetails { links?: { href: string; text?: string }[]; sym?: string; } -/** The position, elevation and time of a trackpoint. */ -export interface TrackpointDetails { - lng: number; - lat: number; - ele: number; - /** ms since epoch */ - time?: number; -} /** * A trackpoint of the selection: what the statistics buffers do not hold for each trackpoint. * Absent fields are unknown. @@ -189,8 +181,6 @@ extern "C" { pub type Selection; #[wasm_bindgen(typescript_type = "WaypointDetails | undefined")] pub type WaypointDetails; - #[wasm_bindgen(typescript_type = "TrackpointDetails | undefined")] - pub type TrackpointDetails; #[wasm_bindgen(typescript_type = "SelectionPoint | undefined")] pub type SelectionPoint; #[wasm_bindgen(typescript_type = "MoveTarget")] diff --git a/website/src/lib/engine/backend/tauri.ts b/website/src/lib/engine/backend/tauri.ts index 53c1af4e4..6d3ec02e1 100644 --- a/website/src/lib/engine/backend/tauri.ts +++ b/website/src/lib/engine/backend/tauri.ts @@ -159,8 +159,6 @@ export async function createTauriBackend(): Promise { (await invoke('file_statistics', { fileId })) ?? undefined, waypoint: async (fileId, waypointId) => (await invoke('waypoint', { fileId, waypointId })) ?? undefined, - trackpoint: async (fileId, segmentId, index) => - (await invoke('trackpoint', { fileId, segmentId, index })) ?? undefined, export_file: async (fileId, time, hr, cad, atemp, power, osm) => { const file = await optionalArray('export_file', Uint8Array, { fileId, diff --git a/website/src/lib/engine/backend/types.ts b/website/src/lib/engine/backend/types.ts index 450b3a98d..c98a22141 100644 --- a/website/src/lib/engine/backend/types.ts +++ b/website/src/lib/engine/backend/types.ts @@ -8,7 +8,6 @@ import type { Selection, SelectionPoint, StorageOpened, - TrackpointDetails, WaypointDetails, } from 'gpx-wasm'; import type { ExportOptions, MergeType, SelectMode, SplitType } from '../types'; @@ -266,11 +265,6 @@ export interface Backend { file_structure(fileId: string): Promise; file_statistics(fileId: string): Promise; waypoint(fileId: string, waypointId: string): Promise; - trackpoint( - fileId: string, - segmentId: string, - index: number - ): Promise; /** A file as GPX (UTF-8 bytes), `undefined` if it does not exist. */ export_file( fileId: string, diff --git a/website/src/lib/engine/backend/wasm.ts b/website/src/lib/engine/backend/wasm.ts index 26983237e..e781f3c15 100644 --- a/website/src/lib/engine/backend/wasm.ts +++ b/website/src/lib/engine/backend/wasm.ts @@ -123,7 +123,6 @@ export async function createWasmBackend(): Promise { file_structure: lift(w.file_structure), file_statistics: lift(w.file_statistics), waypoint: lift(w.waypoint), - trackpoint: lift(w.trackpoint), // a copy out of the memory of the engine, so a plain ArrayBuffer export_file: lift( (...args: Parameters) => diff --git a/website/src/lib/engine/engine.ts b/website/src/lib/engine/engine.ts index d127ee560..70b63e3ce 100644 --- a/website/src/lib/engine/engine.ts +++ b/website/src/lib/engine/engine.ts @@ -33,7 +33,6 @@ import { type FolderEntry, type UnsavedChoice, type WorkspaceState, - type TrackpointDetails, type WaypointDetails, } from './types'; @@ -881,15 +880,6 @@ class Engine { return this.read((b) => b.waypoint(fileId, waypointId), undefined); } - /** A trackpoint of a segment, `undefined` if it does not exist. */ - trackpoint( - fileId: string, - segmentId: string, - index: number - ): Promise { - return this.read((b) => b.trackpoint(fileId, segmentId, index), undefined); - } - /** * A file as GPX (UTF-8 bytes), `undefined` if it does not exist. The options say which data of the * trackpoints to keep. @@ -935,17 +925,6 @@ class Engine { return this.read((b) => b.reduction_distances(), new Float64Array()); } - // Coordinates, as flat [lng, lat, ...] arrays: copies. - // Refetch them when the `rev` of the segment (or the `waypointsRev` of the file) changed. - - segmentCoordinates(segmentId: string): Promise { - return this.read((b) => b.segment_coordinates(segmentId), new Float64Array()); - } - - waypointCoordinates(fileId: string): Promise { - return this.read((b) => b.waypoint_coordinates(fileId), new Float64Array()); - } - /** * Registers a consumer of the statistics that needs some of the metrics that are not part of * them by default (see `StatisticsMetric`). The metrics asked for by all the consumers are diff --git a/website/src/lib/engine/selection-helpers.test.ts b/website/src/lib/engine/selection-helpers.test.ts index 7ca665ee7..4cf8f2a55 100644 --- a/website/src/lib/engine/selection-helpers.test.ts +++ b/website/src/lib/engine/selection-helpers.test.ts @@ -9,7 +9,6 @@ import { hasSelectionWithin, isCovered, isInClipboard, - isEmpty, isSelected, isSelectionHidden, selectedElementIds, @@ -68,12 +67,6 @@ describe('selection helpers', () => { } }); - it('tells whether the selection is empty', () => { - assert.equal(isEmpty(empty), true); - assert.equal(isEmpty(files('F1')), false); - assert.equal(isEmpty(waypoints), false); - }); - it('lists the files holding something selected', () => { assert.deepEqual(selectedFileIds(empty), []); assert.deepEqual(selectedFileIds(files('F1', 'F2')), ['F1', 'F2']); diff --git a/website/src/lib/engine/selection-helpers.ts b/website/src/lib/engine/selection-helpers.ts index 285e262ba..adf43610b 100644 --- a/website/src/lib/engine/selection-helpers.ts +++ b/website/src/lib/engine/selection-helpers.ts @@ -65,10 +65,6 @@ export function coversSegments(selection: Selection): boolean { ); } -export function isEmpty(selection: Selection): boolean { - return selection.type === 'empty'; -} - /** Ids of the files holding something selected (or selected themselves). */ export function selectedFileIds(selection: Selection): string[] { switch (selection.type) { diff --git a/website/src/lib/engine/trackpoint-categories.test.ts b/website/src/lib/engine/trackpoint-categories.test.ts index c29e2a283..2bb0c649b 100644 --- a/website/src/lib/engine/trackpoint-categories.test.ts +++ b/website/src/lib/engine/trackpoint-categories.test.ts @@ -3,52 +3,30 @@ import assert from 'node:assert/strict'; import { categoryIntervals, categoryValue, - categoryValues, intervalAt, type CategoryIntervals, } from '$lib/engine/trackpoint-categories'; -describe('categoryValues', () => { - // asphalt, asphalt, unknown, gravel, gravel, gravel, unknown - const intervals: CategoryIntervals = { - starts: new Uint32Array([0, 2, 3, 6]), - values: new Uint8Array([1, 0, 2, 0]), - names: ['asphalt', 'gravel'], - }; - - it('is the name of the value of the interval of each trackpoint', () => { - assert.deepEqual(categoryValues(intervals, 7), [ - 'asphalt', - 'asphalt', - undefined, - 'gravel', - 'gravel', - 'gravel', - undefined, - ]); - }); - - it('goes on with the last interval until the last trackpoint', () => { - const last = { ...intervals, values: new Uint8Array([1, 0, 2, 2]) }; - assert.deepEqual(categoryValues(last, 9).slice(5), [ - 'gravel', - 'gravel', - 'gravel', - 'gravel', - ]); - }); - - it('does not go past the trackpoints', () => { - assert.deepEqual(categoryValues(intervals, 3), ['asphalt', 'asphalt', undefined]); - assert.deepEqual(categoryValues(intervals, 0), []); - }); - - it('is undefined without intervals, or for a code without name', () => { - assert.deepEqual(categoryValues(undefined, 2), [undefined, undefined]); - const unnamed = { starts: new Uint32Array([0]), values: new Uint8Array([3]), names: [] }; - assert.deepEqual(categoryValues(unnamed, 2), [undefined, undefined]); - }); -}); +/** The value of each of the `length` trackpoints, to compare with what is expected. */ +function categoryValues( + intervals: CategoryIntervals | undefined, + length: number +): (string | undefined)[] { + const result: (string | undefined)[] = new Array(length).fill(undefined); + if (!intervals) { + return result; + } + const { starts, values, names } = intervals; + for (let i = 0; i < starts.length; i++) { + if (!values[i]) { + continue; // unknown, already `undefined` + } + const name = names[values[i] - 1]; + const end = i + 1 < starts.length ? Math.min(starts[i + 1], length) : length; + result.fill(name, starts[i], end); + } + return result; +} describe('categoryIntervals', () => { it('groups the trackpoints that share a value', () => { diff --git a/website/src/lib/engine/trackpoint-categories.ts b/website/src/lib/engine/trackpoint-categories.ts index 894328204..a7c1fffba 100644 --- a/website/src/lib/engine/trackpoint-categories.ts +++ b/website/src/lib/engine/trackpoint-categories.ts @@ -11,31 +11,6 @@ export type CategoryIntervals = { names: string[]; }; -/** - * The value of each of the `length` trackpoints for a category of the engine, `undefined` when it - * is unknown, or when the category is missing (it is unknown for every trackpoint). The intervals - * are scanned once, so it takes a time linear in `length`. - */ -export function categoryValues( - intervals: CategoryIntervals | undefined, - length: number -): (string | undefined)[] { - const result: (string | undefined)[] = new Array(length).fill(undefined); - if (!intervals) { - return result; - } - const { starts, values, names } = intervals; - for (let i = 0; i < starts.length; i++) { - if (!values[i]) { - continue; // unknown, already `undefined` - } - const name = names[values[i] - 1]; - const end = i + 1 < starts.length ? Math.min(starts[i + 1], length) : length; - result.fill(name, starts[i], end); - } - return result; -} - /** The index of the interval of `starts` (sorted) that the trackpoint `index` is in, -1 if none. */ export function intervalAt(starts: Uint32Array, index: number): number { let low = 0; @@ -66,7 +41,7 @@ export function categoryValue( /** * The intervals of the trackpoints that share a value, for a value per trackpoint (`undefined` - * when unknown): the inverse of `categoryValues`. The names are in the order of their first + * when unknown). The names are in the order of their first * appearance. A value that is unknown everywhere gives no intervals. */ export function categoryIntervals(values: readonly (string | undefined)[]): CategoryIntervals { diff --git a/website/src/lib/engine/types.ts b/website/src/lib/engine/types.ts index 8cd6459df..98e8b9165 100644 --- a/website/src/lib/engine/types.ts +++ b/website/src/lib/engine/types.ts @@ -9,7 +9,6 @@ export type { FileStatus, FolderEntry, UnsavedChoice, WorkspaceState } from './b export type { Clipboard, WaypointDetails, - TrackpointDetails, MoveTarget, GlobalStatistics, SelectionPoint,