Skip to content

Commit abcb06b

Browse files
committed
Removed bunch of return commands in favor of the rust syntax of ending method with return value
1 parent d5cf7a9 commit abcb06b

File tree

6 files changed

+104
-123
lines changed

6 files changed

+104
-123
lines changed

src/mapping/chokes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,5 @@ fn distance(first: (usize, usize), second: (usize, usize)) -> f32 {
331331
let pos1 = Pos(first.0, first.1);
332332
let pos2 = Pos(second.0, second.1);
333333

334-
return pos1.euclidean_distance(&pos2) as f32 / MULTF32;
334+
pos1.euclidean_distance(&pos2) as f32 / MULTF32
335335
}

src/mapping/influence.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Map {
151151
maps.push(&mut self.reaper_pathing);
152152
}
153153

154-
return maps;
154+
maps
155155
}
156156

157157
fn get_pure_ground_influence_maps(&mut self) -> Vec<&mut PathFind> {
@@ -162,7 +162,7 @@ impl Map {
162162
maps.push(&mut self.reaper_pathing);
163163
}
164164

165-
return maps;
165+
maps
166166
}
167167

168168
pub fn get_ground_influence_maps(&mut self) -> Vec<&mut PathFind> {
@@ -176,7 +176,7 @@ impl Map {
176176
maps.push(&mut self.reaper_pathing);
177177
}
178178

179-
return maps;
179+
maps
180180
}
181181

182182
pub fn get_air_influence_maps(&mut self) -> Vec<&mut PathFind> {
@@ -187,6 +187,6 @@ impl Map {
187187
maps.push(&mut self.colossus_pathing);
188188
}
189189

190-
return maps;
190+
maps
191191
}
192192
}

src/mapping/map.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,29 @@ impl Map {
150150
}
151151
}
152152

153-
return result;
153+
result
154154
}
155155

156156
/// Returns current influence value
157157
fn current_influence(&self, map_type: u8, position: (f32, f32)) -> f32 {
158158
let map = self.get_map(map_type);
159159
let position_int = round_point2(position);
160160

161-
return map.current_influence(position_int) as f32;
161+
map.current_influence(position_int) as f32
162162
}
163163

164164
/// Finds the first reachable position within specified walking distance from the center point with lowest value
165165
fn lowest_influence_walk(&self, map_type: u8, center: (f32, f32), distance: f32) -> ((usize, usize), f32) {
166166
let map = self.get_map(map_type);
167167
let center_int = round_point2(center);
168168

169-
return map.lowest_influence_walk(center_int, distance);
169+
map.lowest_influence_walk(center_int, distance)
170170
}
171171

172172
/// Finds the first reachable position within specified distance from the center point with lowest value
173173
pub fn lowest_influence(&self, map_type: u8, center: (f32, f32), distance: usize) -> ((usize, usize), f32) {
174174
let map = self.get_map(map_type);
175-
return map.inline_lowest_value(center, distance);
175+
map.inline_lowest_value(center, distance)
176176
}
177177

178178
/// Find the shortest path values without considering influence and returns the path and distance
@@ -186,7 +186,7 @@ impl Map {
186186
let end_int = (end.0.round() as usize, end.1.round() as usize);
187187

188188
let map = self.get_map(map_type);
189-
return map.find_path(start_int, end_int, possible_heuristic);
189+
map.find_path(start_int, end_int, possible_heuristic)
190190
}
191191

192192
/// Find the shortest path values without considering influence and returns the path and distance
@@ -200,7 +200,7 @@ impl Map {
200200
let end_int = (end.0.round() as usize, end.1.round() as usize);
201201

202202
let map = self.get_map(map_type);
203-
return map.find_path_large(start_int, end_int, possible_heuristic);
203+
map.find_path_large(start_int, end_int, possible_heuristic)
204204
}
205205

206206
/// Find the path using influence values and returns the path and distance
@@ -213,7 +213,7 @@ impl Map {
213213
let start_int = (start.0.round() as usize, start.1.round() as usize);
214214
let end_int = (end.0.round() as usize, end.1.round() as usize);
215215
let map = self.get_map(map_type);
216-
return map.find_path_influence(start_int, end_int, possible_heuristic);
216+
map.find_path_influence(start_int, end_int, possible_heuristic)
217217
}
218218

219219
/// Find the path using influence values and returns the path and distance
@@ -226,7 +226,7 @@ impl Map {
226226
let start_int = (start.0.round() as usize, start.1.round() as usize);
227227
let end_int = (end.0.round() as usize, end.1.round() as usize);
228228
let map = self.get_map(map_type);
229-
return map.find_path_influence_large(start_int, end_int, possible_heuristic);
229+
map.find_path_influence_large(start_int, end_int, possible_heuristic)
230230
}
231231

232232
/// Find the shortest path values without considering influence and returns the path and distance
@@ -241,7 +241,7 @@ impl Map {
241241
let end_int = (end.0.round() as usize, end.1.round() as usize);
242242

243243
let map = self.get_map(map_type);
244-
return map.find_path_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
244+
map.find_path_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
245245
}
246246

247247
/// Find the shortest path values without considering influence and returns the path and distance
@@ -256,7 +256,7 @@ impl Map {
256256
let end_int = (end.0.round() as usize, end.1.round() as usize);
257257

258258
let map = self.get_map(map_type);
259-
return map.find_path_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
259+
map.find_path_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
260260
}
261261

262262
/// Find the path using influence values and returns the path and distance
@@ -270,7 +270,7 @@ impl Map {
270270
let start_int = (start.0.round() as usize, start.1.round() as usize);
271271
let end_int = (end.0.round() as usize, end.1.round() as usize);
272272
let map = self.get_map(map_type);
273-
return map.find_path_influence_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
273+
map.find_path_influence_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
274274
}
275275

