cleanup
This commit is contained in:
parent
366c78766d
commit
3506e0057f
1 changed files with 14 additions and 11 deletions
|
@ -47,10 +47,13 @@ impl Region {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tile_relative(&self, x: usize, y: usize, relx: isize, rely: isize) -> Option<&Tile> {
|
fn get_tile_rel(&self, x: usize, y: usize, relx: isize, rely: isize) -> &Tile {
|
||||||
|
let (Some(x), Some(y)) = (x.checked_add_signed(relx), y.checked_add_signed(rely))
|
||||||
|
else { return &Tile::EMPTY; };
|
||||||
self.tiles
|
self.tiles
|
||||||
.get(y.checked_add_signed(rely)?)
|
.get(y)
|
||||||
.and_then(|row| row.get(x.checked_add_signed(relx)?))
|
.and_then(|row| row.get(x))
|
||||||
|
.unwrap_or(&Tile::EMPTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn step(&mut self) {
|
pub fn step(&mut self) {
|
||||||
|
@ -59,14 +62,14 @@ impl Region {
|
||||||
for y in 0..self.height() {
|
for y in 0..self.height() {
|
||||||
let mut row = Vec::with_capacity(self.width());
|
let mut row = Vec::with_capacity(self.width());
|
||||||
for x in 0..self.width() {
|
for x in 0..self.width() {
|
||||||
let n = self.get_tile_relative(x, y, 0, -1).unwrap_or(&Tile::EMPTY);
|
let n = self.get_tile_rel(x, y, 0, -1);
|
||||||
let s = self.get_tile_relative(x, y, 0, 1).unwrap_or(&Tile::EMPTY);
|
let s = self.get_tile_rel(x, y, 0, 1);
|
||||||
let e = self.get_tile_relative(x, y, 1, 0).unwrap_or(&Tile::EMPTY);
|
let e = self.get_tile_rel(x, y, 1, 0);
|
||||||
let w = self.get_tile_relative(x, y, -1, 0).unwrap_or(&Tile::EMPTY);
|
let w = self.get_tile_rel(x, y, -1, 0);
|
||||||
let ne = self.get_tile_relative(x, y, 1, -1).unwrap_or(&Tile::EMPTY);
|
let ne = self.get_tile_rel(x, y, 1, -1);
|
||||||
let nw = self.get_tile_relative(x, y, -1, -1).unwrap_or(&Tile::EMPTY);
|
let nw = self.get_tile_rel(x, y, -1, -1);
|
||||||
let se = self.get_tile_relative(x, y, 1, 1).unwrap_or(&Tile::EMPTY);
|
let se = self.get_tile_rel(x, y, 1, 1);
|
||||||
let sw = self.get_tile_relative(x, y, -1, 1).unwrap_or(&Tile::EMPTY);
|
let sw = self.get_tile_rel(x, y, -1, 1);
|
||||||
|
|
||||||
let edge = Edges::new(n, s, e, w, ne, nw, se, sw);
|
let edge = Edges::new(n, s, e, w, ne, nw, se, sw);
|
||||||
row.push(edge);
|
row.push(edge);
|
||||||
|
|
Loading…
Reference in a new issue