@@ -16,7 +16,7 @@ pub struct Graph {
16
16
nodes : Vec < Node > ,
17
17
ways : Vec < Way > ,
18
18
offset : Vec < usize > ,
19
- grid : HashMap < ( usize , usize ) , Vec < usize > >
19
+ grid : HashMap < ( usize , usize ) , Vec < usize > > ,
20
20
}
21
21
22
22
#[ derive( Copy , Clone , Eq , PartialEq ) ]
@@ -37,12 +37,17 @@ impl PartialOrd for State {
37
37
}
38
38
39
39
impl Graph {
40
- pub fn new ( nodes : Vec < Node > , ways : Vec < Way > , offset : Vec < usize > , grid : HashMap < ( usize , usize ) , Vec < usize > > ) -> Self {
40
+ pub fn new (
41
+ nodes : Vec < Node > ,
42
+ ways : Vec < Way > ,
43
+ offset : Vec < usize > ,
44
+ grid : HashMap < ( usize , usize ) , Vec < usize > > ,
45
+ ) -> Self {
41
46
Graph {
42
47
nodes,
43
48
ways,
44
49
offset,
45
- grid
50
+ grid,
46
51
}
47
52
}
48
53
@@ -54,14 +59,13 @@ impl Graph {
54
59
for node_id in adjacent_nodes {
55
60
match self . nodes . get ( node_id) {
56
61
Some ( node) => {
57
- let distance =
58
- calc_distance ( lat, long, node. latitude , node. longitude ) ;
62
+ let distance = calc_distance ( lat, long, node. latitude , node. longitude ) ;
59
63
if distance < min_distance {
60
64
min_distance = distance;
61
65
min_distance_id = node_id;
62
66
}
63
- } ,
64
- None => continue
67
+ }
68
+ None => continue ,
65
69
}
66
70
}
67
71
return min_distance_id;
@@ -92,24 +96,26 @@ impl Graph {
92
96
let mut node_ids = Vec :: < usize > :: new ( ) ;
93
97
match self . grid . get ( & ( lat_grid, lng_grid) ) {
94
98
Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
95
- None => ( )
99
+ None => ( ) ,
96
100
}
97
101
let mut in_dist: usize = 1 ;
98
102
loop {
99
- for x in lat_grid-in_dist..lat_grid+in_dist+1 {
100
- for y in lng_grid-in_dist..lng_grid+in_dist+1 {
101
- if ( x < lat_grid+in_dist || x > lat_grid-in_dist) && ( y < lng_grid-in_dist || y > lng_grid+in_dist) {
103
+ for x in lat_grid - in_dist..lat_grid + in_dist + 1 {
104
+ for y in lng_grid - in_dist..lng_grid + in_dist + 1 {
105
+ if ( x < lat_grid + in_dist || x > lat_grid - in_dist)
106
+ && ( y < lng_grid - in_dist || y > lng_grid + in_dist)
107
+ {
102
108
// both coordinates are bigger or smaller than the outer bounds => in inner square => already investigated
103
109
continue ;
104
110
}
105
- match self . grid . get ( & ( x, y) ) {
111
+ match self . grid . get ( & ( x, y) ) {
106
112
Some ( adjacent_node_ids) => node_ids. extend ( adjacent_node_ids) ,
107
- None => continue
113
+ None => continue ,
108
114
}
109
115
}
110
116
}
111
117
if node_ids. len ( ) > 0 {
112
- return node_ids
118
+ return node_ids;
113
119
} else {
114
120
// search in next level
115
121
in_dist += 1 ;
0 commit comments