[Optimization] Improve readability (#345)
This commit is contained in:
parent
5a96eea6ba
commit
e99c5eaa24
|
@ -334,14 +334,9 @@ impl ConwayGrid {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn grid_idx<I: std::convert::TryInto<usize>>(&self, x: I, y: I) -> Option<usize> {
|
fn grid_idx<I: std::convert::TryInto<usize>>(&self, x: I, y: I) -> Option<usize> {
|
||||||
if let (Ok(x), Ok(y)) = (x.try_into(), y.try_into()) {
|
match (x.try_into(), y.try_into()) {
|
||||||
if x < self.width && y < self.height {
|
(Ok(x), Ok(y)) if x < self.width && y < self.height => Some(x + y * self.width),
|
||||||
Some(x + y * self.width)
|
_ => None,
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue