Skip to content

Commit 6733106

Browse files
committed
Merge branch 'master' of github.com:Stunkymonkey/osm-dijkstra
2 parents e442de7 + 82f66ac commit 6733106

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

web/src/graph.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,35 @@ impl Graph {
9999
/// returns node_ids in adjacent grid cells
100100
/// goes from most inner cell to cells with distance 1 to n until a node is found
101101
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;
104104
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)) {
106106
Some(adjacent_node_ids) => node_ids.extend(adjacent_node_ids),
107107
None => (),
108108
}
109-
let mut in_dist: usize = 1;
109+
let mut in_dist: i32 = 1;
110110
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,
123131
}
124132
}
125133
if node_ids.len() > 0 {

web/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ fn query(request: web::Json<Query>, dijkstra: web::Data<Graph>) -> web::Json<Res
7171
// println!("travel_type: {}, by_distance: {}", travel_type, by_distance);
7272

7373
// search for clicked points
74+
let timing_find = Instant::now();
7475
let start_id: usize = dijkstra.get_point_id(start.latitude, start.longitude, travel_type);
7576
let end_id: usize = dijkstra.get_point_id(end.latitude, end.longitude, travel_type);
77+
println!("### duration for get_point_id(): {:?}", timing_find.elapsed());
7678

7779
let timing = Instant::now();
7880
let tmp = dijkstra.find_path(start_id, end_id, travel_type, by_distance);

0 commit comments

Comments
 (0)