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
impl GridMatrix
sourcepub const ZERO: GridMatrix = _
pub const ZERO: GridMatrix = _
The zero matrix, which transforms all points to zero.
sourcepub 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
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.
sourcepub fn from_translation(offset: impl Into<Vector3D<i32, Cube>>) -> GridMatrix
pub fn from_translation(offset: impl Into<Vector3D<i32, Cube>>) -> GridMatrix
Construct a translation matrix.
sourcepub fn from_scale(scale: i32) -> GridMatrix
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!
sourcepub fn from_origin(
origin: impl Into<Point3D<i32, Cube>>,
x: Face7,
y: Face7,
z: Face7,
) -> GridMatrix
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),
);sourcepub fn to_free(self) -> Transform3D<f64, Cube, Cube>
pub fn to_free(self) -> Transform3D<f64, 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),
}),
);source§impl GridMatrix
impl GridMatrix
TODO(euclid migration): this used to be a cgmath::Transform impl; clean up
sourcepub fn transform_vector(&self, vec: Vector3D<i32, Cube>) -> Vector3D<i32, Cube>
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.
sourcepub fn transform_point(&self, point: Point3D<i32, Cube>) -> Point3D<i32, Cube>
pub fn transform_point(&self, point: Point3D<i32, Cube>) -> Point3D<i32, Cube>
Transform the given point by this matrix.
sourcepub fn concat(&self, other: &GridMatrix) -> GridMatrix
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))),
);sourcepub fn inverse_transform(&self) -> Option<GridMatrix>
pub fn inverse_transform(&self) -> Option<GridMatrix>
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 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for GridMatrix
impl Debug for GridMatrix
source§impl From<Gridgid> for GridMatrix
impl From<Gridgid> for GridMatrix
source§fn from(value: Gridgid) -> GridMatrix
fn from(value: Gridgid) -> GridMatrix
source§impl Hash for GridMatrix
impl Hash for GridMatrix
source§impl Mul for GridMatrix
impl Mul for GridMatrix
§type Output = GridMatrix
type Output = GridMatrix
* operator.source§fn mul(self, rhs: GridMatrix) -> <GridMatrix as Mul>::Output
fn mul(self, rhs: GridMatrix) -> <GridMatrix as Mul>::Output
* operation. Read moresource§impl One for GridMatrix
impl One for GridMatrix
source§fn one() -> GridMatrix
fn one() -> 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 Copy for GridMatrix
impl Eq for GridMatrix
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 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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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