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