Skip to content

Commit ba53d8e

Browse files
committed
editoast: pathfinding: initial upperbound is based on begin/end track’s bboxes
1 parent 714b2bc commit ba53d8e

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
@@ -191,7 +191,19 @@ 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+
// We build an upper bound that is the diagonal of the bounding box covering start and end
203+
// During the path search, we prune any route that is twice that distance
204+
// We set an upper bound of at least 10 km to avoid problems on very short distances
205+
let mut best_distance = into_cost(best_distance.max(10_000.0));
206+
195207
let successors = |step: &PathfindingStep| {
196208
// We initially don’t know in which direction start searching the path
197209
// So the first step as two successors, at the same track-position, but in opposite directions

0 commit comments

Comments
 (0)