mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-28 10:47:17 +00:00
route full support
This commit is contained in:
1 parent
c842da8dc1
commit
b6c0f5190a
91 files changed
+2523
-847
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::{Link, Track, Waypoints};
|
||||
use crate::{Link, Route, Track, TrackSegment, Waypoints};
|
||||
|
||||
use super::common::uuid_id;
|
||||
|
||||
@@ -8,6 +8,9 @@ uuid_id!(FileId);
|
||||
pub struct File {
|
||||
pub id: FileId,
|
||||
pub info: FileInfo,
|
||||
/// The routes come before the tracks, as in GPX: everything that goes through the segments
|
||||
/// of a file (statistics, the elevation profile...) takes the ones of the routes first.
|
||||
pub rte: Vec<Route>,
|
||||
pub trk: Vec<Track>,
|
||||
pub wpt: Waypoints,
|
||||
}
|
||||
@@ -29,3 +32,50 @@ pub struct Author {
|
||||
/// The author has a single link, unlike the other elements.
|
||||
pub link: Option<Link>,
|
||||
}
|
||||
|
||||
/// Where a segment is in its file: the one of a route, or one of a track.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SegmentIndex {
|
||||
Route(usize),
|
||||
Track { trk: usize, seg: usize },
|
||||
}
|
||||
|
||||
impl File {
|
||||
/// The segments of the routes, then the ones of the tracks.
|
||||
pub fn segments(&self) -> impl Iterator<Item = &TrackSegment> {
|
||||
self.rte
|
||||
.iter()
|
||||
.map(|rte| &rte.seg)
|
||||
.chain(self.trk.iter().flat_map(|trk| &trk.trkseg))
|
||||
}
|
||||
|
||||
/// Where the segments are, in the order of [`File::segments`].
|
||||
pub fn segment_indices(&self) -> impl Iterator<Item = SegmentIndex> + '_ {
|
||||
(0..self.rte.len())
|
||||
.map(SegmentIndex::Route)
|
||||
.chain(self.trk.iter().enumerate().flat_map(|(trk, track)| {
|
||||
(0..track.trkseg.len()).map(move |seg| SegmentIndex::Track { trk, seg })
|
||||
}))
|
||||
}
|
||||
|
||||
/// The segment at `index`. Panics if there is none.
|
||||
pub fn segment(&self, index: SegmentIndex) -> &TrackSegment {
|
||||
match index {
|
||||
SegmentIndex::Route(rte) => &self.rte[rte].seg,
|
||||
SegmentIndex::Track { trk, seg } => &self.trk[trk].trkseg[seg],
|
||||
}
|
||||
}
|
||||
|
||||
/// The segment at `index`. Panics if there is none.
|
||||
pub fn segment_mut(&mut self, index: SegmentIndex) -> &mut TrackSegment {
|
||||
match index {
|
||||
SegmentIndex::Route(rte) => &mut self.rte[rte].seg,
|
||||
SegmentIndex::Track { trk, seg } => &mut self.trk[trk].trkseg[seg],
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the file has no route nor track.
|
||||
pub fn has_no_path(&self) -> bool {
|
||||
self.rte.is_empty() && self.trk.is_empty()
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ mod chunk;
|
||||
mod chunked;
|
||||
mod common;
|
||||
mod file;
|
||||
mod route;
|
||||
mod segment;
|
||||
mod track;
|
||||
mod trackpoint;
|
||||
@@ -14,6 +15,7 @@ pub use chunk::*;
|
||||
pub use chunked::*;
|
||||
pub use common::*;
|
||||
pub use file::*;
|
||||
pub use route::*;
|
||||
pub use segment::*;
|
||||
pub use track::*;
|
||||
pub use trackpoint::*;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
use crate::{TrackInfo, TrackSegment};
|
||||
|
||||
use super::common::uuid_id;
|
||||
|
||||
uuid_id!(RouteId);
|
||||
|
||||
/// A route of the file (`rte`): like a track, but with a single segment, its points.
|
||||
///
|
||||
/// It has the information of a track: GPX gives the same to both.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Route {
|
||||
pub id: RouteId,
|
||||
pub info: TrackInfo,
|
||||
pub seg: TrackSegment,
|
||||
}
|
||||
Reference in new issue
Block a user