mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-15 07:07:07 +00:00
Migration to new Rust-based engine (#401)
* wasm first steps * parsing start * parsing continued * progress * progress * progress * progress * progress * progress * progress * progress * fixes * reorganize * change type * fix * progress * refactoring * progress * progress * progress * keep style info * progress * progress * remove (copy) in name * progress * merge methods into 1 * splice * progress * progress * progress * cleaning * progress * progress * progress * visibility * progress * progress * progress * progress * progress * fixes * progress * fix markers * fix * progress * progress * progress * progress * progress * progress * small fix * use engine info * fix popups * small fix * progress * progress * progress * clean tool * handle self closing elements * reduce data exchanges across boundary * copy on wasm side to avoid any data corruption * speed fix * routing * refactoring * reverse * reverse * crop * split * merge * progress * time tool * fix bounds for waypoints * reduce * fix reactivity * handle corrupt time data * export * progress * remove gpx js package * remove todo * update readme * cleaning * progress * fix link fields * remove unused fields * refactoring and tests * import and export of routes, ref #192 * per-chunk categories storage * cross-tab sync * outdated state * refactoring * reorder methods * refactoring * fix * improve flow * renaming * progress * progress * fix * progress * per file history * keep original flag * use history variant * fix * progress * file explorer * progress * fix * sticky folders * improved sticky folders * fix sortable * fix sortable * fix * fix tab size * no file delete on desktop * fix routing on other file * fix sorting * remember language * open links in browser * commit missing changes * avoid selecting on resize * clarify filename * explorer actions * fix folder styling * drop anywhere in folder * cleaning * fixes * remove focus-ring * full screen * small fix * consistent highlight color * improved preview * performance improvements * sparser data transfers * sparser data transfers * show popup once data is loaded * fix routing control size * fix * sparse desktop build * remove custom ign styles * use new endpoint for openhikingmap * strip native menu * reorder context menu items * route full support * route - track conversion * create route file action * route export, filter out anchors at high zoom level * clarify name handling * move hide & center to view * routes continued * update docs * fix power format, closes #378 * lint fixes * fix display of additional data with gaps, closes #361 * fix linting issues * fix import modules * fix multidrag * change base to resolve * fix type errors * fix layer typings * fix last type error * each keys * improve typings * deploy to cloudflare --------- Co-authored-by: vcoppe <vcoppe@hexaly.com>
This commit is contained in:
1 parent
6a0d434371
commit
8fe7d8d64d
484 files changed
+53949
-41152
No files matched your search
@@ -0,0 +1,91 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{File, FileId, SegmentLocation, State, TrackSegment};
|
||||
|
||||
/// Edits the segments at `locations`, calling `f` with the position of each location in the slice
|
||||
/// and its segment, in that order.
|
||||
///
|
||||
/// Each file concerned is copied once (cheap, trackpoints are shared chunks) and stored back as a
|
||||
/// new snapshot. The segments take care of their own revision (see [`TrackSegment`]).
|
||||
pub fn update_segments(
|
||||
state: &mut State,
|
||||
locations: &[SegmentLocation],
|
||||
mut f: impl FnMut(usize, &mut TrackSegment),
|
||||
) {
|
||||
let mut files: HashMap<FileId, File> = HashMap::new();
|
||||
for (i, location) in locations.iter().enumerate() {
|
||||
let file = files
|
||||
.entry(location.file_id)
|
||||
.or_insert_with(|| (*state.files[&location.file_id]).clone());
|
||||
f(i, file.segment_mut(location.index));
|
||||
}
|
||||
for (file_id, file) in files {
|
||||
state.files.insert(file_id, Rc::new(file));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::engine::command::fixture::Fixture;
|
||||
|
||||
use crate::SegmentIndex;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn fixture() -> (Fixture, FileId) {
|
||||
let mut fx = Fixture::default();
|
||||
let data = std::fs::read("data/with_tracks_and_segments.gpx").unwrap();
|
||||
let file = Rc::new(crate::parse(&data, &mut Default::default()).unwrap());
|
||||
let id = file.id;
|
||||
fx.files.insert(id, file);
|
||||
(fx, id)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_only_the_given_segments_are_edited_in_order() {
|
||||
let (mut fx, id) = fixture();
|
||||
let before = fx.files[&id].clone();
|
||||
let locations = [
|
||||
SegmentLocation {
|
||||
file_id: id,
|
||||
index: SegmentIndex::Track { trk: 1, seg: 0 },
|
||||
},
|
||||
SegmentLocation {
|
||||
file_id: id,
|
||||
index: SegmentIndex::Track { trk: 0, seg: 0 },
|
||||
},
|
||||
];
|
||||
let mut calls = vec![];
|
||||
update_segments(&mut fx.state(), &locations, |i, segment| {
|
||||
calls.push(i);
|
||||
segment.update(0, |trkpt| trkpt.ele = 1234.0);
|
||||
});
|
||||
|
||||
assert_eq!(calls, vec![0, 1]);
|
||||
let after = &fx.files[&id];
|
||||
assert!(!Rc::ptr_eq(after, &before));
|
||||
for (trk, seg) in [(1, 0), (0, 0)] {
|
||||
assert_eq!(after.trk[trk].trkseg[seg][0].ele, 1234.0);
|
||||
assert_ne!(
|
||||
after.trk[trk].trkseg[seg].rev_id,
|
||||
before.trk[trk].trkseg[seg].rev_id
|
||||
);
|
||||
}
|
||||
// the other segments are the same ones
|
||||
assert_eq!(
|
||||
after.trk[0].trkseg[1].rev_id,
|
||||
before.trk[0].trkseg[1].rev_id
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_location_leaves_the_files_alone() {
|
||||
let (mut fx, id) = fixture();
|
||||
let before = fx.files[&id].clone();
|
||||
update_segments(&mut fx.state(), &[], |_, _| panic!("nothing to edit"));
|
||||
assert!(Rc::ptr_eq(&fx.files[&id], &before));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user