Skip to main content

Mat2

Struct Mat2 

Source
#[repr(C)]
pub struct Mat2<T> { pub cols: Vec2<Vec2<T>>, }
Expand description

2x2 matrix.

Fields§

§cols: Vec2<Vec2<T>>

Implementations§

Source§

impl<T> Mat2<T>

Source

pub const ROW_COUNT: usize = 2

Convenience constant representing the number of rows for matrices of this type.

Source

pub const COL_COUNT: usize = 2

Convenience constant representing the number of columns for matrices of this type.

Source

pub fn identity() -> Mat2<T>
where T: Zero + One,

The identity matrix, which is also the default value for square matrices.

assert_eq!(Mat4::<f32>::default(), Mat4::<f32>::identity());
Source

pub fn zero() -> Mat2<T>
where T: Zero,

The matrix with all elements set to zero.

Source

pub fn apply<F>(&mut self, f: F)
where T: Copy, F: FnMut(T) -> T,

Applies the function f to each element of this matrix, in-place.

For an example, see the map() method.

Source

pub fn apply2<F, S>(&mut self, other: Mat2<S>, f: F)
where T: Copy, F: FnMut(T, S) -> T,

Applies the function f to each element of this matrix, in-place.

For an example, see the map2() method.

Source

pub fn numcast<D>(self) -> Option<Mat2<D>>
where T: NumCast, D: NumCast,

Returns a memberwise-converted copy of this matrix, using NumCast.

let m = Mat4::<f32>::identity();
let m: Mat4<i32> = m.numcast().unwrap();
assert_eq!(m, Mat4::identity());
Source

pub fn broadcast_diagonal(val: T) -> Mat2<T>
where T: Zero + Copy,

Initializes a new matrix with elements of the diagonal set to val and the other to zero.

In a way, this is the same as single-argument matrix constructors in GLSL and GLM.

assert_eq!(Mat4::broadcast_diagonal(0), Mat4::zero());
assert_eq!(Mat4::broadcast_diagonal(1), Mat4::identity());
assert_eq!(Mat4::broadcast_diagonal(2), Mat4::new(
    2,0,0,0,
    0,2,0,0,
    0,0,2,0,
    0,0,0,2,
));
Source

pub fn with_diagonal(d: Vec2<T>) -> Mat2<T>
where T: Zero + Copy,

Initializes a matrix by its diagonal, setting other elements to zero.

Source

pub fn diagonal(self) -> Vec2<T>

Gets the matrix’s diagonal into a vector.

assert_eq!(Mat4::<u32>::zero().diagonal(), Vec4::zero());
assert_eq!(Mat4::<u32>::identity().diagonal(), Vec4::one());

let mut m = Mat4::zero();
m[(0, 0)] = 1;
m[(1, 1)] = 2;
m[(2, 2)] = 3;
m[(3, 3)] = 4;
assert_eq!(m.diagonal(), Vec4::new(1, 2, 3, 4));
assert_eq!(m.diagonal(), Vec4::iota() + 1);
Source

pub fn trace(self) -> T
where T: Add<Output = T>,

The sum of the diagonal’s elements.

assert_eq!(Mat4::<u32>::zero().trace(), 0);
assert_eq!(Mat4::<u32>::identity().trace(), 4);
Source

pub fn mul_memberwise(self, m: Mat2<T>) -> Mat2<T>
where T: Mul<Output = T>,

Multiply elements of this matrix with another’s.


let m = Mat4::new(
    0, 1, 2, 3,
    1, 2, 3, 4,
    2, 3, 4, 5,
    3, 4, 5, 6,
);
let r = Mat4::new(
    0, 1, 4, 9,
    1, 4, 9, 16,
    4, 9, 16, 25,
    9, 16, 25, 36,
);
assert_eq!(m.mul_memberwise(m), r);
Source

pub fn row_count(&self) -> usize

Convenience for getting the number of rows of this matrix.

Source

pub fn col_count(&self) -> usize

Convenience for getting the number of columns of this matrix.

Source

pub fn is_packed(&self) -> bool

Are all elements of this matrix tightly packed together in memory ?

This might not be the case for matrices in the repr_simd module (it depends on the target architecture).

Source§

impl<T> Mat2<T>

Source

pub fn map_cols<D, F>(self, f: F) -> Mat2<D>
where F: FnMut(Vec2<T>) -> Vec2<D>,

