Struct mat3

Source
#[repr(C)]
pub struct mat3<T>(/* private fields */);
Expand description

3x3 matrix

Implementations§

Source§

impl<T: Copy> mat3<T>

Source

pub fn transpose(self) -> Self

Get transposed matrix.

§Examples
let matrix = mat3::translate(vec2(1, 2));
let matrix_transposed = matrix.transpose();
for i in 0..3 {
    for j in 0..3 {
        assert_eq!(matrix[(i, j)], matrix_transposed[(j, i)]);
    }
}
Source§

impl<T: Num> mat3<T>

Source

pub fn from_orts(x: vec2<T>, y: vec2<T>) -> Self

Construct a transformation matrix with given orts

§Examples
let e1 = vec2(1.0, 2.0);
let e2 = vec2(3.0, 4.0);
let m = mat3::from_orts(e1, e2);
assert_eq!(vec2(1.0, 0.0).transform(m), e1);
assert_eq!(vec2(0.0, 1.0).transform(m), e2);
let v = vec2(2.0, 3.0);
assert_eq!(v.transform(m), e1 * v.x + e2 * v.y);
Source

pub fn extend3d(self) -> mat4<T>

Extend this into a 3d transformation matrix, leaving z coordinate as is

Source§

impl<T: Float> mat3<T>

Source

pub fn inverse(self) -> Self

Get inverse matrix.

§Examples
let matrix = mat3::<f64>::rotate(Angle::from_radians(0.123));
let matrix_inv = matrix.inverse();
let mult = matrix * matrix_inv;
for i in 0..3 {
    for j in 0..3 {
        assert!((mult[(i, j)] - if i == j { 1.0 } else { 0.0 }).abs() < 1e-5);
    }
}
Source§

impl<T: Float> mat3<T>

Source

pub fn ortho(aabb: Aabb2<T>) -> Self

Get 2d part of the orthographic projection matrix

Source§

impl<T: Num + Copy> mat3<T>

Source

pub fn scale_uniform(factor: T) -> Self

Construct a uniform scale matrix.

§Examples
let matrix = mat3::scale_uniform(2);
assert_eq!(matrix * vec3(1, 2, 1), vec3(2, 4, 1));
Source

pub fn scale_uniform_around(p: vec2<T>, scale: T) -> Self

Construct matrix that performs uniform scaling around a specified point

Source

pub fn scale_around(p: vec2<T>, scale: vec2<T>) -> Self

Construct matrix that performs scaling around a specified point

Source

pub fn scale(factor: vec2<T>) -> Self

Construct a scale matrix.

§Examples
let matrix = mat3::scale(vec2(1, 2));
assert_eq!(matrix * vec3(1, 2, 1), vec3(1, 4, 1));
Source

pub fn translate(dv: vec2<T>) -> Self

Construct a translation matrix.

§Examples
let matrix = mat3::translate(vec2(3, 2));
assert_eq!(matrix * vec3(1, 2, 1), vec3(4, 4, 1));
Source§

impl<T: Float> mat3<T>

Source

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

Construct rotational matrix

Source

pub fn rotate_around(p: vec2<T>, angle: Angle<T>) -> Self

Construct matrix that performs rotation around a specified point

Source§

impl<T> mat3<T>

Source

pub fn map<U, F: Fn(T) -> U>(self, f: F) -> mat3<U>

Map every element

Source§

impl<T: Copy> mat3<T>

Source

pub fn new(values: [[T; 3]; 3]) -> Self

Construct a matrix.

§Examples
let matrix = mat3::new([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
]);
Source

pub fn row(&self, row_index: usize) -> vec3<T>

Get row as a vec3

Source

pub fn col(&self, col_index: usize) -> vec3<T>

Get column as a vec3

Source§

impl<T> mat3<T>

Source

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

Get self as a flat array

Source

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

Get self as a mutable flat array

Source§

impl<T: Num + Copy> mat3<T>

Source

pub fn zero() -> Self

Construct zero matrix.

§Examples
let matrix = mat3::<i32>::zero();
for i in 0..3 {
    for j in 0..3 {
        assert_eq!(matrix[(i, j)], 0);
    }
}
Source

pub fn identity() -> Self

Construct identity matrix.

§Examples
let matrix = mat3::<i32>::identity();
for i in 0..3 {
    for j in 0..3 {
        assert_eq!(matrix[(i, j)], if i == j { 1 } else { 0 });
    }
}

Trait Implementations§

Source§

impl<T: Num + Copy> Add for mat3<T>

Source§

type Output = mat3<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Num + Copy + AddAssign> AddAssign for mat3<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Float> Approx for mat3<T>

Source§

fn approx_distance_to(&self, other: &Self) -> f32

Get an approximated distance between two values
Source§

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

Check if values are approximately equal using DEFAULT_EPS
Source§

fn approx_eq_eps(&self, other: &Self, eps: f32) -> bool

Check if values are approximately equal using supplied eps value
Source§

impl<T: Clone> Clone for mat3<T>

Source§

fn clone(&self) -> mat3<T>

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<T: Debug> Debug for mat3<T>

Source§

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

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

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

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl<T: Num + Copy> Div<T> for mat3<T>

Source§

type Output = mat3<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: Num + Copy + DivAssign> DivAssign<T> for mat3<T>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T> Index<(usize, usize)> for mat3<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, (row, col): (usize, usize)) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<(usize, usize)> for mat3<T>

Source§

fn index_mut(&mut self, (row, col): (usize, usize)) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: Num + Copy> Mul<T> for mat3<T>

Source§

type Output = mat3<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Num + Copy> Mul<vec3<T>> for mat3<T>

Source§

type Output = vec3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<T>) -> vec3<T>

Performs the * operation. Read more
Source§

impl<T: Num + Copy + AddAssign> Mul for mat3<T>

Source§

type Output = mat3<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Num + Copy + MulAssign> MulAssign<T> for mat3<T>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T: Num + Copy + AddAssign> MulAssign for mat3<T>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<T: Num + Copy + Neg<Output = T>> Neg for mat3<T>

Source§

type Output = mat3<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<T> Serialize for mat3<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

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

impl<T: Num + Copy> Sub for mat3<T>

Source§

type Output = mat3<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Num + Copy + SubAssign> SubAssign for mat3<T>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<T: Copy> Copy for mat3<T>

Auto Trait Implementations§

§

impl<T> Freeze for mat3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for mat3<T>
where T: RefUnwindSafe,

§

impl<T> Send for mat3<T>
where T: Send,

§

impl<T> Sync for mat3<T>
where T: Sync,

§

impl<T> Unpin for mat3<T>
where T: Unpin,

§

impl<T> UnwindSafe for mat3<T>
where T: 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> 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<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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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