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.
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),
}),
);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
Source§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
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: 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.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