diff --git a/mino/src/piece.rs b/mino/src/piece.rs index c3d756c..c8c2507 100644 --- a/mino/src/piece.rs +++ b/mino/src/piece.rs @@ -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 { impl<'c, S: Shape<'c>> Piece { /// 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;