Struct glamour::Matrix3

source ·
#[repr(C)]
pub struct Matrix3<U: Scalar> { pub x_axis: Vector3<U>, pub y_axis: Vector3<U>, pub z_axis: Vector3<U>, }
Expand description

3x3 column-major matrix.

Bitwise compatible with glam::Mat3 / glam::DMat3.

Alignment: Same as T.

Fields§

§x_axis: Vector3<U>§y_axis: Vector3<U>§z_axis: Vector3<U>

Implementations§

source§

impl<T> Matrix3<T>
where T: FloatScalar,

source

pub const ZERO: Self = _

All zeroes.

source

pub const NAN: Self = _

All NaNs.

source

pub const IDENTITY: Self = _

Identity matrix

§Example
let matrix = Matrix3::<f32>::IDENTITY;
assert_eq!(matrix.row(0), vec3!(1.0, 0.0, 0.0));
assert_eq!(matrix.row(1), vec3!(0.0, 1.0, 0.0));
assert_eq!(matrix.row(2), vec3!(0.0, 0.0, 1.0));
source

pub fn transform_point<U: Unit<Scalar = T>>( &self, point: Point2<U>, ) -> Point2<U>

Transform 2D point.

See glam::Mat3::transform_point2() or glam::DMat3::transform_point2() (depending on the scalar).

§Example
let matrix = Matrix3::<f32>::from_angle(Angle::<f32>::from_degrees(90.0));
let point = Point2::<f32> { x: 1.0, y: 0.0 };
let rotated = matrix.transform_point(point);
approx::assert_abs_diff_eq!(rotated, point!(0.0, 1.0));
source

pub fn transform_vector<U: Unit<Scalar = T>>( &self, vector: Vector2<U>, ) -> Vector2<U>

Transform 2D vector.

See glam::Mat3::transform_vector2() or glam::DMat3::transform_vector2() (depending on the scalar).

source§

impl<T: FloatScalar> Matrix3<T>

source

pub fn is_nan(&self) -> bool

Returns true if any elements are NaN.

source

pub fn is_finite(&self) -> bool

Returns true if all elements are finite.

source

pub fn transpose(&self) -> Self

Returns the transpose of self.

source

pub fn inverse(&self) -> Self

Returns the inverse of self.

source

pub fn determinant(&self) -> T::Scalar

Returns the determinant of self.

source

pub fn abs(&self) -> Self

Takes the absolute value of each element in self.

source

pub fn mul_scalar(&self, rhs: T::Scalar) -> Self

Multiplies the matrix by a scalar.

source

pub fn div_scalar(&self, rhs: T::Scalar) -> Self

Divides the matrix by a scalar.

source

pub fn mul_vec3(&self, vec: Vector3<T>) -> Vector3<T>

Transforms a 3D vector.

source

pub fn from_cols( x_axis: Vector3<T>, y_axis: Vector3<T>, z_axis: Vector3<T>, ) -> Self

Creates a 3x3 matrix from three column vectors.

source

pub fn col(&self, index: usize) -> Vector3<T>

Returns the matrix column for the given index.

§Panics

Panics if index is greater than 2.

source

pub fn row(&self, index: usize) -> Vector3<T>

Returns the matrix row for the given index.

§Panics

Panics if index is greater than 2.

source

pub fn transform_vector2(&self, vector: Vector2<T>) -> Vector2<T>

Rotates the given 2D vector.

This is the equivalent of multiplying rhs as a 3D vector where z is 0.

This method assumes that self contains a valid affine transform.

§Panics

Will panic if the 2nd row of self is not (0, 0, 1) when glam_assert is enabled.

source

pub fn transform_point2(&self, point: Point2<T>) -> Point2<T>

Transforms the given 2D point.

This is the equivalent of multiplying rhs as a 3D vector where z is 1.

This method assumes that self contains a valid affine transform.

§Panics

Will panic if the 2nd row of self is not (0, 0, 1) when glam_assert is enabled.

source

pub fn from_scale(vector: Vector2<T>) -> Self

Creates an affine transformation matrix from the given non-uniform 2D scale.

See (e.g.) glam::Mat3::from_scale().

source

pub fn from_angle(angle: Angle<T::Scalar>) -> Self

Creates an affine transformation matrix from the given 2D rotation angle.

See (e.g.) glam::Mat3::from_angle().

