impl From<(x,y,r)> for Loc
This commit is contained in:
parent
b3d9e3c476
commit
096189373c
|
@ -15,13 +15,20 @@ pub struct Loc {
|
||||||
pub r: Rot,
|
pub r: Rot,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(i16, i16)> for Loc {
|
impl From<(i16, i16, Rot)> for Loc {
|
||||||
fn from((x, y): (i16, i16)) -> Self {
|
#[inline]
|
||||||
let r = Rot::default();
|
fn from((x, y, r): (i16, i16, Rot)) -> Self {
|
||||||
Loc { x, y, r }
|
Loc { x, y, r }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<(i16, i16)> for Loc {
|
||||||
|
#[inline]
|
||||||
|
fn from((x, y): (i16, i16)) -> Self {
|
||||||
|
(x, y, Rot::default()).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a rotation state for a piece. The initial state is "north" (`N`), and there
|
/// Represents a rotation state for a piece. The initial state is "north" (`N`), and there
|
||||||
/// are 4 total orientations to represent each 90 degree turn possible.
|
/// are 4 total orientations to represent each 90 degree turn possible.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Default)]
|
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Default)]
|
||||||
|
|
|
@ -61,14 +61,7 @@ mod test {
|
||||||
fn test_spawn() {
|
fn test_spawn() {
|
||||||
use Shape::*;
|
use Shape::*;
|
||||||
for s in [L, O, J, I, S, T, Z] {
|
for s in [L, O, J, I, S, T, Z] {
|
||||||
assert_eq!(
|
assert_eq!(Piece::spawn(s).loc, (4, 19, Rot::N).into());
|
||||||
Piece::spawn(s).loc,
|
|
||||||
Loc {
|
|
||||||
x: 4,
|
|
||||||
y: 19,
|
|
||||||
r: Rot::N
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,11 +122,7 @@ mod test {
|
||||||
use input::Spin::*;
|
use input::Spin::*;
|
||||||
let mut piece = Piece {
|
let mut piece = Piece {
|
||||||
shape: Shape::O,
|
shape: Shape::O,
|
||||||
loc: Loc {
|
loc: (6, 6, Rot::N).into(),
|
||||||
x: 6,
|
|
||||||
y: 6,
|
|
||||||
r: Rot::N,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
assert_eq!(input::rotate(&mut piece, Mat::EMPTY, Cw), Some(0));
|
assert_eq!(input::rotate(&mut piece, Mat::EMPTY, Cw), Some(0));
|
||||||
assert_eq!(piece.loc.x, 6);
|
assert_eq!(piece.loc.x, 6);
|
||||||
|
@ -160,11 +149,7 @@ mod test {
|
||||||
};
|
};
|
||||||
let mut piece = Piece {
|
let mut piece = Piece {
|
||||||
shape: Shape::T,
|
shape: Shape::T,
|
||||||
loc: Loc {
|
loc: (5, 3, Rot::N).into(),
|
||||||
x: 5,
|
|
||||||
y: 3,
|
|
||||||
r: Rot::N,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
assert_eq!(input::rotate(&mut piece, SETUP, input::Spin::Ccw), Some(4));
|
assert_eq!(input::rotate(&mut piece, SETUP, input::Spin::Ccw), Some(4));
|
||||||
assert_eq!(piece.loc.x, 6);
|
assert_eq!(piece.loc.x, 6);
|
||||||
|
@ -182,11 +167,7 @@ mod test {
|
||||||
};
|
};
|
||||||
let mut piece = Piece {
|
let mut piece = Piece {
|
||||||
shape: Shape::Z,
|
shape: Shape::Z,
|
||||||
loc: Loc {
|
loc: (5, 3, Rot::N).into(),
|
||||||
x: 5,
|
|
||||||
y: 3,
|
|
||||||
r: Rot::N,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
assert_eq!(input::rotate(&mut piece, SETUP, input::Spin::Cw), Some(3));
|
assert_eq!(input::rotate(&mut piece, SETUP, input::Spin::Cw), Some(3));
|
||||||
assert_eq!(piece.loc.x, 5);
|
assert_eq!(piece.loc.x, 5);
|
||||||
|
|
Loading…
Reference in New Issue