Returns a column-wise-converted copy of this matrix, using the given conversion closure.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<f32>::new(
    0.25, 1.25, 5.56, 8.66,
    8.53, 2.92, 3.86, 9.36,
    1.02, 0.28, 5.52, 6.06,
    6.20, 7.01, 4.90, 5.26
);
let m = m.map_cols(|col| col.map(|x| x.round() as i32));
assert_eq!(m, Mat4::new(
    0, 1, 6, 9,
    9, 3, 4, 9,
    1, 0, 6, 6,
    6, 7, 5, 5
));
Source

pub fn into_col_array(self) -> [T; 4]

Converts this matrix into a fixed-size array of elements.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
    0, 4, 8, 12,
    1, 5, 9, 13,
    2, 6, 10, 14,
    3, 7, 11, 15
];
assert_eq!(m.into_col_array(), array);
Source

pub fn into_col_arrays(self) -> [[T; 2]; 2]

Converts this matrix into a fixed-size array of fixed-size arrays of elements.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
    [ 0, 4,  8, 12, ],
    [ 1, 5,  9, 13, ],
    [ 2, 6, 10, 14, ],
    [ 3, 7, 11, 15, ],
];
assert_eq!(m.into_col_arrays(), array);
Source

pub fn from_col_array(array: [T; 4]) -> Mat2<T>

Converts a fixed-size array of elements into a matrix.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
    0, 4, 8, 12,
    1, 5, 9, 13,
    2, 6, 10, 14,
    3, 7, 11, 15
];
assert_eq!(m, Mat4::from_col_array(array));
Source

pub fn from_col_arrays(array: [[T; 2]; 2]) -> Mat2<T>

Converts a fixed-size array of fixed-size arrays of elements into a matrix.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
    [ 0, 4,  8, 12, ],
    [ 1, 5,  9, 13, ],
    [ 2, 6, 10, 14, ],
    [ 3, 7, 11, 15, ],
];
assert_eq!(m, Mat4::from_col_arrays(array));
Source

pub fn into_row_array(self) -> [T; 4]

Converts this matrix into a fixed-size array of elements.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
];
assert_eq!(m.into_row_array(), array);
Source

pub fn into_row_arrays(self) -> [[T; 2]; 2]

Converts this matrix into a fixed-size array of fixed-size arrays of elements.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
    [  0,  1,  2,  3, ],
    [  4,  5,  6,  7, ],
    [  8,  9, 10, 11, ],
    [ 12, 13, 14, 15, ],
];
assert_eq!(m.into_row_arrays(), array);
Source

pub fn from_row_array(array: [T; 4]) -> Mat2<T>

Converts a fixed-size array of elements into a matrix.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
];
assert_eq!(m, Mat4::from_row_array(array));
Source

pub fn from_row_arrays(array: [[T; 2]; 2]) -> Mat2<T>

Converts a fixed-size array of fixed-size array of elements into a matrix.

use vek::mat::repr_c::column_major::Mat4;

let m = Mat4::<u32>::new(
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15
);
let array = [
    [  0,  1,  2,  3, ],
    [  4,  5,  6,  7, ],
    [  8,  9, 10, 11, ],
    [ 12, 13, 14, 15, ],
];
assert_eq!(m, Mat4::from_row_arrays(array));
Source

pub fn as_col_ptr(&self) -> *const T

Gets a const pointer to this matrix’s elements.

§Panics

Panics if the matrix’s elements are not tightly packed in memory, which may be the case for matrices in the repr_simd module. You may check this with the is_packed() method.

Source

pub fn as_mut_col_ptr(&mut self) -> *mut T

Gets a mut pointer to this matrix’s elements.

§Panics

Panics if the matrix’s elements are not tightly packed in memory, which may be the case for matrices in the repr_simd module. You may check this with the is_packed() method.

Source

pub fn as_col_slice(&self) -> &[T]

View this matrix as an immutable slice.

§Panics

Panics if the matrix’s elements are not tightly packed in memory, which may be the case for matrices in the repr_simd module. You may check this with the is_packed() method.

Source

pub fn as_mut_col_slice(&mut self) -> &mut [T]

View this matrix as a mutable slice.

§Panics

Panics if the matrix’s elements are not tightly packed in memory, which may be the case for matrices in the repr_simd module. You may check this with the is_packed() method.

Source§

impl<T> Mat2<T>

Source

pub const GL_SHOULD_TRANSPOSE: bool = false