source

pub fn from_axis_angle(axis: Vector3<T>, angle: Angle<T::Scalar>) -> Self

Creates a 3D rotation matrix from a normalized rotation axis and angle.

source

pub fn from_translation(translation: Vector2<T>) -> Self

Creates an affine transformation matrix from the given 2D translation.

See (e.g.) glam::Mat3::from_translation().

source

pub fn from_scale_angle_translation( scale: Vector2<T>, angle: Angle<T::Scalar>, translation: Vector2<T>, ) -> Self

Creates an affine transformation matrix from the given 2D scale, rotation angle and translation.

See (e.g.) glam::Mat3::from_scale_angle_translation().

source

pub fn from_diagonal(diagonal: Vector3<T>) -> Self

Creates a 3x3 matrix with its diagonal set to diagonal and all other entries set to 0.

source

pub fn from_quat(rotation: <T::Scalar as FloatScalar>::Quat) -> Self

Creates a 3D rotation matrix from the given quaternion.

source

pub fn from_rotation_x(angle: Angle<T::Scalar>) -> Self

Creates a 3D rotation matrix from angle around the x axis.

source

pub fn from_rotation_y(angle: Angle<T::Scalar>) -> Self

Creates a 3D rotation matrix from angle around the y axis.

source

pub fn from_rotation_z(angle: Angle<T::Scalar>) -> Self

Creates a 3D rotation matrix from angle around the z axis.

source

pub fn from_mat2(mat2: Matrix2<T::Scalar>) -> Self

Creates an affine transformation matrix from the given 2x2 matrix.

source

pub fn from_mat4(mat4: Matrix4<T::Scalar>) -> Self

Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column.

source

pub fn from_mat4_minor(mat4: Matrix4<T::Scalar>, i: usize, j: usize) -> Self

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

§Panics

