Skip to main content

DMat2

Struct DMat2 

#[repr(C)]
pub struct DMat2 { pub x_axis: DVec2, pub y_axis: DVec2, }
Expand description

A 2x2 column major matrix.

Fields§

§x_axis: DVec2§y_axis: DVec2

Implementations§

§

impl DMat2

pub const ZERO: DMat2

A 2x2 matrix with all elements set to 0.0.

pub const IDENTITY: DMat2

A 2x2 identity matrix, where all diagonal elements are 1, and all off-diagonal elements are 0.

pub const NAN: DMat2

All NAN:s.

pub const fn from_cols(x_axis: DVec2, y_axis: DVec2) -> DMat2

Creates a 2x2 matrix from two column vectors.

See also Self::from_rows when the data is in row major order.

pub const fn from_rows(row0: DVec2, row1: DVec2) -> DMat2

Creates a 2x2 matrix from two row vectors.

Matrices are stored in column major order, so the given rows are permuted into the matrix layout. Use Self::from_cols instead when the data is already in column major order.

pub const fn from_cols_array(m: &[f64; 4]) -> DMat2

Creates a 2x2 matrix from a [f64; 4] array stored in column major order.

If the data is in row major order use Self::from_rows_array instead.

pub const fn to_cols_array(&self) -> [f64; 4]

Creates a [f64; 4] array storing data in column major order.

If you require the data in row major order use Self::to_rows_array instead.

pub const fn from_cols_array_2d(m: &[[f64; 2]; 2]) -> DMat2

Creates a 2x2 matrix from a [[f64; 2]; 2] 2D array stored in column major order.

If the data is in row major order transpose the returned matrix.

pub const fn to_cols_array_2d(&self) -> [[f64; 2]; 2]

Creates a [[f64; 2]; 2] 2D array storing data in column major order.

If you require row major order transpose the matrix first.

pub const fn from_rows_array(m: &[f64; 4]) -> DMat2

Creates a 2x2 matrix from a [f64; 4] array stored in row major order.

Matrices are stored in column major order, so the array is permuted into the matrix layout. Use Self::from_cols_array instead when the data is already in column major order.

pub const fn to_rows_array(&self) -> [f64; 4]

Creates a [f64; 4] array storing data in row major order.

Matrices are stored in column major order, so the array is permuted out of the column major storage. Use Self::to_cols_array instead when you want data in column major order.

pub const fn from_diagonal(diagonal: DVec2) -> DMat2

Creates a 2x2 matrix with its diagonal set to diagonal and all other entries set to 0.

pub fn from_scale_angle(scale: DVec2, angle: f64) -> DMat2

Creates a 2x2 matrix containing the combining non-uniform scale and rotation of angle (in radians).

pub fn from_angle(angle: f64) -> DMat2

Creates a 2x2 matrix containing a rotation of angle (in radians).

pub fn from_mat3(m: DMat3) -> DMat2

Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column.

pub fn from_mat3_minor(m: DMat3, i: usize, j: usize) -> DMat2

Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the ith column and jth row.

§Panics

Panics if i or j is greater than 2.

pub const fn from_cols_slice(slice: &[f64]) -> DMat2

Creates a 2x2 matrix from the first 4 values in slice.

See also Self::from_rows_slice when the slice is in row major order.

§Panics

Panics if slice is less than 4 elements long.

pub fn write_cols_to_slice(&self, slice: &mut [f64])

Writes the columns of self to the first 4 elements in slice.

§Panics

Panics if slice is less than 4 elements long.

pub const fn from_rows_slice(slice: &[f64]) -> DMat2

Creates a 2x2 matrix from the first 4 values in slice, stored in row major order.

Matrices are stored in column major order, so the slice is permuted into the matrix layout. Use Self::from_cols_slice instead when the slice is already in column major order.

§Panics

Panics if slice is less than 4 elements long.

pub fn col(&self, index: usize) -> DVec2

Returns the matrix column for the given index.

§Panics

Panics if index is greater than 1.

pub fn col_mut(&mut self, index: usize) -> &mut DVec2

Returns a mutable reference to the matrix column for the given index.

§Panics

Panics if index is greater than 1.

pub fn row(&self, index: usize) -> DVec2

Returns the matrix row for the given index.

See also Self::set_row when you need to change the row.

§Panics

Panics if index is greater than 1.

pub fn set_row(&mut self, index: usize, row: DVec2)

Sets the matrix row for the given index.

Matrices are stored in column major order, so the row is spread across all 2 columns and writing it touches every column. Use Self::col_mut instead when you can work with columns. See also Self::row.

§Panics

Panics if index is greater than 1.

pub fn is_finite(&self) -> bool

Returns true if, and only if, all elements are finite. If any element is either NaN, positive or negative infinity, this will return false.

pub fn is_nan(&self) -> bool

Returns true if any elements are NaN.

pub fn transpose(&self) -> DMat2

Returns the transpose of self.

pub fn diagonal(&self) -> DVec2

Returns the diagonal of self.

pub fn determinant(&self) -> f64

Returns the determinant of self.

pub fn inverse(&self) -> DMat2

Returns the inverse of self.

If the matrix is not invertible the returned matrix will be invalid. The returned matrix will also be invalid if the inverse is not finite, which can happen when self contains very large or very small values. Use Self::try_inverse or Self::inverse_or_zero to detect these cases.

§Panics

Will panic if the resulting inverted matrix is not finite when glam_assert is enabled.

pub fn try_inverse(&self) -> Option<DMat2>

Returns the inverse of self or None if the matrix is not invertible, or if the inverse is not finite.

pub fn inverse_or_zero(&self) -> DMat2

Returns the inverse of self or DMat2::ZERO if the matrix is not invertible, or if the inverse is not finite.

pub fn mul_vec2(&self, rhs: DVec2) -> DVec2

Transforms a 2D vector.

pub fn mul_transpose_vec2(&self, rhs: DVec2) -> DVec2

Transforms a 2D vector by the transpose of self.

pub fn mul_mat2(&self, rhs: &DMat2) -> DMat2

Multiplies two 2x2 matrices.

pub fn add_mat2(&self, rhs: &DMat2) -> DMat2

Adds two 2x2 matrices.

pub fn sub_mat2(&self, rhs: &DMat2) -> DMat2

Subtracts two 2x2 matrices.

pub fn mul_scalar(&self, rhs: f64) -> DMat2

Multiplies a 2x2 matrix by a scalar.

pub fn mul_diagonal_scale(&self, scale: DVec2) -> DMat2

Multiply self by a scaling vector scale. This is faster than creating a whole diagonal scaling matrix and then multiplying that. This operation is commutative.

pub fn div_scalar(&self, rhs: f64) -> DMat2

Divides a 2x2 matrix by a scalar.

pub fn recip(&self) -> DMat2

Returns a matrix containing the reciprocal 1.0/n of each element of self.

pub fn abs_diff_eq(&self, rhs: DMat2, max_abs_diff: f64) -> bool

Returns true if the absolute difference of all elements between self and rhs is less than or equal to max_abs_diff.

This can be used to compare if two matrices contain similar elements. It works best when comparing with a known value. The max_abs_diff that should be used used depends on the values being compared against.

For more see comparing floating point numbers.

pub fn abs(&self) -> DMat2

Takes the absolute value of each element in self

pub fn as_mat2(&self) -> Mat2

Trait Implementations§

§

impl AbsDiffEq for DMat2

§

type Epsilon = <f64 as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
§

fn default_epsilon() -> <DMat2 as AbsDiffEq>::Epsilon

The default tolerance to use when testing values that are close together. Read more
§

fn abs_diff_eq( &self, other: &DMat2, epsilon: <DMat2 as AbsDiffEq>::Epsilon, ) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
§

impl Add for DMat2

§

type Output = DMat2

The resulting type after applying the + operator.
§

fn add(self, rhs: DMat2) -> DMat2

Performs the + operation. Read more
§

impl Add<&DMat2> for DMat2

§

type Output = DMat2

The resulting type after applying the + operator.
§

fn add(self, rhs: &DMat2) -> DMat2

Performs the + operation. Read more
§

impl Add<&DMat2> for &DMat2

§

type Output = DMat2

The resulting type after applying the + operator.
§

fn add(self, rhs: &DMat2) -> DMat2

Performs the + operation. Read more
§

impl Add<DMat2> for &DMat2

§

type Output = DMat2

The resulting type after applying the + operator.
§

fn add(self, rhs: DMat2) -> DMat2

Performs the + operation. Read more
§

impl AddAssign for DMat2

§

fn add_assign(&mut self, rhs: DMat2)

Performs the += operation. Read more
§

impl AddAssign<&DMat2> for DMat2

§