The transpose parameter to pass to OpenGL glUniformMatrix*() functions.

Source

pub fn gl_should_transpose(&self) -> bool

Gets the transpose parameter to pass to OpenGL glUniformMatrix*() functions.

The return value is a plain bool which you may directly cast to a GLboolean.

This takes &self to prevent surprises when changing the type of matrix you plan to send.

Source§

impl<T> Mat2<T>

Source

pub fn map<D, F>(self, f: F) -> Mat2<D>
where F: FnMut(T) -> D,

Returns an element-wise-converted copy of this matrix, using the given conversion closure.

use vek::mat::repr_c::row_major::Mat4;

let m = Mat4::<f32>::new(
    0.25, 1.25, 5.56, 8.66,
    8.53, 2.92, 3.86, 9.36,
    1.02, 0.28, 5.52, 6.06,
    6.20, 7.01, 4.90, 5.26
);
let m = m.map(|x| x.round() as i32);
assert_eq!(m, Mat4::new(
    0, 1, 6, 9,
    9, 3, 4, 9,
    1, 0, 6, 6,
    6, 7, 5, 5
));
Source

pub fn as_<D>(self) -> Mat2<D>
where T: AsPrimitive<D>, D: 'static + Copy,

Returns a memberwise-converted copy of this matrix, using AsPrimitive.

§Examples
let v = Vec4::new(0_f32, 1., 2., 3.);
let i: Vec4<i32> = v.as_();
assert_eq!(i, Vec4::new(0, 1, 2, 3));
§Safety