Panics if i`` or j` is greater than 3.

source

pub fn mul_mat3(&self, other: &Self) -> Self

Multiplies two 3x3 matrices.

source

pub fn add_mat3(&self, other: &Self) -> Self

Adds two 3x3 matrices.

source

pub fn sub_mat3(&self, other: &Self) -> Self

Subtracts two 3x3 matrices.

source

pub fn to_cols_array(&self) -> [T::Scalar; 9]

Creates a [T; 9] array storing data in column major order.

source

pub fn to_cols_array_2d(&self) -> [[T::Scalar; 3]; 3]

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

source

pub fn from_cols_array(array: &[T::Scalar; 9]) -> Self

Creates a 3x3 matrix from a [T; 9] array stored in column major order.

source

pub fn from_rows(r0: Vector3<T>, r1: Vector3<T>, r2: Vector3<T>) -> Self

Create from rows (i.e., transposed).

source

pub fn is_invertible(&self) -> bool

Return true if the determinant is finite and nonzero.

source

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

Get the inverse if the matrix is invertible.

source

pub fn to_rows_array(&self) -> [T; 9]

Get the columns of the transposed matrix as a scalar array.

source

pub fn to_rows_array_2d(&self) -> [[T; 3]; 3]

Get the columns of the transposed matrix.

Trait Implementations§

source§

impl<T> AbsDiffEq for Matrix3<T>
where T: FloatScalar, T::Epsilon: Clone,

source§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

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

fn abs_diff_eq(&self, other: &Self, epsilon: Self::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: &Self, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl<T: Scalar> AsMut<[[T; 3]; 3]> for Matrix3<T>

source§

fn as_mut(&mut self) -> &mut [[T; 3]; 3]

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

impl<T: Scalar> AsRef<[[T; 3]; 3]> for Matrix3<T>

source§

fn as_ref(&self) -> &[[T; 3]; 3]

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

impl<U: Clone + Scalar> Clone for Matrix3<U>

source§

fn clone(&self) -> Matrix3<U>

Returns a copy 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<T> Debug for Matrix3<T>
where T: FloatScalar,

source§

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

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

impl<T> Default for Matrix3<T>
where T: FloatScalar,

source§

fn default() -> Self

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

impl<T> Div<T> for Matrix3<T>
where T: FloatScalar,

source§

type Output = Matrix3<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<T> DivAssign<T> for Matrix3<T>
where T: FloatScalar,

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl<T: Scalar> From<[[T; 3]; 3]> for Matrix3<T>

source§

fn from(value: [[T; 3]; 3]) -> Self

Converts to this type from the input type.
source§

impl<T: FloatScalar> From<[T; 9]> for Matrix3<T>

source§

fn from(value: [T; 9]) -> Matrix3<T>

Converts to this type from the input type.
source§

impl From<DMat3> for Matrix3<f64>

source§

fn from(mat: DMat3) -> Self

Converts to this type from the input type.
source§

impl From<Mat3> for Matrix3<f32>

source§

fn from(mat: Mat3) -> Self

Converts to this type from the input type.
source§

impl From<Mat3A> for Matrix3<f32>

source§

fn from(mat: Mat3A) -> Self

Converts to this type from the input type.
source§

impl<T: FloatScalar> From<Matrix3<T>> for [T; 9]

source§

fn from(value: Matrix3<T>) -> [T; 9]

Converts to this type from the input type.
source§

impl From<Matrix3<f32>> for Mat3

source§

fn from(mat: Matrix3<f32>) -> Self

Converts to this type from the input type.
source§

impl From<Matrix3<f32>> for Mat3A

source§

fn from(mat: Matrix3<f32>) -> Self

Converts to this type from the input type.
source§

impl From<Matrix3<f64>> for DMat3

source§

fn from(mat: Matrix3<f64>) -> Self

Converts to this type from the input type.
source§

impl<T> Mul<T> for Matrix3<T>
where T: FloatScalar,

source§

type Output = Matrix3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<T> Mul<Vector3<T>> for Matrix3<T::Scalar>
where T: FloatUnit,

source§

type Output = Vector3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Vector3<T>) -> Self::Output

Performs the * operation. Read more
source§

impl<T> Mul for Matrix3<T>
where T: FloatScalar,

source§

type Output = Matrix3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl<T> MulAssign<T> for Matrix3<T>
where T: FloatScalar,

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

impl<U: PartialEq + Scalar> PartialEq for Matrix3<U>

source§

fn eq(&self, other: &Matrix3<U>) -> bool

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

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

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

impl<T> RelativeEq for Matrix3<T>
where T: FloatScalar, T::Epsilon: Clone,

source§

fn default_max_relative() -> Self::Epsilon

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

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

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

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

The inverse of RelativeEq::relative_eq.
source§

impl<T: FloatScalar> Transparent for Matrix3<T>

source§

type Wrapped = <T as FloatScalar>::Mat3

The inner type that shares a compatible representation with Self.
source§

fn wrap(x: Self::Wrapped) -> Self

Wrap the inner type by copy. Read more
source§

fn peel(x: Self) -> Self::Wrapped

Unwrap the inner type by copy. Read more
source§

fn peel_ref(x: &Self) -> &Self::Wrapped

Convert a reference to the inner type. Read more
source§

fn peel_mut(x: &mut Self) -> &mut Self::Wrapped

Convert a mutable reference to the inner type. Read more
source§

impl<T: FloatScalar> UlpsEq for Matrix3<T>

source§

fn default_max_ulps() -> u32

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

fn ulps_eq(&self, other: &Self, epsilon: Self::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: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
source§

impl<T: Scalar> Zeroable for Matrix3<T>

source§

fn zeroed() -> Self

source§

impl<U: Copy + Scalar> Copy for Matrix3<U>

source§

impl<U: Eq + Scalar> Eq for Matrix3<U>

source§

impl<T: Scalar> Pod for Matrix3<T>

source§

impl<U: Scalar> StructuralPartialEq for Matrix3<U>

Auto Trait Implementations§

§

impl<U> Freeze for Matrix3<U>
where U: Freeze,

§

impl<U> RefUnwindSafe for Matrix3<U>
where U: RefUnwindSafe,

§

impl<U> Send for Matrix3<U>

§

impl<U> Sync for Matrix3<U>

§

impl<U> Unpin for Matrix3<U>
where U: Unpin,

§

impl<U> UnwindSafe for Matrix3<U>
where U: UnwindSafe,

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> 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<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, 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.
source§

impl<T> AnyBitPattern for T
where T: Pod,

source§

impl<T> NoUninit for T
where T: Pod,

source§

impl<T> PodValue for T
where T: Copy + Debug + Default + PartialEq + Pod + Send + Sync + Serializable + 'static,

source§

impl<T> Serializable for T

source§

impl<T> WasmComponentType for T