Struct Transform2

Source
#[repr(C)]
pub struct Transform2<T> { pub a11: T, pub a12: T, pub a13: T, pub a21: T, pub a22: T, pub a23: T, }
Expand description

2D affine transformation matrix.

Each field aij represents the i-th row and j-th column of the matrix.

The third row is implied to be [0, 0, 1] and is omitted.

Fields§

§a11: T§a12: T§a13: T§a21: T§a22: T§a23: T

Implementations§

Source§

impl<T> Transform2<T>

Source

pub const fn new( a11: T, a12: T, a13: T, a21: T, a22: T, a23: T, ) -> Transform2<T>

Constructs a new matrix from components.

Source§

impl<T: Zero> Transform2<T>

Source

pub const ZERO: Transform2<T>

Zero matrix.

Source§

impl<T: Zero + One> Transform2<T>

Source

pub const IDENTITY: Transform2<T>

Identity matrix.

Source§

impl<T: Scalar> Transform2<T>

Source

pub fn translate(trans: impl Into<Vec2<T>>) -> Transform2<T>

Translation matrix.

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

pub fn scale(scale: impl Into<Vec2<T>>) -> Transform2<T>

Scaling matrix.

Scales around the origin.

Source

pub fn rotate(angle: impl Angle<T = T>) -> Transform2<T>

Rotation matrix.

Rotates around the origin.

Source

pub fn skew(skew: impl Into<Vec2<T>>) -> Transform2<T>

Skewing matrix.

Source

pub fn reflect(line: impl Into<Vec2<T>>) -> Transform2<T>

Reflection matrix.

Reflects around the given axis. If axis is the zero vector, returns a point reflection around the origin.

Source

pub fn project(line: impl Into<Vec2<T>>) -> Transform2<T>

Projection matrix.

Projects onto the given axis. If axis is the zero vector, returns the zero matrix.

Source

pub fn remap(from: Bounds2<T>, to: Bounds2<T>) -> Transform2<T>

Remap matrix.

Source§

impl<T: Zero + One> Transform2<T>

Source

pub fn mat3(self) -> Mat3<T>

Converts to a 3x3 matrix.

Source§

impl<T> Transform2<T>

Source

pub fn from_row_major(mat: [[T; 3]; 2]) -> Transform2<T>

Imports the matrix from a row-major layout.

Source

pub fn from_column_major(mat: [[T; 2]; 3]) -> Transform2<T>

Imports the matrix from a column-major layout.

Source

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

Exports the matrix as a row-major array.

Source

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

Exports the matrix as a column-major array.

Source§

impl<T> Transform2<T>

Source

pub fn compose(x: Vec2<T>, y: Vec2<T>, t: Vec2<T>) -> Transform2<T>

Composes the matrix from basis vectors.

Source

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

Gets the transformed X basis vector.

Source

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

Gets the transformed Y basis vector.

Source

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

Gets the translation vector.

Source

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

Gets the rotation matrix.

Source§

impl<T: Scalar> Transform2<T>

Source

pub fn determinant(self) -> T

Computes the determinant.

Source

pub fn trace(self) -> T

Computes the trace.

Source

pub fn inverse(self) -> Transform2<T>

Computes the inverse matrix.

Trait Implementations§

Source§

impl<T: Clone> Clone for Transform2<T>

Source§

fn clone(&self) -> Transform2<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 Transform2<T>

Source§

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

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

impl<T: Default> Default for Transform2<T>

Source§

fn default() -> Transform2<T>

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

impl<T: Zero + One> From<Transform2<T>> for Mat3<T>

Source§

fn from(mat: Transform2<T>) -> Mat3<T>

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Transform2<T>

Source§

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

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: Copy + Add<Output = T> + Mul<Output = T>> Mul<Mat2<T>> for Transform2<T>

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Transform2<T>> for Mat2<T>

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Transform2<T>> for Mat3<T>

Source§

type Output = Mat3<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Vec2<T>> for Transform2<T>

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Vec3<T>> for Transform2<T>

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul for Transform2<T>

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Mat2<T>> for Transform2<T>

Source§

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

Performs the *= operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Transform2<T>> for Mat3<T>

Source§

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

Performs the *= operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign for Transform2<T>

Source§

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

Performs the *= operation. Read more
Source§

impl<T: PartialEq> PartialEq for Transform2<T>

Source§

fn eq(&self, other: &Transform2<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: Copy> Copy for Transform2<T>

Source§

impl<T: Eq> Eq for Transform2<T>

Source§

impl<T> StructuralPartialEq for Transform2<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Transform2<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.