Struct all_is_cubes::math::GridMatrix

source ·
pub struct GridMatrix {
    pub x: Vector3D<i32, Cube>,
    pub y: Vector3D<i32, Cube>,
    pub z: Vector3D<i32, Cube>,
    pub w: Vector3D<i32, Cube>,
}
Expand description

A 4×3 affine transformation matrix in GridCoordinates.

TODO: The operators implemented for this are very incomplete.

TODO(euclid migration): Can we dispose of this type now?

Fields§

§x: Vector3D<i32, Cube>

First column

§y: Vector3D<i32, Cube>

Second column

§z: Vector3D<i32, Cube>

Third column

§w: Vector3D<i32, Cube>

Fourth column (translation)

Implementations§

source§

impl GridMatrix

source

pub const ZERO: GridMatrix = _

The zero matrix, which transforms all points to zero.

source

pub const fn new( x0: i32, x1: i32, x2: i32, y0: i32, y1: i32, y2: i32, z0: i32, z1: i32, z2: i32, w0: i32, w1: i32, w2: i32, ) -> GridMatrix

Note: This takes the elements in a column-major ordering, so the argument order is transposed relative to a conventional textual display of a matrix.

source

pub fn from_translation(offset: impl Into<Vector3D<i32, Cube>>) -> GridMatrix

Construct a translation matrix.

source

pub fn from_scale(scale: i32) -> GridMatrix

Construct a uniform scaling matrix.

Note that since this is an integer matrix, there is no possibility of scaling less than 1 other than 0!

source

pub fn from_origin( origin: impl Into<Point3D<i32, Cube>>, x: Face7, y: Face7, z: Face7, ) -> GridMatrix

Construct a transformation to a translated and rotated coordinate system from an origin in the target coordinate system and basis vectors expressed as Face7s.

Skews or scaling cannot be performed using this constructor.

use all_is_cubes::math::{Face7::*, GridMatrix, GridPoint};

let transform = GridMatrix::from_origin([10, 10, 10], PX, PZ, NY);
assert_eq!(
    transform.transform_point(GridPoint::new(1, 2, 3)),
    GridPoint::new(11, 7, 12),
);
source

pub fn to_free(self) -> Transform3D<f64, Cube, Cube>

Convert this integer-valued matrix to an equivalent float-valued matrix.

source

pub fn transform_cube(&self, cube: Cube) -> Cube

Equivalent to temporarily applying an offset of [0.5, 0.5, 0.5] while transforming cube as per GridMatrix::transform_point, despite the fact that integer arithmetic is being used.

This operation thus transforms the standard positive-octant unit cube identified by its most negative corner the same way as the GridAab::single_cube containing that cube.

use all_is_cubes::math::{Cube, Face7::*, GridMatrix, GridPoint};

// Translation without rotation has the usual definition.
let matrix = GridMatrix::from_translation([10, 0, 0]);
assert_eq!(matrix.transform_cube(Cube::new(1, 1, 1)), Cube::new(11, 1, 1));

// With a rotation or reflection, the results are different.
// TODO: Come up with a better example and explanation.
let reflected = GridMatrix::from_origin([10, 0, 0], NX, PY, PZ);
assert_eq!(reflected.transform_point(GridPoint::new(1, 5, 5)), GridPoint::new(9, 5, 5));
assert_eq!(reflected.transform_cube(Cube::new(1, 5, 5)), Cube::new(8, 5, 5));
source

pub fn decompose(self) -> Option<Gridgid>

Decomposes a matrix into its rotation and translation components, stored in a Gridgid. Returns None if the matrix has any scaling or skew.

use all_is_cubes::math::{Face6::*, Gridgid, GridMatrix, GridRotation, GridVector};

assert_eq!(
    GridMatrix::new(
        0, -1,  0,
        1,  0,  0,
        0,  0,  1,
        7,  3, -8,
    ).decompose(),
    Some(Gridgid {
        rotation: GridRotation::from_basis([NY, PX, PZ]),
        translation: GridVector::new(7, 3, -8),
    }),
);
source§

impl GridMatrix

TODO(euclid migration): this used to be a cgmath::Transform impl; clean up

source

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

Transform (rotate and scale) the given vector. The translation part of this matrix is ignored.

source

pub fn transform_point(&self, point: Point3D<i32, Cube>) -> Point3D<i32, Cube>

Transform the given point by this matrix.

source

pub fn concat(&self, other: &GridMatrix) -> GridMatrix

use all_is_cubes::math::{GridMatrix, GridPoint};

let transform_1 = GridMatrix::new(
    0, -1, 0,
    1, 0, 0,
    0, 0, 1,
    0, 0, 0,
);
let transform_2 = GridMatrix::from_translation([10, 20, 30]);

// Demonstrate the directionality of concatenation.
assert_eq!(
    transform_1.concat(&transform_2).transform_point(GridPoint::new(0, 3, 0)),
    transform_1.transform_point(transform_2.transform_point(GridPoint::new(0, 3, 0))),
);
source

pub fn inverse_transform(&self) -> Option<GridMatrix>

Invert this matrix. Returns None if it is not invertible.

Trait Implementations§

source§

impl Clone for GridMatrix

source§

fn clone(&self) -> GridMatrix

Returns a copy 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 GridMatrix

source§

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

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

impl From<Gridgid> for GridMatrix

source§

fn from(value: Gridgid) -> GridMatrix

Converts to this type from the input type.
source§

impl Hash for GridMatrix

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 GridMatrix

§

type Output = GridMatrix

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl One for GridMatrix

source§

fn one() -> GridMatrix

Returns the multiplicative identity element of Self, 1. Read more
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 GridMatrix

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for GridMatrix

source§

impl Eq for GridMatrix

source§

impl StructuralPartialEq for GridMatrix

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: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

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

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, 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> Is for T
where T: ?Sized,

§

type EqTo = T

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,

§

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>,

§

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>,

§

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.