fn add_assign(&mut self, rhs: &DMat2)

Performs the += operation. Read more
§

impl AsMut<[f64; 4]> for DMat2

§

fn as_mut(&mut self) -> &mut [f64; 4]

Converts this type into a mutable reference of the (usually inferred) input type.
§

impl AsRef<[f64; 4]> for DMat2

§

fn as_ref(&self) -> &[f64; 4]

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Clone for DMat2

§

fn clone(&self) -> DMat2

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
§

impl Copy for DMat2

§

impl Debug for DMat2

§

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

Formats the value using the given formatter. Read more
§

impl Default for DMat2

§

fn default() -> DMat2

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for DMat2

Deserialize expects a sequence of 4 values.

§

fn deserialize<D>( deserializer: D, ) -> Result<DMat2, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for DMat2

§

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

Formats the value using the given formatter. Read more
§

impl Div<&f64> for DMat2

§

type Output = DMat2

The resulting type after applying the / operator.
§

fn div(self, rhs: &f64) -> DMat2

Performs the / operation. Read more
§

impl Div<&f64> for &DMat2

§

type Output = DMat2

The resulting type after applying the / operator.
§

fn div(self, rhs: &f64) -> DMat2

Performs the / operation. Read more
§

impl Div<f64> for DMat2

§

type Output = DMat2

The resulting type after applying the / operator.
§

fn div(self, rhs: f64) -> DMat2

Performs the / operation. Read more
§

impl Div<f64> for &DMat2

§

type Output = DMat2

The resulting type after applying the / operator.
§

fn div(self, rhs: f64) -> DMat2

Performs the / operation. Read more
§

impl DivAssign<&f64> for DMat2

§

fn div_assign(&mut self, rhs: &f64)

Performs the /= operation. Read more
§

impl DivAssign<f64> for DMat2

§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl<S> From<Matrix<f64, Const<2>, Const<2>, S>> for DMat2
where S: RawStorage<f64, Const<2>, Const<2>>,

Source§

fn from(e: Matrix<f64, Const<2>, Const<2>, S>) -> DMat2

Converts to this type from the input type.
Source§

impl From<Rotation<f64, 2>> for DMat2

Source§

fn from(e: Rotation<f64, 2>) -> DMat2

Converts to this type from the input type.
Source§

impl From<Unit<Complex<f64>>> for DMat2

Source§

fn from(e: Unit<Complex<f64>>) -> DMat2

Converts to this type from the input type.
§

impl Mul for DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: DMat2) -> DMat2

Performs the * operation. Read more
§

impl Mul<&DMat2> for DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: &DMat2) -> DMat2

Performs the * operation. Read more
§

impl Mul<&DMat2> for &DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: &DMat2) -> DMat2

Performs the * operation. Read more
§

impl Mul<&DVec2> for DMat2

§

type Output = DVec2

The resulting type after applying the * operator.
§

fn mul(self, rhs: &DVec2) -> DVec2

Performs the * operation. Read more
§

impl Mul<&DVec2> for &DMat2

§

type Output = DVec2

The resulting type after applying the * operator.
§

fn mul(self, rhs: &DVec2) -> DVec2

Performs the * operation. Read more
§

impl Mul<&f64> for DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: &f64) -> DMat2

Performs the * operation. Read more
§

impl Mul<&f64> for &DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: &f64) -> DMat2

Performs the * operation. Read more
§

impl Mul<DMat2> for &DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: DMat2) -> DMat2

Performs the * operation. Read more
§

impl Mul<DVec2> for DMat2

§

type Output = DVec2

The resulting type after applying the * operator.
§

fn mul(self, rhs: DVec2) -> <DMat2 as Mul<DVec2>>::Output

Performs the * operation. Read more
§

impl Mul<DVec2> for &DMat2

§

type Output = DVec2

The resulting type after applying the * operator.
§

fn mul(self, rhs: DVec2) -> DVec2

Performs the * operation. Read more
§

impl Mul<f64> for DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: f64) -> DMat2

Performs the * operation. Read more
§

impl Mul<f64> for &DMat2

§

type Output = DMat2

The resulting type after applying the * operator.
§

fn mul(self, rhs: f64) -> DMat2

Performs the * operation. Read more
§

impl MulAssign for DMat2

§

fn mul_assign(&mut self, rhs: DMat2)

Performs the *= operation. Read more
§

impl MulAssign<&DMat2> for DMat2

§