276276
/// Find the path using influence values and returns the path and distance
@@ -284,7 +284,7 @@ impl Map {
284284
let start_int = (start.0.round() as usize, start.1.round() as usize);
285285
let end_int = (end.0.round() as usize, end.1.round() as usize);
286286
let map = self.get_map(map_type);
287-
return map.find_path_influence_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
287+
map.find_path_influence_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
288288
}
289289

290290
/// Finds a compromise where low influence matches with close position to the start position.
@@ -295,7 +295,7 @@ impl Map {
295295
distance: f32)
296296
-> ((f32, f32), f32) {
297297
let map = self.get_map(map_type);
298-
return map.find_low_inside_walk(start, target, distance);
298+
map.find_low_inside_walk(start, target, distance)
299299
}
300300
}
301301

@@ -402,14 +402,13 @@ impl Map {
402402

403403
let c = points[x][y].cliff_type;
404404

405-
if c != Cliff::None {
406-
if points[x + 1][y].cliff_type != c
407-
&& points[x - 1][y].cliff_type != c
408-
&& points[x][y + 1].cliff_type != c
409-
&& points[x][y - 1].cliff_type != c
410-
{
411-
points[x][y].cliff_type = Cliff::None;
412-
}
405+
if c != Cliff::None
406+
&& points[x + 1][y].cliff_type != c
407+
&& points[x - 1][y].cliff_type != c
408+
&& points[x][y + 1].cliff_type != c
409+
&& points[x][y - 1].cliff_type != c
410+
{
411+
points[x][y].cliff_type = Cliff::None;
413412
}
414413

415414
if !set_handled_overlord_spots.contains(&point_hash) && points[x][y].overlord_spot {
@@ -515,7 +514,7 @@ fn flood_fill_overlord(points: &mut Vec<Vec<map_point::MapPoint>>,
515514

516515
let mut result = true;
517516
points[x][y].overlord_spot = replacement;
518-
// if points[x][y].overlord_spot == target {
517+
519518
if y > 0 {
520519
result &= flood_fill_overlord(points, x, ((y as u32) - 1) as usize, target_height, replacement, set);
521520
}
@@ -528,7 +527,6 @@ fn flood_fill_overlord(points: &mut Vec<Vec<map_point::MapPoint>>,
528527
if x < points.len() - 1 {
529528
result &= flood_fill_overlord(points, x + 1, y, target_height, replacement, set);
530529
}
531-
// }
532530

533-
return result;
531+
result
534532
}

src/mapping/zones.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ impl Map {
7373

7474
pub fn get_zone(&self, position: (f32, f32)) -> i8 {
7575
let u_position = round_point2(position);
76-
let index = self.points[u_position.0][u_position.1].zone_index;
77-
index
76+
self.points[u_position.0][u_position.1].zone_index
7877
}
7978
}
8079

8180
impl Map {
82-
fn borrow(&mut self, x: usize, y: usize) -> &mut MapPoint { return &mut self.points[x][y]; }
83-
fn zone_index(&mut self, x: usize, y: usize) -> i8 { return self.points[x][y].zone_index; }
81+
fn borrow(&mut self, x: usize, y: usize) -> &mut MapPoint { &mut self.points[x][y] }
82+
fn zone_index(&mut self, x: usize, y: usize) -> i8 { self.points[x][y].zone_index }
8483
}
8584

8685
fn flood_fill(map: &mut Map,
@@ -128,7 +127,6 @@ fn flood_fill(map: &mut Map,
128127
return;
129128
}
130129

131-
// if points[x][y].overlord_spot == target {
132130
if y > 0 {
133131
flood_fill(map, x, ((y as u32) - 1) as usize, target_height, zone_index, origin, sorted_base_locations);
134132
}
@@ -141,7 +139,4 @@ fn flood_fill(map: &mut Map,
141139
if x < map.points.len() - 1 {
142140
flood_fill(map, x + 1, y, target_height, zone_index, origin, sorted_base_locations);
143141
}
144-
// }
145-
146-
return;
147142
}

src/path_find/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::f32::MAX;
2-
31
use pathfinding::prelude::{absdiff, astar, dijkstra_all, dijkstra_partial};
42
use pyo3::prelude::*;
53

@@ -911,8 +909,8 @@ impl PathFind {
911909
if distance_from_target > distance {
912910
continue;
913911
}
914-
915-
let distance_from_start= octile_distance_f32(corrected_start, destination.0);
912+
913+
let distance_from_start = octile_distance_f32(corrected_start, destination.0);
916914
// Use magic distance constant here to not move without reason.
917915
// Let's take the distance into account so that same influence value is better when it's closer.
918916
let distance_value = distance_from_start;
@@ -924,7 +922,7 @@ impl PathFind {
924922
}
925923
}
926924

927-
return best_target;
925+
best_target
928926
}
929927

930928
pub fn invert_djiktra(&self, start: (f32, f32), distance: f32) -> Vec<((usize, usize), f32)> {
@@ -946,7 +944,7 @@ impl PathFind {
946944
destination_collection.push(((x, y), d));
947945
}
948946

949-
return destination_collection;
947+
destination_collection
950948
}
951949

952950
pub fn djiktra(&self, start: (f32, f32), distance: f32) -> Vec<((usize, usize), f32)> {
@@ -968,6 +966,6 @@ impl PathFind {
968966
destination_collection.push(((x, y), d));
969967
}
970968

971-
return destination_collection;
969+
destination_collection
972970
}
973971
}

0 commit comments

Comments
 (0)