From 87d6d5f30e796d3e5bd73e6949f996dc4babb604 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Sat, 3 Oct 2026 11:49:10 +0200 Subject: [PATCH] change type --- gpx-rs/src/engine/derived/statistics_cache.rs | 33 +++++++---- gpx-rs/src/engine/selection.rs | 59 +++++++------------ 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/gpx-rs/src/engine/derived/statistics_cache.rs b/gpx-rs/src/engine/derived/statistics_cache.rs index c5ba7c2b5..3906a2303 100644 --- a/gpx-rs/src/engine/derived/statistics_cache.rs +++ b/gpx-rs/src/engine/derived/statistics_cache.rs @@ -43,28 +43,32 @@ impl StatisticsCache { if let Some(state) = state { match selection { Selection::Empty => (), - Selection::File(s) => { - for id in s.files.iter() { + Selection::File { file_ids } => { + for id in file_ids.iter() { if let Some(file) = state.get(id) { self.add_file_stats(file, &mut stats); } } } - Selection::Track(s) => { - if let Some(file) = state.get(&s.file) { + Selection::Track { file_id, trk_ids } => { + if let Some(file) = state.get(file_id) { for trk in file.trk.iter() { - if s.trk.contains(&trk.id) { + if trk_ids.contains(&trk.id) { self.add_track_stats(trk, &mut stats); } } } } - Selection::TrackSegment(s) => { - if let Some(file) = state.get(&s.file) { + Selection::TrackSegment { + file_id, + trk_id, + trkseg_ids, + } => { + if let Some(file) = state.get(file_id) { for trk in file.trk.iter() { - if s.trk == trk.id { + if *trk_id == trk.id { for trkseg in trk.trkseg.iter() { - if s.trkseg.contains(&trkseg.id) { + if trkseg_ids.contains(&trkseg.id) { self.add_segment_stats(trkseg, &mut stats); } } @@ -73,13 +77,16 @@ impl StatisticsCache { } } } - Selection::Waypoints(s) => { - if let Some(file) = state.get(&s.file) { + Selection::Waypoints { file_id } => { + if let Some(file) = state.get(file_id) { self.add_file_stats(file, &mut stats); } } - Selection::Waypoint(s) => { - if let Some(file) = state.get(&s.file) { + Selection::Waypoint { + file_id, + wpt_ids: _, + } => { + if let Some(file) = state.get(file_id) { self.add_file_stats(file, &mut stats); } } diff --git a/gpx-rs/src/engine/selection.rs b/gpx-rs/src/engine/selection.rs index e555f6826..2f4d6a42e 100644 --- a/gpx-rs/src/engine/selection.rs +++ b/gpx-rs/src/engine/selection.rs @@ -2,50 +2,35 @@ use std::collections::HashSet; use crate::{FileId, TrackId, TrackSegmentId, WaypointId}; -#[derive(Debug)] -pub struct FileSelection { - pub files: HashSet, -} - -#[derive(Debug)] -pub struct TrackSelection { - pub file: FileId, - pub trk: HashSet, -} - -#[derive(Debug)] -pub struct TrackSegmentSelection { - pub file: FileId, - pub trk: TrackId, - pub trkseg: HashSet, -} - -#[derive(Debug)] -pub struct WaypointsSelection { - pub file: FileId, -} - -#[derive(Debug)] -pub struct WaypointSelection { - pub file: FileId, - pub wpt: HashSet, -} - #[derive(Debug, Default)] pub enum Selection { #[default] Empty, - File(FileSelection), - Track(TrackSelection), - TrackSegment(TrackSegmentSelection), - Waypoints(WaypointsSelection), - Waypoint(WaypointSelection), + File { + file_ids: HashSet, + }, + Track { + file_id: FileId, + trk_ids: HashSet, + }, + TrackSegment { + file_id: FileId, + trk_id: TrackId, + trkseg_ids: HashSet, + }, + Waypoints { + file_id: FileId, + }, + Waypoint { + file_id: FileId, + wpt_ids: HashSet, + }, } impl Selection { pub fn select(&mut self, id: FileId) { - let mut files = HashSet::default(); - files.insert(id); - *self = Selection::File(FileSelection { files }); + let mut file_ids = HashSet::default(); + file_ids.insert(id); + *self = Selection::File { file_ids }; } }