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