Returns an array of all locations within a certain radius squared of this location that are on the map. The locations are ordered first by the x-coordinate, then the y-coordinate. The radius squared is inclusive.
(&self, location: MapLocation,
radius_squared: u32)
| 527 | /// The locations are ordered first by the x-coordinate, then the |
| 528 | /// y-coordinate. The radius squared is inclusive. |
| 529 | pub fn all_locations_within(&self, location: MapLocation, |
| 530 | radius_squared: u32) -> Vec<MapLocation> { |
| 531 | let mut locations = vec![]; |
| 532 | let map = self.starting_map(location.planet); |
| 533 | |
| 534 | let radius = (radius_squared as f32).sqrt() as i32; |
| 535 | let min_x = cmp::max(location.x - radius, 0); |
| 536 | let max_x = cmp::min(location.x + radius, map.width as i32 - 1); |
| 537 | let min_y = cmp::max(location.y - radius, 0); |
| 538 | let max_y = cmp::min(location.y + radius, map.height as i32 - 1); |
| 539 | |
| 540 | for x in min_x..max_x + 1 { |
| 541 | for y in min_y..max_y + 1 { |
| 542 | let loc = MapLocation::new(location.planet, x, y); |
| 543 | if location.distance_squared_to(loc) <= radius_squared { |
| 544 | locations.push(loc); |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | locations |
| 550 | } |
| 551 | |
| 552 | /// * LocationOffMap - the location is off the map. |
| 553 | /// * LocationNotVisible - the location is outside the vision range. |