GridRotation

Enum GridRotation 

Source
#[repr(u8)]
pub enum GridRotation {
Show 48 variants RXYZ = 0, RXYz = 1, RXyZ = 2, RXyz = 3, RxYZ = 4, RxYz = 5, RxyZ = 6, Rxyz = 7, RXZY = 8, RXZy = 9, RXzY = 10, RXzy = 11, RxZY = 12, RxZy = 13, RxzY = 14, Rxzy = 15, RYXZ = 16, RYXz = 17, RYxZ = 18, RYxz = 19, RyXZ = 20, RyXz = 21, RyxZ = 22, Ryxz = 23, RYZX = 24, RYZx = 25, RYzX = 26, RYzx = 27, RyZX = 28, RyZx = 29, RyzX = 30, Ryzx = 31, RZXY = 32, RZXy = 33, RZxY = 34, RZxy = 35, RzXY = 36, RzXy = 37, RzxY = 38, Rzxy = 39, RZYX = 40, RZYx = 41, RZyX = 42, RZyx = 43, RzYX = 44, RzYx = 45, RzyX = 46, Rzyx = 47,
}
Expand description

Represents a discrete (grid-aligned) rotation, or exchange of axes.

Compared to a GridMatrix, this cannot specify scale, translation, or skew; it is used for identifying the rotations of blocks.

Each of the variant names specifies the three unit vectors which (x, y, z), respectively, should be multiplied by to perform the rotation. Lowercase refers to a negated unit vector.

See also:

§Serialization stability warning

This type implements serde::Serialize and serde::Deserialize, but serialization support is still experimental (as is the game data model in general). We do not guarantee that future versions of all-is-cubes will be able to deserialize data which is serialized by this version.

Additionally, the serialization schema is designed with serde_json in mind. It is not guaranteed that using a different data format crate, which may use a different subset of the information exposed via serde::Serialize, will produce stable results.

Variants§

§

RXYZ = 0

§

RXYz = 1

§

RXyZ = 2

§

RXyz = 3

§

RxYZ = 4

§

RxYz = 5

§

RxyZ = 6

§

Rxyz = 7

§

RXZY = 8

§

RXZy = 9

§

RXzY = 10

§

RXzy = 11

§

RxZY = 12

§

RxZy = 13

§

RxzY = 14

§

Rxzy = 15

§

RYXZ = 16

§

RYXz = 17

§

RYxZ = 18

§

RYxz = 19

§

RyXZ = 20

§

RyXz = 21

§

RyxZ = 22

§

Ryxz = 23

§

RYZX = 24

§

RYZx = 25

§

RYzX = 26

§

RYzx = 27

§

RyZX = 28

§

RyZx = 29

§

RyzX = 30

§

Ryzx = 31

§

RZXY = 32

§

RZXy = 33

§

RZxY = 34

§

RZxy = 35

§

RzXY = 36

§

RzXy = 37

§

RzxY = 38

§

Rzxy = 39

§

RZYX = 40

§

RZYx = 41

§

RZyX = 42

§

RZyx = 43

§

RzYX = 44

§

RzYx = 45

§

RzyX = 46

§

Rzyx = 47

Implementations§

Source§

impl GridRotation

Source

pub const ALL: [GridRotation; 48]

All 48 possible rotations.

Warning: TODO: The ordering of these rotations is not yet stable. The current ordering is based on the six axis permutations followed by rotations.

Source

pub const ALL_BUT_REFLECTIONS: [GridRotation; 24]

All possible rotations that are not reflections.

Warning: TODO: The ordering of these rotations is not yet stable.

Source

pub const IDENTITY: GridRotation = Self::RXYZ

The identity rotation, also known as RXYZ.

Source

pub fn from_basis(basis: impl Into<[Face6; 3]>) -> GridRotation

Constructs a rotation from a basis: that is, the returned rotation will rotate PX into basis[0], PY into basis[1], and PZ into basis[2].

Panics if the three provided axes are not mutually perpendicular.

Source

pub fn from_to( source: Face6, destination: Face6, up: Face6, ) -> Option<GridRotation>

Find the rotation (without reflection) which rotates source to destination. and leaves up unaffected. (This might also be considered a “look at” operation).

If it is not possible to leave up unaffected, returns None. (Trying two perpendicular up directions will always succeed.)

Source

pub const fn to_positive_octant_transform(self, size: i32) -> Gridgid

Expresses this rotation as a Gridgid transform which rotates “in place” the points within the volume defined by coordinates in the range [0, size].

That is, a [GridAab] of that volume will be unchanged by rotation:

use all_is_cubes::block::Resolution;
use all_is_cubes::math::{Face6, GridAab, GridRotation};

let b = GridAab::for_block(Resolution::R8);
let rotation = Face6::PY.clockwise().to_positive_octant_transform(8);
assert_eq!(b.transform(rotation), Some(b));

Such matrices are suitable for rotating the voxels of a block, provided that the voxel coordinates are then transformed with GridMatrix::transform_cube, not GridMatrix::transform_point (due to the lower-corner format of cube coordinates).


