Make Cells::translate a pure function
This commit is contained in:
parent
1075546dd8
commit
eebbde71b9
|
@ -124,9 +124,11 @@ impl<'c> Cells<'c> {
|
|||
|
||||
/// Translates the cells by the given amount in both directions.
|
||||
#[inline]
|
||||
pub fn translate(&mut self, dx: i16, dy: i16) {
|
||||
self.x = self.x.checked_add(dx).expect("overflow/underflow");
|
||||
self.y = self.y.checked_add(dy).expect("overflow/underflow");
|
||||
pub fn translate(&self, dx: i16, dy: i16) -> Self {
|
||||
let mut copy = *self;
|
||||
copy.x = self.x.checked_add(dx).expect("overflow/underflow");
|
||||
copy.y = self.y.checked_add(dy).expect("overflow/underflow");
|
||||
copy
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -157,14 +159,14 @@ pub struct Piece<S> {
|
|||
impl<'c, S: Shape<'c>> Piece<S> {
|
||||
/// Returns the cells occupied by this piece.
|
||||
pub fn cells(&self) -> Cells<'c> {
|
||||
let mut cells = self.shape.cells(self.loc.r);
|
||||
cells.translate(self.loc.x, self.loc.y);
|
||||
cells
|
||||
self.shape
|
||||
.cells(self.loc.r)
|
||||
.translate(self.loc.x, self.loc.y)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
pub mod test {
|
||||
use super::*;
|
||||
use crate::mat;
|
||||
|
||||
|
|
Loading…
Reference in New Issue