fn mul_assign(&mut self, rhs: &DMat2)

Performs the *= operation. Read more
§

impl MulAssign<&f64> for DMat2

§

fn mul_assign(&mut self, rhs: &f64)

Performs the *= operation. Read more
§

impl MulAssign<f64> for DMat2

§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
§

impl Neg for DMat2

§

type Output = DMat2

The resulting type after applying the - operator.
§

fn neg(self) -> <DMat2 as Neg>::Output

Performs the unary - operation. Read more
§

impl Neg for &DMat2

§

type Output = DMat2

The resulting type after applying the - operator.
§

fn neg(self) -> DMat2

Performs the unary - operation. Read more
§

impl PartialEq for DMat2

§

fn eq(&self, rhs: &DMat2) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
§

impl Pod for DMat2

§

impl Product for DMat2

§

fn product<I>(iter: I) -> DMat2
where I: Iterator<Item = DMat2>,

Takes an iterator and generates Self from the elements by multiplying the items.
§

impl<'a> Product<&'a DMat2> for DMat2

§

fn product<I>(iter: I) -> DMat2
where I: Iterator<Item = &'a DMat2>,

Takes an iterator and generates Self from the elements by multiplying the items.
§

impl RelativeEq for DMat2

§

fn default_max_relative() -> <DMat2 as AbsDiffEq>::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
§

fn relative_eq( &self, other: &DMat2, epsilon: <DMat2 as AbsDiffEq>::Epsilon, max_relative: <DMat2 as AbsDiffEq>::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
§

impl Serialize for DMat2

Serialize as a sequence of 4 values.

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Sub for DMat2

§

type Output = DMat2

The resulting type after applying the - operator.
§

fn sub(self, rhs: DMat2) -> DMat2

Performs the - operation. Read more
§

impl Sub<&DMat2> for DMat2

§

type Output = DMat2

The resulting type after applying the - operator.
§

fn sub(self, rhs: &DMat2) -> DMat2

Performs the - operation. Read more
§

impl Sub<&DMat2> for &DMat2

§

type Output = DMat2

The resulting type after applying the - operator.
§

fn sub(self, rhs: &DMat2) -> DMat2

Performs the - operation. Read more
§

impl Sub<DMat2> for &DMat2

§

type Output = DMat2

The resulting type after applying the - operator.
§

fn sub(self, rhs: DMat2) -> DMat2

Performs the - operation. Read more
§

impl SubAssign for DMat2

§

fn sub_assign(&mut self, rhs: DMat2)

Performs the -= operation. Read more
§

impl SubAssign<&DMat2> for DMat2

§

fn sub_assign(&mut self, rhs: &DMat2)

Performs the -= operation. Read more
§

impl Sum for DMat2

§

fn sum<I>(iter: I) -> DMat2
where I: Iterator<Item = DMat2>,

Takes an iterator and generates Self from the elements by “summing up” the items.
§

impl<'a> Sum<&'a DMat2> for DMat2

§

fn sum<I>(iter: I) -> DMat2
where I: Iterator<Item = &'a DMat2>,

Takes an iterator and generates Self from the elements by “summing up” the items.
§

impl UlpsEq for DMat2

§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
§

fn ulps_eq( &self, other: &DMat2, epsilon: <DMat2 as AbsDiffEq>::Epsilon, max_ulps: u32, ) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
Source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
§

impl Zeroable for DMat2

Source§

fn zeroed() -> Self

Auto Trait Implementations§

§

impl Freeze for DMat2

§

impl RefUnwindSafe for DMat2

§

impl Send for DMat2

§

impl Sync for DMat2

§

impl Unpin for DMat2

§

impl UnsafeUnpin for DMat2

§

impl UnwindSafe for DMat2

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> AnyBitPattern for T
where T: Pod,

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

Source§

impl<T, Right> ClosedDiv<Right> for T
where T: Div<Right, Output = T> + DivAssign<Right>,

Source§

impl<T, Right> ClosedDivAssign<Right> for T
where T: ClosedDiv<Right> + DivAssign<Right>,

Source§

impl<T, Right> ClosedMul<Right> for T
where T: Mul<Right, Output = T> + MulAssign<Right>,

Source§

impl<T, Right> ClosedMulAssign<Right> for T
where T: ClosedMul<Right> + MulAssign<Right>,

Source§

impl<T> ClosedNeg for T
where T: Neg<Output = T>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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<T> NoUninit for T
where T: Pod,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.