use super::Transform;
#[repr(u8)]
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum Rotation {
None = 0,
Quarter = 1,
Half = 2,
ThreeQuarters = 3,
}
#[repr(u8)]
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum Axis3D {
X = 0,
Y = 1,
Z = 2,
}
pub struct Rotate2(pub Rotation);
pub struct Rotate3 {
pub rotation: Rotation,
pub axis: Axis3D,
pub left_handed: bool,
}
impl Transform<2> for Rotate2 {
fn apply(&self, index: &mut [isize; 2]) {
let [x, y] = *index;
match self.0 {
Rotation::Half => {
index[0] = -x;
index[1] = -y;
}
Rotation::Quarter => {
index[0] = -y;
index[1] = x;
}
Rotation::ThreeQuarters => {
index[0] = y;
index[1] = -x;
}
_ => {
}
}
}
}
impl Transform<3> for Rotate3 {
fn apply(&self, index: &mut [isize; 3]) {
let [x, y, z] = *index;
match (self.axis, self.rotation, self.left_handed) {
(Axis3D::X, Rotation::Half, _) => {
index[1] = -y;
index[2] = -z;
}
(Axis3D::Y, Rotation::Half, _) => {
index[0] = -x;
index[2] = -z;
}
(Axis3D::Z, Rotation::Half, _) => {
index[0] = -x;
index[1] = -y;
}
(Axis3D::X, Rotation::Quarter, false) | (Axis3D::X, Rotation::ThreeQuarters, true) => {
index[1] = -z;
index[2] = y;
}
(Axis3D::X, Rotation::Quarter, true) | (Axis3D::X, Rotation::ThreeQuarters, false) => {
index[1] = z;
index[2] = -y;
}
(Axis3D::Y, Rotation::Quarter, false) | (Axis3D::Y, Rotation::ThreeQuarters, true) => {
index[0] = z;
index[2] = -x;
}
(Axis3D::Y, Rotation::Quarter, true) | (Axis3D::Y, Rotation::ThreeQuarters, false) => {
index[0] = -z;
index[2] = x;
}
(Axis3D::Z, Rotation::Quarter, false) | (Axis3D::Z, Rotation::ThreeQuarters, true) => {
index[0] = -y;
index[1] = x;
}
(Axis3D::Z, Rotation::Quarter, true) | (Axis3D::Z, Rotation::ThreeQuarters, false) => {
index[0] = y;
index[1] = -x;
}
_ => {
}
}
}
}