diff --git a/editoast/src/views/path/projection.rs b/editoast/src/views/path/projection.rs index 1ddcce447d4..4385de99dd6 100644 --- a/editoast/src/views/path/projection.rs +++ b/editoast/src/views/path/projection.rs @@ -134,7 +134,7 @@ impl<'a> PathProjection<'a> { /// If there is no common track section range, the returned list is empty. /// The positions in the intersection list are guaranteed to increase. In other words `list[n].0 < list[n].1 <= list[n+1].0 < list[n+1].1` /// These positions can then be use in conjunction with [PathProjection::get_location]. - pub fn get_intersections(&self, track_ranges: &[TrackRange]) -> Vec<(u64, u64)> { + pub fn get_intersections(&self, track_ranges: &[TrackRange]) -> Vec { // Handle the length computation in mm let mut next_pos: u64 = 0; let mut current_pos: u64; @@ -206,10 +206,31 @@ impl<'a> PathProjection<'a> { } } +pub struct Intersection { + start: u64, + end: u64, +} +impl From<(u64, u64)> for Intersection { + fn from((start, end): (u64, u64)) -> Self { + debug_assert!( + start <= end, + "intersection should have a 'start' ({start}) smaller than 'end' ({end})" + ); + Self { start, end } + } +} +impl Intersection { + pub fn start(&self) -> u64 { + self.start + } + pub fn end(&self) -> u64 { + self.end + } +} struct IntersectionBuilder { start: Option, current: u64, - intersections: Vec<(u64, u64)>, + intersections: Vec, } impl IntersectionBuilder { @@ -224,7 +245,8 @@ impl IntersectionBuilder { fn finish(&mut self) { if let Some(start) = self.start { assert_ne!(start, self.current); - self.intersections.push((start, self.current)); + self.intersections + .push(Intersection::from((start, self.current))); } self.start = None; } diff --git a/editoast/src/views/train_schedule/projection.rs b/editoast/src/views/train_schedule/projection.rs index fb7e1405a5f..4fbcc8c5222 100644 --- a/editoast/src/views/train_schedule/projection.rs +++ b/editoast/src/views/train_schedule/projection.rs @@ -399,7 +399,8 @@ fn compute_space_time_curves( let mut space_time_curves = vec![]; for intersection in intersections { - let (start, end) = intersection; + let start = intersection.start(); + let end = intersection.end(); let start_index = find_index_upper(positions, start); let end_index = find_index_upper(positions, end);