Skip to main content

GridMatrix

Struct GridMatrix 

Source
pub struct GridMatrix {
    pub x: GridVector,
    pub y: GridVector,
    pub z: GridVector,
    pub w: GridVector,
}
Expand description

A 4×3 affine transformation matrix in GridCoordinates.

Fields§

§x: GridVector

First column

§y: GridVector

Second column

§z: GridVector

Third column

§w: GridVector

Fourth column (translation)

Implementations§

Source§

impl GridMatrix

Source

pub const ZERO: Self

The zero matrix, which transforms all points to zero.

Source

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

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<GridVector>) -> Self

Construct a translation matrix.

Source

pub fn from_scale(scale: GridCoordinate) -> Self

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<GridPoint>, x: Face7, y: Face7, z: Face7, ) -> Self

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

pub fn transform_vector(&self, vec: GridVector) -> GridVector

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

Source

pub fn transform_point(&self, point: GridPoint) -> GridPoint

Transform the given point by this matrix.

Source

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

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

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

Trait Implementations§

Source§

impl Clone for GridMatrix

Source§

fn clone(&self) -> GridMatrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for GridMatrix

Source§

impl Debug for GridMatrix

Source§

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

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

impl Eq for GridMatrix

Source§

impl From<Gridgid> for GridMatrix

Source§

fn from(value: Gridgid) -> Self

Converts to this type from the input type.
Source§

impl Hash for GridMatrix

Source§

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

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

Source§

type Output = GridMatrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl One for GridMatrix

Source§

fn one() -> Self

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 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: 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<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<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> 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.