parsing start

This commit is contained in:
vcoppe
2026-09-18 09:03:51 +02:00
parent ed6264444f
commit 69049e1345
29 changed files with 6622 additions and 119 deletions
+11
View File
@@ -0,0 +1,11 @@
#[derive(Debug, Default)]
pub struct Link {
pub href: String,
pub text: Option<String>,
}
#[derive(Debug, Default)]
pub struct LngLat {
pub lng: f64,
pub lat: f64,
}
+26
View File
@@ -0,0 +1,26 @@
use std::rc::Rc;
use crate::gpx::{Link, Track, WaypointChunk};
#[derive(Debug, Default)]
pub struct GPXFile {
pub info: GPXFileInfo,
pub trk: Vec<Track>,
pub wpt: Vec<Rc<WaypointChunk>>,
}
#[derive(Debug, Default)]
pub struct GPXFileInfo {
pub name: String,
pub desc: Option<String>,
pub author: Option<Author>,
pub link: Option<Link>,
pub time: Option<i64>,
}
#[derive(Debug, Default)]
pub struct Author {
pub name: Option<String>,
pub email: Option<String>,
pub link: Option<Link>,
}
+13
View File
@@ -0,0 +1,13 @@
mod common;
mod file;
mod segment;
mod track;
mod trackpoint;
mod waypoint;
pub use common::*;
pub use file::*;
pub use segment::*;
pub use track::*;
pub use trackpoint::*;
pub use waypoint::*;
+39
View File
@@ -0,0 +1,39 @@
use std::{cell::RefCell, rc::Rc};
use crate::gpx::TrackPoint;
#[derive(Debug, Default)]
pub struct TrackSegment {
pub chunks: Vec<Rc<RefCell<TrackPointChunk>>>,
}
impl TrackSegment {
pub fn append(&mut self, trkpt: TrackPoint) {
if self
.chunks
.last()
.is_none_or(|c| c.borrow().trkpt.len() == MAX_CHUNK_SIZE)
{
self.add_chunk();
}
self.chunks
.last_mut()
.unwrap()
.borrow_mut()
.trkpt
.push(trkpt);
}
fn add_chunk(&mut self) {
self.chunks
.push(Rc::new(RefCell::new(TrackPointChunk::default())));
}
}
static MAX_CHUNK_SIZE: usize = 4096;
#[derive(Debug, Default)]
pub struct TrackPointChunk {
pub trkpt: Vec<TrackPoint>,
}
+20
View File
@@ -0,0 +1,20 @@
use crate::gpx::{Link, TrackSegment};
#[derive(Debug, Default)]
pub struct Track {
pub info: TrackInfo,
pub trkseg: Vec<TrackSegment>,
}
#[derive(Debug, Default)]
pub struct TrackInfo {
pub name: Option<String>,
pub cmt: Option<String>,
pub desc: Option<String>,
pub src: Option<String>,
pub link: Option<Link>,
pub type_: Option<String>,
pub color: Option<String>,
pub opacity: Option<f64>,
pub width: Option<f64>,
}
+13
View File
@@ -0,0 +1,13 @@
use crate::gpx::LngLat;
#[derive(Debug, Default)]
pub struct TrackPoint {
pub coordinates: LngLat,
pub ele: f64,
pub time: Option<i64>,
pub hr: Option<u16>,
pub cad: Option<u16>,
pub power: Option<u16>,
pub atemp: Option<i16>,
// TODO OSM data? or store intervals at a higher level?
}
+16
View File
@@ -0,0 +1,16 @@
use crate::gpx::{Link, LngLat};
pub type WaypointChunk = Vec<Waypoint>;
#[derive(Debug, Default)]
pub struct Waypoint {
pub coordinates: LngLat,
pub ele: f64,
pub time: Option<i64>,
pub name: Option<String>,
pub cmt: Option<String>,
pub desc: Option<String>,
pub link: Option<Link>,
pub sym: Option<String>,
pub type_: Option<String>,
}