pub struct Affine<const N: usize, T, A: Alignment>(/* private fields */)
where
Length<N>: SupportedLength,
T: Scalar;Expand description
An affine transform, which can represent translation, rotation, scaling and shear.
Affine is the generic form of:
Affine is generic over:
§Guarantees
Affine<N, T, A> represents Matrix<N, T, A> followed by Vector<N, T, A>
followed by optional padding due to alignment.
Padding bytes are initialized and accept any bit-pattern. It is sound to
store any bit-pattern in padding, and it is unsound to assume that
padding contains valid values of T unless T accepts all bit-patterns.
-
Affine<N, T, Unaligned>: has no padding, has no additional alignment. -
Affine<2, T, Aligned>: may have one padding vector, may have additional alignment. -
Affine<3, T, Aligned>: may have four padding elements if bothMatrix<3, T, Aligned>andVector<3, T, Aligned>don’t have padding, may have additional alignment. -
Affine<4, T, Aligned>: has no padding, has the alignment ofMatrix<4, T, Aligned>.
Affines of scalar types with the same Scalar::Repr are guaranteed to
have compatible memory layouts, unless Repr = (). They are guaranteed to
have the same size and element positions, but their alignment may differ.
Types containing compatible Affine types are not guaranteed to have
the same memory layout. For example, even though Affine2<f32> and
Affine2<i32> have the same memory layout, Option<Affine2<f32>> and
Option<Affine2<i32>> may not.
Implementations§
Source§impl<const N: usize, T, A: Alignment> Affine<N, T, A>
impl<const N: usize, T, A: Alignment> Affine<N, T, A>
Sourcepub const fn from_mat(mat: Matrix<N, T, A>) -> Selfwhere
T: Zero,
pub const fn from_mat(mat: Matrix<N, T, A>) -> Selfwhere
T: Zero,
Creates an affine transform from a matrix, expressing scale, rotation and shear.
Sourcepub const fn from_translation(translation: Vector<N, T, A>) -> Self
pub const fn from_translation(translation: Vector<N, T, A>) -> Self
Creates an affine transform from a translation vector.
Sourcepub const fn from_mat_translation(
mat: Matrix<N, T, A>,
translation: Vector<N, T, A>,
) -> Self
pub const fn from_mat_translation( mat: Matrix<N, T, A>, translation: Vector<N, T, A>, ) -> Self
Creates an affine transform from a translation vector and a matrix, expressing scale, rotation and shear.
Sourcepub const fn to_alignment<A2: Alignment>(&self) -> Affine<N, T, A2>
pub const fn to_alignment<A2: Alignment>(&self) -> Affine<N, T, A2>
Converts the affine to the specified alignment.
See Alignment for more information.
Source§impl<T, A: Alignment> Affine<2, T, A>where
T: Scalar,
impl<T, A: Alignment> Affine<2, T, A>where
T: Scalar,
Sourcepub const fn from_cols(
x_axis: Vector<2, T, A>,
y_axis: Vector<2, T, A>,
z_axis: Vector<2, T, A>,
) -> Self
pub const fn from_cols( x_axis: Vector<2, T, A>, y_axis: Vector<2, T, A>, z_axis: Vector<2, T, A>, ) -> Self
Creates a 2D affine transform from three column vectors.
Sourcepub const fn from_col_array(array: &[Vector<2, T, A>; 3]) -> Self
pub const fn from_col_array(array: &[Vector<2, T, A>; 3]) -> Self
Creates a 2D affine transform from three column vectors.
Sourcepub const fn to_col_array(&self) -> [Vector<2, T, A>; 3]
pub const fn to_col_array(&self) -> [Vector<2, T, A>; 3]
Converts the affine transform to three column vectors.
Sourcepub const fn as_col_array_ref(&self) -> &[Vector<2, T, A>; 3]
pub const fn as_col_array_ref(&self) -> &[Vector<2, T, A>; 3]
Returns a reference to the affine transform’s columns.
Sourcepub const fn as_col_array_mut(&mut self) -> &mut [Vector<2, T, A>; 3]
pub const fn as_col_array_mut(&mut self) -> &mut [Vector<2, T, A>; 3]
Returns a mutable reference to the affine transform’s columns.
Source§impl<T, A: Alignment> Affine<3, T, A>where
T: Scalar,
impl<T, A: Alignment> Affine<3, T, A>where
T: Scalar,
Sourcepub const fn from_cols(
x_axis: Vector<3, T, A>,
y_axis: Vector<3, T, A>,
z_axis: Vector<3, T, A>,
w_axis: Vector<3, T, A>,
) -> Self
pub const fn from_cols( x_axis: Vector<3, T, A>, y_axis: Vector<3, T, A>, z_axis: Vector<3, T, A>, w_axis: Vector<3, T, A>, ) -> Self
Creates a 3D affine transform from four column vectors.
Sourcepub const fn from_col_array(array: &[Vector<3, T, A>; 4]) -> Self
pub const fn from_col_array(array: &[Vector<3, T, A>; 4]) -> Self
Creates a 3D affine transform from four column vectors.
Sourcepub const fn to_col_array(&self) -> [Vector<3, T, A>; 4]
pub const fn to_col_array(&self) -> [Vector<3, T, A>; 4]
Converts the affine transform to four column vectors.
Sourcepub const fn as_col_array_ref(&self) -> &[Vector<3, T, A>; 4]
pub const fn as_col_array_ref(&self) -> &[Vector<3, T, A>; 4]
Returns a reference to the affine transform’s columns.
Sourcepub const fn as_col_array_mut(&mut self) -> &mut [Vector<3, T, A>; 4]
pub const fn as_col_array_mut(&mut self) -> &mut [Vector<3, T, A>; 4]
Returns a mutable reference to the affine transform’s columns.
Source§impl<T, A: Alignment> Affine<4, T, A>where
T: Scalar,
impl<T, A: Alignment> Affine<4, T, A>where
T: Scalar,
Sourcepub const fn from_cols(
x_axis: Vector<4, T, A>,
y_axis: Vector<4, T, A>,
z_axis: Vector<4, T, A>,
w_axis: Vector<4, T, A>,
fifth_axis: Vector<4, T, A>,
) -> Self
pub const fn from_cols( x_axis: Vector<4, T, A>, y_axis: Vector<4, T, A>, z_axis: Vector<4, T, A>, w_axis: Vector<4, T, A>, fifth_axis: Vector<4, T, A>, ) -> Self
Creates a 4D affine transform from five column vectors.
Sourcepub const fn from_col_array(array: &[Vector<4, T, A>; 5]) -> Self
pub const fn from_col_array(array: &[Vector<4, T, A>; 5]) -> Self
Creates a 4D affine transform from five column vectors.
Sourcepub const fn to_col_array(&self) -> [Vector<4, T, A>; 5]
pub const fn to_col_array(&self) -> [Vector<4, T, A>; 5]
Converts the affine transform to five column vectors.
Sourcepub const fn as_col_array_ref(&self) -> &[Vector<4, T, A>; 5]
pub const fn as_col_array_ref(&self) -> &[Vector<4, T, A>; 5]
Returns a reference to the affine transform’s columns.
Sourcepub const fn as_col_array_mut(&mut self) -> &mut [Vector<4, T, A>; 5]
pub const fn as_col_array_mut(&mut self) -> &mut [Vector<4, T, A>; 5]
Returns a mutable reference to the affine transform’s columns.