Commit bd5d68e 1 parent 149b9ea commit bd5d68e Copy full SHA for bd5d68e
File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,20 @@ impl BoundingBox {
54
54
pub fn from_geometry ( value : Geometry ) -> Result < Self > {
55
55
Self :: from_geojson ( value. value )
56
56
}
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
+ }
57
71
}
58
72
59
73
#[ derive( Debug , Error , EditoastError ) ]
Original file line number Diff line number Diff line change @@ -184,7 +184,19 @@ fn compute_path(
184
184
let into_cost = |length : f64 | ( length * 100. ) . round ( ) as u64 ;
185
185
let get_length = |track : & String | track_sections[ track] . unwrap_track_section ( ) . length ;
186
186
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
+
188
200
let successors = |step : & PathfindingStep | {
189
201
// We initially don’t know in which direction start searching the path
190
202
// So the first step as two successors, at the same track-position, but in opposite directions
You can’t perform that action at this time.
0 commit comments