mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-04 12:58:23 +00:00
merge methods into 1
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
use crate::{
|
|
||||||
Append, Clean, Crop, Delete, DeleteAll, Duplicate, Elevation, Extract, Load, Merge, Metadata,
|
|
||||||
MoveWaypoint, New, NewTrack, NewTrackSegment, NewWaypoint, Replace, Reverse, Split, Style,
|
|
||||||
Time,
|
|
||||||
};
|
|
||||||
use crate::{Apply, CommandError, State};
|
use crate::{Apply, CommandError, State};
|
||||||
|
use crate::{
|
||||||
|
Clean, Crop, Delete, DeleteAll, Duplicate, Elevation, Extract, Load, Merge, Metadata,
|
||||||
|
MoveWaypoint, New, NewTrack, NewTrackSegment, NewWaypoint, Reverse, SpliceTrackpoints, Split,
|
||||||
|
Style, Time,
|
||||||
|
};
|
||||||
|
|
||||||
/// A user action that edits the files. Each variant wraps the command's own struct, whose
|
/// A user action that edits the files. Each variant wraps the command's own struct, whose
|
||||||
/// effect is implemented in its own file (see `Apply`).
|
/// effect is implemented in its own file (see `Apply`).
|
||||||
@@ -22,8 +22,7 @@ pub enum Command<'a> {
|
|||||||
NewTrack(NewTrack),
|
NewTrack(NewTrack),
|
||||||
NewTrackSegment(NewTrackSegment),
|
NewTrackSegment(NewTrackSegment),
|
||||||
Reverse(Reverse),
|
Reverse(Reverse),
|
||||||
Append(Append<'a>),
|
SpliceTrackpoints(SpliceTrackpoints<'a>),
|
||||||
Replace(Replace<'a>),
|
|
||||||
NewWaypoint(NewWaypoint<'a>),
|
NewWaypoint(NewWaypoint<'a>),
|
||||||
MoveWaypoint(MoveWaypoint),
|
MoveWaypoint(MoveWaypoint),
|
||||||
Crop(Crop),
|
Crop(Crop),
|
||||||
@@ -48,8 +47,7 @@ impl Apply for Command<'_> {
|
|||||||
Command::NewTrack(c) => c.apply(state),
|
Command::NewTrack(c) => c.apply(state),
|
||||||
Command::NewTrackSegment(c) => c.apply(state),
|
Command::NewTrackSegment(c) => c.apply(state),
|
||||||
Command::Reverse(c) => c.apply(state),
|
Command::Reverse(c) => c.apply(state),
|
||||||
Command::Append(c) => c.apply(state),
|
Command::SpliceTrackpoints(c) => c.apply(state),
|
||||||
Command::Replace(c) => c.apply(state),
|
|
||||||
Command::NewWaypoint(c) => c.apply(state),
|
Command::NewWaypoint(c) => c.apply(state),
|
||||||
Command::MoveWaypoint(c) => c.apply(state),
|
Command::MoveWaypoint(c) => c.apply(state),
|
||||||
Command::Crop(c) => c.apply(state),
|
Command::Crop(c) => c.apply(state),
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
use crate::{Apply, CommandError, State};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Append<'a> {
|
|
||||||
pub lng: &'a [f64],
|
|
||||||
pub lat: &'a [f64],
|
|
||||||
pub ele: &'a [f64],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Apply for Append<'_> {
|
|
||||||
fn apply(self, _state: &mut State) -> Result<(), CommandError> {
|
|
||||||
// TODO
|
|
||||||
Err(CommandError::NotImplemented("append"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
mod append;
|
|
||||||
mod clean;
|
mod clean;
|
||||||
mod crop;
|
mod crop;
|
||||||
mod elevation;
|
mod elevation;
|
||||||
@@ -6,12 +5,11 @@ mod extract;
|
|||||||
mod merge;
|
mod merge;
|
||||||
mod move_waypoint;
|
mod move_waypoint;
|
||||||
mod new_waypoint;
|
mod new_waypoint;
|
||||||
mod replace;
|
|
||||||
mod reverse;
|
mod reverse;
|
||||||
|
mod splice_trackpoints;
|
||||||
mod split;
|
mod split;
|
||||||
mod time;
|
mod time;
|
||||||
|
|
||||||
pub use append::*;
|
|
||||||
pub use clean::*;
|
pub use clean::*;
|
||||||
pub use crop::*;
|
pub use crop::*;
|
||||||
pub use elevation::*;
|
pub use elevation::*;
|
||||||
@@ -19,7 +17,7 @@ pub use extract::*;
|
|||||||
pub use merge::*;
|
pub use merge::*;
|
||||||
pub use move_waypoint::*;
|
pub use move_waypoint::*;
|
||||||
pub use new_waypoint::*;
|
pub use new_waypoint::*;
|
||||||
pub use replace::*;
|
|
||||||
pub use reverse::*;
|
pub use reverse::*;
|
||||||
|
pub use splice_trackpoints::*;
|
||||||
pub use split::*;
|
pub use split::*;
|
||||||
pub use time::*;
|
pub use time::*;
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
use crate::{Apply, CommandError, State};
|
use crate::{Apply, CommandError, State};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Replace<'a> {
|
pub struct SpliceTrackpoints<'a> {
|
||||||
pub start: u32,
|
pub start: u32,
|
||||||
pub end: u32,
|
pub end: u32,
|
||||||
pub lng: &'a [f64],
|
pub lng: &'a [f64],
|
||||||
@@ -9,9 +9,9 @@ pub struct Replace<'a> {
|
|||||||
pub ele: &'a [f64],
|
pub ele: &'a [f64],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Apply for Replace<'_> {
|
impl Apply for SpliceTrackpoints<'_> {
|
||||||
fn apply(self, _state: &mut State) -> Result<(), CommandError> {
|
fn apply(self, _state: &mut State) -> Result<(), CommandError> {
|
||||||
// TODO
|
// TODO
|
||||||
Err(CommandError::NotImplemented("replace"))
|
Err(CommandError::NotImplemented("splice_trackpoints"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,15 +182,10 @@ pub fn reverse() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn append(lng: &[f64], lat: &[f64], ele: &[f64]) -> bool {
|
pub fn splice_trackpoints(start: u32, end: u32, lng: &[f64], lat: &[f64], ele: &[f64]) -> bool {
|
||||||
same_len(lng, lat, ele) && edit(Command::Append(engine::Append { lng, lat, ele }))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn replace(start: u32, end: u32, lng: &[f64], lat: &[f64], ele: &[f64]) -> bool {
|
|
||||||
start <= end
|
start <= end
|
||||||
&& same_len(lng, lat, ele)
|
&& same_len(lng, lat, ele)
|
||||||
&& edit(Command::Replace(engine::Replace {
|
&& edit(Command::SpliceTrackpoints(engine::SpliceTrackpoints {
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
lng,
|
lng,
|
||||||
|
|||||||
Reference in New Issue
Block a user