pub struct Matrix2<T> {
pub x_: Vector2<T>,
pub y_: Vector2<T>,
}Expand description
The code defines a generic struct called Matrix2 with two fields, x_ and y_, which are both of type Vector2.
Properties:
x_: Thex_property represents the first row of theMatrix2object. It is of typeVector2<T>, whereTis a generic type parameter. This means that the elements of the first row are stored in aVector2object.y_: They_property is a public field of typeVector2<T>. It represents the second row of theMatrix2object.
Fields§
§x_: Vector2<T>The first row of the Matrix2 object
y_: Vector2<T>The second row of the Matrix2 object
Implementations§
Source§impl<T> Matrix2<T>
impl<T> Matrix2<T>
Sourcepub const fn new(x_: Vector2<T>, y_: Vector2<T>) -> Self
pub const fn new(x_: Vector2<T>, y_: Vector2<T>) -> Self
Creates a new Matrix2<T>.
The new function creates a new Matrix2 object with the given Vector2 objects.
Arguments:
x_: A vector representing the first row of the matrix.y_: The parametery_is aVector2<T>object representing the second row of the matrix.
Returns:
The new function returns a Matrix2<T> object.
§Examples
use ginger::matrix2::Matrix2;
use ginger::vector2::Vector2;
let x = Vector2::new(3, 4);
let y = Vector2::new(5, 6);
assert_eq!(Matrix2::new(x, y), Matrix2 { x_: x, y_: y });Source§impl<T: Clone + Num> Matrix2<T>
impl<T: Clone + Num> Matrix2<T>
Sourcepub fn det(&self) -> T
pub fn det(&self) -> T
Calculate the determinant of this Matrix2<T>.
The det function calculates the determinant of a 2x2 matrix.
Returns:
The det() function returns the determinant of the Matrix2<T>.
§Examples
use ginger::matrix2::Matrix2;
use ginger::vector2::Vector2;
let x = Vector2::new(3, 4);
let y = Vector2::new(5, 6);
let matrix2 = Matrix2::new(x, y);
assert_eq!(matrix2.det(), -2);Sourcepub fn mdot(&self, v: &Vector2<T>) -> Vector2<T>
pub fn mdot(&self, v: &Vector2<T>) -> Vector2<T>
Matrix-vector multiplication
The mdot function performs matrix-vector multiplication.
Arguments:
v: The parametervis a reference to aVector2<T>object, whereTis the type of the elements in the vector.
Returns:
The mdot function returns a Vector2<T> object.
§Examples
use ginger::matrix2::Matrix2;
use ginger::vector2::Vector2;
let x = Vector2::new(3, 4);
let y = Vector2::new(5, 6);
let v = &Vector2::new(1, 1);
let matrix2 = Matrix2::new(x, y);
assert_eq!(matrix2.mdot(v), Vector2::new(7, 11));Sourcepub fn scale(&self, alpha: T) -> Self
pub fn scale(&self, alpha: T) -> Self
The scale function multiplies a matrix by a scalar.
Arguments:
alpha: The parameteralpharepresents the scalar value by which the matrix is multiplied.
Returns:
The scale method returns a new Matrix2 object.
§Examples
use ginger::matrix2::Matrix2;
use ginger::vector2::Vector2;
let x = Vector2::new(3, 4);
let y = Vector2::new(5, 6);
let matrix2 = Matrix2::new(x, y);
assert_eq!(matrix2.scale(10), Matrix2 { x_: Vector2::new(30, 40), y_: Vector2::new(50, 60)});Sourcepub fn unscale(&self, alpha: T) -> Self
pub fn unscale(&self, alpha: T) -> Self
The unscale function divides each element of a matrix by a scalar value.
Arguments:
alpha: The parameteralphais a scalar value that is used to divide each element of the matrix by. It is used to scale down the matrix by dividing each element byalpha.
Returns:
The unscale method returns a new instance of Matrix2 with the elements of self divided by the
scalar alpha.
§Examples
use ginger::matrix2::Matrix2;
use ginger::vector2::Vector2;
let x = Vector2::new(30, 40);
let y = Vector2::new(50, 60);
let matrix2 = Matrix2::new(x, y);
assert_eq!(matrix2.unscale(10), Matrix2 { x_: Vector2::new(3, 4), y_: Vector2::new(5, 6)});Trait Implementations§
Source§impl<'a, T: Clone + NumAssign> AddAssign<&'a Matrix2<T>> for Matrix2<T>
impl<'a, T: Clone + NumAssign> AddAssign<&'a Matrix2<T>> for Matrix2<T>
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
+= operation. Read moreSource§impl<T: Clone + NumAssign> AddAssign for Matrix2<T>
impl<T: Clone + NumAssign> AddAssign for Matrix2<T>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl<'a, T: Clone + NumAssign> DivAssign<&'a T> for Matrix2<T>
impl<'a, T: Clone + NumAssign> DivAssign<&'a T> for Matrix2<T>
Source§fn div_assign(&mut self, other: &T)
fn div_assign(&mut self, other: &T)
/= operation. Read moreSource§impl<T: Clone + NumAssign> DivAssign<T> for Matrix2<T>
impl<T: Clone + NumAssign> DivAssign<T> for Matrix2<T>
Source§fn div_assign(&mut self, other: T)
fn div_assign(&mut self, other: T)
/= operation. Read moreSource§impl<'a, T: Clone + NumAssign> MulAssign<&'a T> for Matrix2<T>
impl<'a, T: Clone + NumAssign> MulAssign<&'a T> for Matrix2<T>
Source§fn mul_assign(&mut self, other: &T)
fn mul_assign(&mut self, other: &T)
*= operation. Read moreSource§impl<T: Clone + NumAssign> MulAssign<T> for Matrix2<T>
impl<T: Clone + NumAssign> MulAssign<T> for Matrix2<T>
Source§fn mul_assign(&mut self, other: T)
fn mul_assign(&mut self, other: T)
*= operation. Read moreSource§impl<'a, T: Clone + NumAssign> SubAssign<&'a Matrix2<T>> for Matrix2<T>
impl<'a, T: Clone + NumAssign> SubAssign<&'a Matrix2<T>> for Matrix2<T>
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
-= operation. Read moreSource§impl<T: Clone + NumAssign> SubAssign for Matrix2<T>
impl<T: Clone + NumAssign> SubAssign for Matrix2<T>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read more