In Rust versions before 1.45.0, some uses of the as operator were not entirely safe. In particular, it was undefined behavior if a truncated floating point value could not fit in the target integer type (#10184);

let x: u8 = (1.04E+17).as_(); // UB
Source

pub fn map2<D, F, S>(self, other: Mat2<S>, f: F) -> Mat2<D>
where F: FnMut(T, S) -> D,

Applies the function f to each element of two matrices, pairwise, and returns the result.

use vek::mat::repr_c::row_major::Mat4;

let a = Mat4::<f32>::new(
    0.25, 1.25, 2.52, 2.99,
    0.25, 1.25, 2.52, 2.99,
    0.25, 1.25, 2.52, 2.99,
    0.25, 1.25, 2.52, 2.99
);
let b = Mat4::<i32>::new(
    0, 1, 0, 0,
    1, 0, 0, 0,
    0, 0, 1, 0,
    0, 0, 0, 1
);
let m = a.map2(b, |a, b| a.round() as i32 + b);
assert_eq!(m, Mat4::new(
    0, 2, 3, 3,
    1, 1, 3, 3,
    0, 1, 4, 3,
    0, 1, 3, 4
));
Source

pub fn transposed(self) -> Mat2<T>

The matrix’s transpose.


let m = Mat2::new(
    0, 1,
    4, 5
);
let t = Mat2::new(
    0, 4,
    1, 5
);
assert_eq!(m.transposed(), t);
assert_eq!(m, m.transposed().transposed());
Source

pub fn transpose(&mut self)

Transpose this matrix.


let mut m = Mat2::new(
    0, 1,
    4, 5
);
let t = Mat2::new(
    0, 4,
    1, 5
);
m.transpose();
assert_eq!(m, t);
Source

pub fn determinant(self) -> T
where T: Mul<Output = T> + Sub<Output = T>,

Get this matrix’s determinant.

A matrix is invertible if its determinant is non-zero.

let (a,b,c,d) = (0,1,2,3);
let m = Mat2::new(a,b,c,d);
assert_eq!(m.determinant(), a*d - c*b);
Source

pub fn rotate_z(&mut self, angle_radians: T)
where T: Real + MulAdd<Output = T>,

Rotates this matrix around the Z axis (counter-clockwise rotation in 2D).

Source

pub fn rotated_z(self, angle_radians: T) -> Mat2<T>
where T: Real + MulAdd<Output = T>,

Rotates this matrix around the Z axis (counter-clockwise rotation in 2D).

Source

pub fn rotation_z(angle_radians: T) -> Mat2<T>
where T: Real,

Creates a matrix that rotates around the Z axis (counter-clockwise rotation in 2D).

Source

pub fn scale_2d<V>(&mut self, v: V)
where V: Into<Vec2<T>>, T: Real + MulAdd<Output = T>,

Scales this matrix in 2D.

Source

pub fn scaled_2d<V>(self, v: V) -> Mat2<T>
where V: Into<Vec2<T>>, T: Real + MulAdd<Output = T>,

Returns this matrix scaled in 2D.

Source

pub fn scaling_2d<V>(v: V) -> Mat2<T>
where V: Into<Vec2<T>>, T: Zero,

Creates a 2D scaling matrix.

Source

pub fn shear_x(&mut self, k: T)
where T: Real + MulAdd<Output = T>,

Shears this matrix along the X axis.

Source

pub fn sheared_x(self, k: T) -> Mat2<T>
where T: Real + MulAdd<Output = T>,

Returns this matrix sheared along the X axis.

Source

pub fn shearing_x(k: T) -> Mat2<T>
where T: Zero + One,

Creates a 2D shearing matrix along the X axis.

Source

pub fn shear_y(&mut self, k: T)
where T: Real + MulAdd<Output = T>,

Shears this matrix along the Y axis.

Source

pub fn sheared_y(self, k: T) -> Mat2<T>
where T: Real + MulAdd<Output = T>,

Returns this matrix sheared along the Y axis.

Source

pub fn shearing_y(k: T) -> Mat2<T>
where T: Zero + One,

Creates a 2D shearing matrix along the Y axis.

Source§

impl<T> Mat2<T>

Source

pub fn new(m00: T, m01: T, m10: T, m11: T) -> Mat2<T>

Creates a new 2x2 matrix from elements in a layout-agnostic way.

The parameters are named mij where i is the row index and j the column index. Their order is always the same regardless of the matrix’s layout.

Trait Implementations§

Source§

impl<T> AbsDiffEq for Mat2<T>
where T: AbsDiffEq, <T as AbsDiffEq>::Epsilon: Copy,

Source§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

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

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

fn abs_diff_eq( &self, other: &Mat2<T>, epsilon: <Mat2<T> 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.
Source§

impl<T> Add<T> for Mat2<T>
where T: Copy + Add<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> <Mat2<T> as Add<T>>::Output

Performs the + operation. Read more
Source§

impl<T> Add for Mat2<T>
where T: Add<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Mat2<T>) -> <Mat2<T> as Add>::Output

Performs the + operation. Read more
Source§

impl<T> AddAssign<T> for Mat2<T>
where T: Add<Output = T> + Copy,

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<T> AddAssign for Mat2<T>
where T: Add<Output = T> + Copy,

Source§

fn add_assign(&mut self, rhs: Mat2<T>)

Performs the += operation. Read more
Source§

impl<T> Clone for Mat2<T>
where T: Clone,

Source§

fn clone(&self) -> Mat2<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 for Mat2<T>
where T: Debug,

Source§

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

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

impl<T> Default for Mat2<T>
where T: Zero + One,

The default value for a square matrix is the identity.

assert_eq!(Mat4::<f32>::default(), Mat4::<f32>::identity());
Source§

fn default() -> Mat2<T>

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

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

Source§

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

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

impl<T> Display for Mat2<T>
where T: Display,

Displays this matrix using the following format:

(i being the number of rows and j the number of columns)

( m00 ... m0j
  ... ... ...
  mi0 ... mij )

Note that elements are not comma-separated. This format doesn’t depend on the matrix’s storage layout.

Source§

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

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

impl<T> Div<T> for Mat2<T>
where T: Copy + Div<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> <Mat2<T> as Div<T>>::Output

Performs the / operation. Read more
Source§

impl<T> Div for Mat2<T>
where T: Div<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Mat2<T>) -> <Mat2<T> as Div>::Output

Performs the / operation. Read more
Source§

impl<T> DivAssign<T> for Mat2<T>
where T: Div<Output = T> + Copy,

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T> DivAssign for Mat2<T>
where T: Div<Output = T> + Copy,

Source§

fn div_assign(&mut self, rhs: Mat2<T>)

Performs the /= operation. Read more
Source§

impl<T> From<Mat2<T>> for Mat2<T>

Source§

fn from(m: Mat2<T>) -> Mat2<T>

Converts to this type from the input type.
Source§

impl<T> From<Mat2<T>> for Mat2<T>

Source§

fn from(m: Mat2<T>) -> Mat2<T>

Converts to this type from the input type.
Source§

impl<T> From<Mat2<T>> for Mat3<T>
where T: Zero + One,

Source§

