From 096189373c54936d19fc4938ad286665c7344642 Mon Sep 17 00:00:00 2001 From: tali Date: Wed, 14 Dec 2022 15:03:21 -0500 Subject: [PATCH] impl From<(x,y,r)> for Loc --- mino/src/piece.rs | 13 ++++++++++--- mino/src/srs.rs | 27 ++++----------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/mino/src/piece.rs b/mino/src/piece.rs index d6d892a..5cd6dc7 100644 --- a/mino/src/piece.rs +++ b/mino/src/piece.rs @@ -15,13 +15,20 @@ pub struct Loc { pub r: Rot, } -impl From<(i16, i16)> for Loc { - fn from((x, y): (i16, i16)) -> Self { - let r = Rot::default(); +impl From<(i16, i16, Rot)> for Loc { + #[inline] + fn from((x, y, r): (i16, i16, Rot)) -> Self { 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 /// are 4 total orientations to represent each 90 degree turn possible. #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Default)] diff --git a/mino/src/srs.rs b/mino/src/srs.rs index b9cb228..79296b9 100644 --- a/mino/src/srs.rs +++ b/mino/src/srs.rs @@ -61,14 +61,7 @@ mod test { fn test_spawn() { use Shape::*; for s in [L, O, J, I, S, T, Z] { - assert_eq!( - Piece::spawn(s).loc, - Loc { - x: 4, - y: 19, - r: Rot::N - } - ); + assert_eq!(Piece::spawn(s).loc, (4, 19, Rot::N).into()); } } @@ -129,11 +122,7 @@ mod test { use input::Spin::*; let mut piece = Piece { shape: Shape::O, - loc: Loc { - x: 6, - y: 6, - r: Rot::N, - }, + loc: (6, 6, Rot::N).into(), }; assert_eq!(input::rotate(&mut piece, Mat::EMPTY, Cw), Some(0)); assert_eq!(piece.loc.x, 6); @@ -160,11 +149,7 @@ mod test { }; let mut piece = Piece { shape: Shape::T, - loc: Loc { - x: 5, - y: 3, - r: Rot::N, - }, + loc: (5, 3, Rot::N).into(), }; assert_eq!(input::rotate(&mut piece, SETUP, input::Spin::Ccw), Some(4)); assert_eq!(piece.loc.x, 6); @@ -182,11 +167,7 @@ mod test { }; let mut piece = Piece { shape: Shape::Z, - loc: Loc { - x: 5, - y: 3, - r: Rot::N, - }, + loc: (5, 3, Rot::N).into(), }; assert_eq!(input::rotate(&mut piece, SETUP, input::Spin::Cw), Some(3)); assert_eq!(piece.loc.x, 5);