Skip to content

Commit 012c137

Browse files
committed
editoast: pathfinding: initial upperbound is based on begin/end track’s bboxes
1 parent 6c9aefe commit 012c137

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

editoast/src/map/bounding_box.rs

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ impl BoundingBox {
5454
pub fn from_geometry(value: Geometry) -> Result<Self> {
5555
Self::from_geojson(value.value)
5656
}
57+
58+
/// Computes the length (in meters) of the diagonal
59+
/// It represents the longest distance as the crow flies between two points in the box
60+
pub fn diagonal_length(&self) -> f64 {
61+
let a = osm4routing::Coord {
62+
lon: self.0 .0,
63+
lat: self.0 .1,
64+
};
65+
let b = osm4routing::Coord {
66+
lon: self.1 .0,
67+
lat: self.1 .1,
68+
};
69+
a.distance_to(b)
70+
}
5771
}
5872

5973
#[derive(Debug, Error, EditoastError)]

editoast/src/views/infra/pathfinding.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,16 @@ fn compute_path(
191191
let into_cost = |length: f64| (length * 100.).round() as u64;
192192
let get_length = |track: &String| track_sections[track].unwrap_track_section().length;
193193
let success = |step: &PathfindingStep| step.found;
194-
let mut best_distance = u64::MAX;
194+
195+
let starting_track = track_sections[&input.starting.track.0].unwrap_track_section();
196+
let ending_track = track_sections[&input.ending.track.0].unwrap_track_section();
197+
let best_distance = starting_track
198+
.bbox_geo
199+
.clone()
200+
.union(&ending_track.bbox_geo)
201+
.diagonal_length();
202+
let mut best_distance = into_cost(best_distance);
203+
195204
let successors = |step: &PathfindingStep| {
196205
// We initially don’t know in which direction start searching the path
197206
// So the first step as two successors, at the same track-position, but in opposite directions

0 commit comments

Comments
 (0)