fn from(m: Mat2<T>) -> Mat3<T>

Converts to this type from the input type.
Source§

impl<T> From<Mat2<T>> for Mat4<T>
where T: Zero + One,

Source§

fn from(m: Mat2<T>) -> Mat4<T>

Converts to this type from the input type.
Source§

impl<T> From<Mat3<T>> for Mat2<T>

Source§

fn from(m: Mat3<T>) -> Mat2<T>

Converts to this type from the input type.
Source§

impl<T> From<Mat4<T>> for Mat2<T>

Source§

fn from(m: Mat4<T>) -> Mat2<T>

Converts to this type from the input type.
Source§

impl<T> Hash for Mat2<T>
where T: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

Index this matrix in a layout-agnostic way with an (i, j) (row index, column index) tuple.

Matrices cannot be indexed by Vec2s because that would be likely to cause confusion: should x be the row index (because it’s the first element) or the column index (because it’s a horizontal position) ?

Source§

type Output = T

The returned type after indexing.
Source§

fn index( &self, t: (usize, usize), ) -> &<Mat2<T> as Index<(usize, usize)>>::Output

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

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

Source§

fn index_mut( &mut self, t: (usize, usize), ) -> &mut <Mat2<T> as Index<(usize, usize)>>::Output

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

impl<T> Mul<CubicBezier2<T>> for Mat2<T>
where T: Real + MulAdd<Output = T>,

Source§

type Output = CubicBezier2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<Mat2<T>> for Mat2<T>
where T: Mul<Output = T> + MulAdd<Output = T> + Copy,

Multiplies a column-major matrix with a row-major matrix.

use vek::mat::row_major::Mat4 as Rows4;
use vek::mat::column_major::Mat4 as Cols4;

let m = Cols4::<u32>::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let b = Rows4::from(m);
let r = Rows4::<u32>::new(
    26, 32, 18, 24,
    82, 104, 66, 88,
    38, 56, 74, 92,
    54, 68, 42, 56
);
assert_eq!(m * b, r);
assert_eq!(m * Rows4::<u32>::identity(), m.into());
assert_eq!(Cols4::<u32>::identity() * b, m.into());
Source§

type Output = Mat2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat2<T>) -> <Mat2<T> as Mul<Mat2<T>>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul<Mat2<T>> for Mat2<T>
where T: Mul<Output = T> + MulAdd<Output = T> + Copy,

Multiplies a row-major matrix with a column-major matrix, producing a column-major matrix.

use vek::mat::row_major::Mat4 as Rows4;
use vek::mat::column_major::Mat4 as Cols4;

let m = Rows4::<u32>::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let b = Cols4::from(m);
let r = Cols4::<u32>::new(
    26, 32, 18, 24,
    82, 104, 66, 88,
    38, 56, 74, 92,
    54, 68, 42, 56
);
assert_eq!(m * b, r);
assert_eq!(m * Cols4::<u32>::identity(), m.into());
assert_eq!(Rows4::<u32>::identity() * b, m.into());
Source§

type Output = Mat2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat2<T>) -> <Mat2<T> as Mul<Mat2<T>>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul<Mat2<T>> for Vec2<T>
where T: Mul<Output = T> + MulAdd<Output = T> + Copy,

Multiplies a row vector with a column-major matrix, giving a row vector.

use vek::mat::column_major::Mat4;
use vek::vec::Vec4;

let m = Mat4::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(26, 32, 18, 24);
assert_eq!(v * m, r);
Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat2<T>) -> <Vec2<T> as Mul<Mat2<T>>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul<QuadraticBezier2<T>> for Mat2<T>
where T: Real + MulAdd<Output = T>,

Source§

type Output = QuadraticBezier2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<T> for Mat2<T>
where T: Zero<Output = T> + Add + Mul<Output = T> + Copy,

Source§

type Output = Mat2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> <Mat2<T> as Mul<T>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul<Vec2<T>> for Mat2<T>
where T: Mul<Output = T> + MulAdd<Output = T> + Copy,

Multiplies a column-major matrix with a column vector, giving a column vector.

With SIMD vectors, this is the most efficient way.

use vek::mat::column_major::Mat4;
use vek::vec::Vec4;

let m = Mat4::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(14, 38, 12, 26);
assert_eq!(m * v, r);
Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, v: Vec2<T>) -> <Mat2<T> as Mul<Vec2<T>>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul for Mat2<T>
where T: Mul<Output = T> + MulAdd<Output = T> + Copy,