let rotation = Face6::PY.clockwise().to_positive_octant_transform(4);
assert_eq!(rotation.transform_cube(Cube::new(0, 0, 0)), Cube::new(3, 0, 0));
assert_eq!(rotation.transform_cube(Cube::new(3, 0, 0)), Cube::new(3, 0, 3));
assert_eq!(rotation.transform_cube(Cube::new(3, 0, 3)), Cube::new(0, 0, 3));
assert_eq!(rotation.transform_cube(Cube::new(0, 0, 3)), Cube::new(0, 0, 0));
Source

pub fn to_rotation_matrix(self) -> GridMatrix

Expresses this rotation as a matrix without any translation.

Source

pub fn transform(self, face: Face6) -> Face6

Rotate the face by this rotation.

Source

pub fn transform_vector( self, vector: Vector3D<i32, Cube>, ) -> Vector3D<i32, Cube>

Rotate the vector by this rotation.

May panic or wrap if vector has any components equal to GridCoordinate::MIN.

Source

pub fn checked_transform_vector( self, vector: Vector3D<i32, Cube>, ) -> Option<Vector3D<i32, Cube>>

Rotate the vector by this rotation.

Returns None if vector has any components equal to GridCoordinate::MIN, which would overflow.

Source

pub fn transform_size(self, size: Size3D<u32, Cube>) -> Size3D<u32, Cube>

Rotate the size value by this rotation.

This is similar to GridRotation::transform_vector() except that the components are only swapped, not negated, and there is no possibility of numeric overflow.

Source

pub const fn is_reflection(self) -> bool

Returns whether this is a reflection.

use all_is_cubes::math::{GridRotation, Face6::*};

assert!(!GridRotation::IDENTITY.is_reflection());
assert!(!GridRotation::from_basis([PX, PZ, NY]).is_reflection());
assert!(GridRotation::from_basis([PX, PZ, PY]).is_reflection());
Source

pub const fn inverse(self) -> GridRotation

Returns the inverse of this rotation; the one which undoes this.

use all_is_cubes::math::GridRotation;

for &rotation in &GridRotation::ALL {
    assert_eq!(rotation * rotation.inverse(), GridRotation::IDENTITY);
}
Source

pub fn iterate(self) -> impl Iterator<Item = GridRotation>

Generates the sequence of rotations that may be obtained by concatenating/multiplying this rotation with itself repeatedly.

The first element of the iterator will always be the identity, i.e. this rotation applied zero times. The iterator ends when the sequence would repeat itself, i.e. just before it would produce the identity again.

§Example results of iteration
use all_is_cubes::math::{Face6::*, GridRotation};

// The identity rotation remains itself when iterated.
assert_eq!(
    GridRotation::IDENTITY.iterate().collect::<Vec<_>>(),
    vec![GridRotation::IDENTITY],
);

// Any reflection or 180° rotation will produce itself and the identity.
let x_reflection = GridRotation::from_basis([NX, PY, PZ]);
assert_eq!(
    x_reflection.iterate().collect::<Vec<_>>(),
    vec![GridRotation::IDENTITY, x_reflection],
);

// Any 90° rotation produces four distinct rotations.
assert_eq!(
    PY.clockwise().iterate().collect::<Vec<_>>(),
    vec![
        GridRotation::IDENTITY,
        PY.clockwise(),
        PY.r180(),
        PY.counterclockwise(),
   ],
);

Trait Implementations§

Source§

impl<'arbitrary> Arbitrary<'arbitrary> for GridRotation

Source§

fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<GridRotation, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest( u: Unstructured<'arbitrary>, ) -> Result<GridRotation, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Clone for GridRotation

Source§

fn clone(&self) -> GridRotation

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GridRotation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for GridRotation

Source§

fn default() -> GridRotation

Returns the identity (no rotation).

Source§

impl<'de> Deserialize<'de> for GridRotation

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<GridRotation, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<GridRotation> for Gridgid

Source§

fn from(value: GridRotation) -> Gridgid

Converts to this type from the input type.
Source§

impl Hash for GridRotation

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for GridRotation

Source§

fn mul(self, rhs: GridRotation) -> <GridRotation as Mul>::Output

Multiplication is concatenation: self * rhs is equivalent to applying rhs and then applying self.

use all_is_cubes::math::{Face6, Face6::*, GridRotation, GridPoint};

let transform_1 = GridRotation::from_basis([NY, PX, PZ]);
let transform_2 = GridRotation::from_basis([PY, PZ, PX]);

// Demonstrate the directionality of concatenation.
for face in Face6::ALL {
    assert_eq!(
        (transform_1 * transform_2).transform(face),
        transform_1.transform(transform_2.transform(face)),
    );
}
Source§

type Output = GridRotation

The resulting type after applying the * operator.
Source§

impl One for GridRotation

Source§

fn one() -> GridRotation

Returns the identity (no rotation).

Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl PartialEq for GridRotation

Source§

fn eq(&self, other: &GridRotation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for GridRotation

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for GridRotation

Source§

impl Eq for GridRotation

Source§

impl StructuralPartialEq for GridRotation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn as_dyn_eq(&self) -> &(dyn DynEq + 'static)

Casts the type to dyn Any.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> One for T
where T: One,

Source§

fn one() -> T

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,