Commit 012c137 1 parent 6c9aefe commit 012c137 Copy full SHA for 012c137
File tree 2 files changed +24
-1
lines changed
2 files changed +24
-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 @@ -191,7 +191,16 @@ fn compute_path(
191
191
let into_cost = |length : f64 | ( length * 100. ) . round ( ) as u64 ;
192
192
let get_length = |track : & String | track_sections[ track] . unwrap_track_section ( ) . length ;
193
193
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
+
195
204
let successors = |step : & PathfindingStep | {
196
205
// We initially don’t know in which direction start searching the path
197
206
// 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