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: GridVectorFirst column
y: GridVectorSecond column
z: GridVectorThird column
w: GridVectorFourth column (translation)
Implementations§
Source§impl GridMatrix
impl GridMatrix
Sourcepub 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
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.
Sourcepub fn from_translation(offset: impl Into<GridVector>) -> Self
pub fn from_translation(offset: impl Into<GridVector>) -> Self
Construct a translation matrix.
Sourcepub fn from_scale(scale: GridCoordinate) -> Self
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!
Sourcepub fn from_origin(
origin: impl Into<GridPoint>,
x: Face7,
y: Face7,
z: Face7,
) -> Self
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),
);Sourcepub fn to_free(self) -> Transform3D<FreeCoordinate, Cube, Cube>
pub fn to_free(self) -> Transform3D<FreeCoordinate, Cube, Cube>
Convert this integer-valued matrix to an equivalent float-valued matrix.
Sourcepub fn transform_cube(&self, cube: Cube) -> Cube
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));Sourcepub fn decompose(self) -> Option<Gridgid>
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),
}),
);Sourcepub fn transform_vector(&self, vec: GridVector) -> GridVector
pub fn transform_vector(&self, vec: GridVector) -> GridVector
Transform (rotate and scale) the given vector. The translation part of this matrix is ignored.
Sourcepub fn transform_point(&self, point: GridPoint) -> GridPoint
pub fn transform_point(&self, point: GridPoint) -> GridPoint
Transform the given point by this matrix.
Sourcepub fn concat(&self, other: &Self) -> Self
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))),
);Sourcepub fn inverse_transform(&self) -> Option<Self>
pub fn inverse_transform(&self) -> Option<Self>
Invert this matrix. Returns None if it is not invertible.
Trait Implementations§
Source§impl Clone for GridMatrix
impl Clone for GridMatrix
Source§fn clone(&self) -> GridMatrix
fn clone(&self) -> GridMatrix
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for GridMatrix
Source§impl Debug for GridMatrix
impl Debug for GridMatrix
impl Eq for GridMatrix
Source§impl From<Gridgid> for GridMatrix
impl From<Gridgid> for GridMatrix
Source§impl Hash for GridMatrix
impl Hash for GridMatrix
Source§impl Mul for GridMatrix
impl Mul for GridMatrix
Source§impl One for GridMatrix
impl One for GridMatrix
Source§impl PartialEq for GridMatrix
impl PartialEq for GridMatrix
Source§fn eq(&self, other: &GridMatrix) -> bool
fn eq(&self, other: &GridMatrix) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for GridMatrix
Auto Trait Implementations§
impl Freeze for GridMatrix
impl RefUnwindSafe for GridMatrix
impl Send for GridMatrix
impl Sync for GridMatrix
impl Unpin for GridMatrix
impl UnsafeUnpin for GridMatrix
impl UnwindSafe for GridMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.