@@ -93,27 +93,35 @@ impl Graph {
93
93
/// returns node_ids in adjacent grid cells
94
94
/// goes from most inner cell to cells with distance 1 to n until a node is found
95
95
fn get_adjacent_node_ids ( & self , lat : f32 , lng : f32 ) -> Vec < usize > {
96
- let lat_grid = ( lat * GRID_MULTIPLICATOR as f32 ) as usize ;
97
- let lng_grid = ( lng * GRID_MULTIPLICATOR as f32 ) as usize ;
96
+ let lat_grid = ( lat * GRID_MULTIPLICATOR as f32 ) as i32 ;
97
+ let lng_grid = ( lng * GRID_MULTIPLICATOR as f32 ) as i32 ;
98
98
let mut node_ids = Vec :: < usize > :: new ( ) ;
99
- match self . grid . get ( & ( lat_grid, lng_grid) ) {
99
+ match self . grid . get ( & ( lat_grid as usize , lng_grid as usize ) ) {
100
100
Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
101
101
None => ( ) ,
102
102
}
103
- let mut in_dist: usize = 1 ;
103
+ let mut in_dist: i32 = 1 ;
104
104
loop {
105
- for x in lat_grid - in_dist..lat_grid + in_dist + 1 {
106
- for y in lng_grid - in_dist..lng_grid + in_dist + 1 {
107
- if ( x < lat_grid + in_dist || x > lat_grid - in_dist)
108
- && ( y < lng_grid - in_dist || y > lng_grid + in_dist)
109
- {
110
- // both coordinates are bigger or smaller than the outer bounds => in inner square => already investigated
111
- continue ;
112
- }
113
- match self . grid . get ( & ( x, y) ) {
114
- Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
115
- None => continue ,
116
- }
105
+ for i in -in_dist..in_dist {
106
+ // top row left to right (increasing x, fix y)
107
+ match self . grid . get ( & ( ( lat_grid+i) as usize , ( lng_grid+in_dist) as usize ) ) {
108
+ Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
109
+ None => continue ,
110
+ }
111
+ // right column top to bottom (fix x, decreasing y)
112
+ match self . grid . get ( & ( ( lat_grid+in_dist) as usize , ( lng_grid-i) as usize ) ) {
113
+ Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
114
+ None => continue ,
115
+ }
116
+ // bottom row right to left (decreasing x, fix y)
117
+ match self . grid . get ( & ( ( lat_grid-i) as usize , ( lng_grid-in_dist) as usize ) ) {
118
+ Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
119
+ None => continue ,
120
+ }
121
+ // left column bottom to top (fix x, increasing y)
122
+ match self . grid . get ( & ( ( lat_grid-in_dist) as usize , ( lng_grid+i) as usize ) ) {
123
+ Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
124
+ None => continue ,
117
125
}
118
126
}
119
127
if node_ids. len ( ) > 0 {
0 commit comments