Skip to content

Commit

Permalink
editoast: make intersection as a type
Browse files Browse the repository at this point in the history
Signed-off-by: Jean SIMARD <[email protected]>
  • Loading branch information
woshilapin committed Sep 17, 2024
1 parent 512fe9a commit cd98dc3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
28 changes: 25 additions & 3 deletions editoast/src/views/path/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Intersection> {
// Handle the length computation in mm
let mut next_pos: u64 = 0;
let mut current_pos: u64;
Expand Down Expand Up @@ -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<u64>,
current: u64,
intersections: Vec<(u64, u64)>,
intersections: Vec<Intersection>,
}

impl IntersectionBuilder {
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion editoast/src/views/train_schedule/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit cd98dc3

Please sign in to comment.