Skip to main content

Affine

Struct Affine 

Source
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:

  • N: Length (2, 3, or 4)
  • T: Scalar type (see Scalar)
  • A: Alignment (see Alignment)

§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 both Matrix<3, T, Aligned> and Vector<3, T, Aligned> don’t have padding, may have additional alignment.

  • Affine<4, T, Aligned>: has no padding, has the alignment of Matrix<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>

Source

pub const fn from_mat(mat: Matrix<N, T, A>) -> Self
where T: Zero,

Creates an affine transform from a matrix, expressing scale, rotation and shear.

Source

pub const fn from_translation(translation: Vector<N, T, A>) -> Self
where T: Zero + One,

Creates an affine transform from a translation vector.

Source

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.

Source

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

pub const fn align(&self) -> Affine<N, T, Aligned>

Converts the affine to Aligned alignment.

See Alignment for more information.

Source

pub const fn unalign(&self) -> Affine<N, T, Unaligned>

Converts the affine to Unaligned alignment.

See Alignment for more information.

Source§

impl<T, A: Alignment> Affine<2, T, A>
where T: Scalar,

Source

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.

Source

pub const fn from_col_array(array: &[Vector<2, T, A>; 3]) -> Self

Creates a 2D affine transform from three column vectors.

Source

pub const fn to_col_array(&self) -> [Vector<2, T, A>; 3]

Converts the affine transform to three column vectors.

Source

pub const fn as_col_array_ref(&self) -> &[Vector<2, T, A>; 3]

Returns a reference to the affine transform’s columns.

Source

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,

Source

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.

Source

pub const fn from_col_array(array: &[Vector<3, T, A>; 4]) -> Self

Creates a 3D affine transform from four column vectors.

Source

pub const fn to_col_array(&self) -> [Vector<3, T, A>; 4]

Converts the affine transform to four column vectors.

Source

pub const fn as_col_array_ref(&self) -> &[Vector<3, T, A>; 4]

Returns a reference to the affine transform’s columns.

Source

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,

Source

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.

Source

pub const fn from_col_array(array: &[Vector<4, T, A>; 5]) -> Self

Creates a 4D affine transform from five column vectors.

Source

pub const fn to_col_array(&self) -> [Vector<4, T, A>; 5]

Converts the affine transform to five column vectors.

Source

pub const fn as_col_array_ref(&self) -> &[Vector<4, T, A>; 5]

Returns a reference to the affine transform’s columns.

Source

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.

Source§

impl<const N: usize, T, A: Alignment> Affine<N, T, A>

Source

pub const ZERO: Self

All zeros.

Transforms any finite vector to zero.

Source§

impl<const N: usize, T, A: Alignment> Affine<N, T, A>
where Length<N>: SupportedLength, T: Scalar + Zero + One,

Source

pub const IDENTITY: Self

The identity transform.

Corresponds to no transformation.

Source§

impl<const N: usize, T, A: Alignment> Affine<N, T, A>
where Length<N>: SupportedLength, T: Scalar + Nan,

Source

pub const NAN: Self

All NaN (Not a Number).

Trait Implementations§

Source§

impl<const N: usize, T, A: Alignment> Clone for Affine<N, T, A>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const N: usize, T, A: Alignment> Debug for Affine<N, T, A>

Source§

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

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

impl<const N: usize, T, A: Alignment> Deref for Affine<N, T, A>

Source§

type Target = AffineDeref<N, T, A>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const N: usize, T, A: Alignment> DerefMut for Affine<N, T, A>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<const N: usize, T, A: Alignment> Display for Affine<N, T, A>

Source§

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

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

impl<const N: usize, T, A: Alignment> PartialEq for Affine<N, T, A>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &Self) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize, T, A: Alignment> Copy for Affine<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Eq for Affine<N, T, A>
where Length<N>: SupportedLength, T: Scalar + Eq,

Source§

impl<const N: usize, T, A: Alignment> RefUnwindSafe for Affine<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Send for Affine<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Sync for Affine<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Unpin for Affine<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> UnwindSafe for Affine<N, T, A>

Auto Trait Implementations§

§

impl<const N: usize, T, A> Freeze for Affine<N, T, A>
where <<T as Scalar>::Repr as ScalarRepr>::AffineRepr<N, T, A>: Freeze,

§

impl<const N: usize, T, A> UnsafeUnpin for Affine<N, T, A>
where <<T as Scalar>::Repr as ScalarRepr>::AffineRepr<N, T, A>: UnsafeUnpin,

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> 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<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<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.