Multiplies a column-major matrix with another.

use vek::mat::column_major::Mat4;

let m = Mat4::<u32>::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let r = Mat4::<u32>::new(
    26, 32, 18, 24,
    82, 104, 66, 88,
    38, 56, 74, 92,
    54, 68, 42, 56
);
assert_eq!(m * m, r);
assert_eq!(m, m * Mat4::<u32>::identity());
assert_eq!(m, Mat4::<u32>::identity() * m);
Source§

type Output = Mat2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat2<T>) -> <Mat2<T> as Mul>::Output

Performs the * operation. Read more
Source§

impl<T> MulAdd for Mat2<T>
where T: MulAdd<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the fused multiply-add.
Source§

fn mul_add(self, a: Mat2<T>, b: Mat2<T>) -> <Mat2<T> as MulAdd>::Output

Performs the fused multiply-add operation (self * a) + b
Source§

impl<T> MulAddAssign for Mat2<T>
where T: MulAddAssign,

Source§

fn mul_add_assign(&mut self, a: Mat2<T>, b: Mat2<T>)

Performs the fused multiply-add assignment operation *self = (*self * a) + b
Source§

impl<T> MulAssign<T> for Mat2<T>
where T: Zero<Output = T> + Add + Mul<Output = T> + Copy,

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T> MulAssign for Mat2<T>
where T: Add<Output = T> + Mul<Output = T> + Copy + MulAdd<Output = T> + Zero,

Source§

fn mul_assign(&mut self, rhs: Mat2<T>)

Performs the *= operation. Read more
Source§

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

Source§

type Output = Mat2<T>

The resulting type after applying the - operator.
Source§

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

Performs the unary - operation. Read more
Source§

impl<T> One for Mat2<T>
where T: Zero + One + Copy + MulAdd<Output = T>,

Source§

fn one() -> Mat2<T>

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<T> PartialEq for Mat2<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Mat2<T>) -> 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 Mat2<T>
where T: RelativeEq, <T as AbsDiffEq>::Epsilon: Copy,

Source§

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

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

fn relative_eq( &self, other: &Mat2<T>, epsilon: <T as AbsDiffEq>::Epsilon, max_relative: <T 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.
Source§

impl<T> Rem<T> for Mat2<T>
where T: Copy + Rem<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: T) -> <Mat2<T> as Rem<T>>::Output

Performs the % operation. Read more
Source§

impl<T> Rem for Mat2<T>
where T: Rem<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Mat2<T>) -> <Mat2<T> as Rem>::Output

Performs the % operation. Read more
Source§

impl<T> RemAssign<T> for Mat2<T>
where T: Rem<Output = T> + Copy,

Source§

fn rem_assign(&mut self, rhs: T)

Performs the %= operation. Read more
Source§

impl<T> RemAssign for Mat2<T>
where T: Rem<Output = T> + Copy,

Source§

fn rem_assign(&mut self, rhs: Mat2<T>)

Performs the %= operation. Read more
Source§

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

Source§

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

impl<T> Sub<T> for Mat2<T>
where T: Copy + Sub<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> <Mat2<T> as Sub<T>>::Output

Performs the - operation. Read more
Source§

impl<T> Sub for Mat2<T>
where T: Sub<Output = T>,

Source§

type Output = Mat2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Mat2<T>) -> <Mat2<T> as Sub>::Output

Performs the - operation. Read more
Source§

impl<T> SubAssign<T> for Mat2<T>
where T: Sub<Output = T> + Copy,

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

impl<T> SubAssign for Mat2<T>
where T: Sub<Output = T> + Copy,

Source§

fn sub_assign(&mut self, rhs: Mat2<T>)

Performs the -= operation. Read more
Source§

impl<T> Sum for Mat2<T>
where T: Add<Output = T> + Zero,

Source§

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

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

impl<T> UlpsEq for Mat2<T>
where T: UlpsEq, <T as AbsDiffEq>::Epsilon: Copy,

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: &Mat2<T>, epsilon: <T 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.
Source§

impl<T> Zero for Mat2<T>
where T: Zero + PartialEq,

Source§

fn zero() -> Mat2<T>

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<T> Copy for Mat2<T>
where T: Copy,

Source§

impl<T> Eq for Mat2<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for Mat2<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for Mat2<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Mat2<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> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. 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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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