#[repr(C)]pub struct Mat2<T> {
pub a11: T,
pub a12: T,
pub a21: T,
pub a22: T,
}
Expand description
2D transformation matrix.
Each field aij represents the i-th row and j-th column of the matrix.
Fields§
§a11: T
§a12: T
§a21: T
§a22: T
Implementations§
Source§impl<T: Scalar> Mat2<T>
impl<T: Scalar> Mat2<T>
Sourcepub fn scale(scale: impl Into<Vec2<T>>) -> Mat2<T>
pub fn scale(scale: impl Into<Vec2<T>>) -> Mat2<T>
Scaling matrix.
Scales around the origin.
Examples found in repository?
examples/svgdoc.rs (line 232)
222fn reflect_2d() -> String {
223 // Calculate data
224 let v = Vec2 { x: 10.0, y: 2.5 };
225 let this = Vec2 { x: 4.0, y: 4.0 };
226 let p = this.project(v);
227 let pv = p - this;
228 let result = p + pv;
229 let origin = Vec2::ZERO;
230
231 // Visualize data
232 let transform = Transform2::translate((40.0f32, 120.0f32)) * Mat2::scale((25.0, -25.0));
233 let this = transform * this;
234 let v = transform * v;
235 let p = transform * p;
236 let pv = transform * pv;
237 let result = transform * result;
238 let origin = transform * origin;
239
240 let mut svg = SvgWriter::new(400, 200);
241 svg.line(this, result).stroke("black").stroke_width(0.5).stroke_dasharray(&[5.0, 5.0]);
242 svg.line(p, pv).stroke("black").stroke_width(0.5).stroke_dasharray(&[5.0, 5.0]);
243 svg.line(pv, result).stroke("black").stroke_width(0.5).stroke_dasharray(&[5.0, 5.0]);
244 svg.arrow(origin, v, ARROW_SIZE).stroke("black");
245 svg.arrow(origin, this, ARROW_SIZE).stroke("black");
246 svg.arrow(origin, result, ARROW_SIZE).stroke("red");
247 svg.circle(p, 2.0).fill("black");
248 svg.text(v, "v").fill("black");
249 svg.text(this, "self").fill("black");
250 svg.text(p + Vec2(8.0, 10.0), "p").fill("black");
251 svg.text(result, "result").fill("red");
252 svg.text(p.lerp(pv, 0.9) + Vec2(-15.0, -5.0), "-self").fill("black");
253 svg.text(pv.lerp(result, 0.8) + Vec2(0.0, 15.0), "+p").fill("black");
254 svg.close()
255}
Source§impl<T> Mat2<T>
impl<T> Mat2<T>
Sourcepub fn affine(self) -> Transform2<T>where
T: Zero,
pub fn affine(self) -> Transform2<T>where
T: Zero,
Converts to a Transform2 matrix.
Sourcepub fn translate(self, trans: impl Into<Vec2<T>>) -> Transform2<T>
pub fn translate(self, trans: impl Into<Vec2<T>>) -> Transform2<T>
Adds a translation to the matrix.
Source§impl<T> Mat2<T>
impl<T> Mat2<T>
Sourcepub fn from_row_major(mat: [[T; 2]; 2]) -> Mat2<T>
pub fn from_row_major(mat: [[T; 2]; 2]) -> Mat2<T>
Imports the matrix from a row-major layout.
Sourcepub fn from_column_major(mat: [[T; 2]; 2]) -> Mat2<T>
pub fn from_column_major(mat: [[T; 2]; 2]) -> Mat2<T>
Imports the matrix from a column-major layout.
Sourcepub fn into_row_major(self) -> [[T; 2]; 2]
pub fn into_row_major(self) -> [[T; 2]; 2]
Exports the matrix as a row-major array.
Sourcepub fn into_column_major(self) -> [[T; 2]; 2]
pub fn into_column_major(self) -> [[T; 2]; 2]
Exports the matrix as a column-major array.
Source§impl<T: Scalar> Mat2<T>
impl<T: Scalar> Mat2<T>
Sourcepub fn determinant(self) -> T
pub fn determinant(self) -> T
Computes the determinant.
Trait Implementations§
Source§impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Mat2<T>> for Transform2<T>
impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Mat2<T>> for Transform2<T>
Source§type Output = Transform2<T>
type Output = Transform2<T>
The resulting type after applying the
*
operator.Source§impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Transform2<T>> for Mat2<T>
impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Transform2<T>> for Mat2<T>
Source§type Output = Transform2<T>
type Output = Transform2<T>
The resulting type after applying the
*
operator.Source§fn mul(self, rhs: Transform2<T>) -> Transform2<T>
fn mul(self, rhs: Transform2<T>) -> Transform2<T>
Performs the
*
operation. Read moreSource§impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Mat2<T>> for Transform2<T>
impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Mat2<T>> for Transform2<T>
Source§fn mul_assign(&mut self, rhs: Mat2<T>)
fn mul_assign(&mut self, rhs: Mat2<T>)
Performs the
*=
operation. Read moreSource§impl<T: Copy + MulAssign> MulAssign<T> for Mat2<T>
impl<T: Copy + MulAssign> MulAssign<T> for Mat2<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the
*=
operation. Read moreSource§impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign for Mat2<T>
impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign for Mat2<T>
Source§fn mul_assign(&mut self, rhs: Mat2<T>)
fn mul_assign(&mut self, rhs: Mat2<T>)
Performs the
*=
operation. Read moreimpl<T: Copy> Copy for Mat2<T>
impl<T: Eq> Eq for Mat2<T>
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> UnwindSafe for Mat2<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more