Skip to content

Commit bd5d68e

Browse files
committed
editoast: pathfinding: initial upperbound is based on begin/end track’s bboxes
1 parent 149b9ea commit bd5d68e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-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

+13-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,19 @@ fn compute_path(
184184
let into_cost = |length: f64| (length * 100.).round() as u64;
185185
let get_length = |track: &String| track_sections[track].unwrap_track_section().length;
186186
let success = |step: &PathfindingStep| step.found;
187-
let mut best_distance = u64::MAX;
187+
188+
let starting_track = track_sections[&input.starting.track.0].unwrap_track_section();
189+
let ending_track = track_sections[&input.ending.track.0].unwrap_track_section();
190+
let best_distance = starting_track
191+
.bbox_geo
192+
.clone()
193+
.union(&ending_track.bbox_geo)
194+
.diagonal_length();
195+
// We build an upper bound that is the diagonal of the bounding box covering start and end
196+
// During the path search, we prune any route that is twice that distance
197+
// We set an upper bound of at least 10 km to avoid problems on very short distances
198+
let mut best_distance = into_cost(best_distance.max(10_000.0));
199+
188200
let successors = |step: &PathfindingStep| {
189201
// We initially don’t know in which direction start searching the path
190202
// So the first step as two successors, at the same track-position, but in opposite directions

0 commit comments

Comments
 (0)