#[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>
impl<T> Transform2<T>
Sourcepub const fn new(
a11: T,
a12: T,
a13: T,
a21: T,
a22: T,
a23: T,
) -> Transform2<T>
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>
impl<T: Zero> Transform2<T>
Sourcepub const ZERO: Transform2<T>
pub const ZERO: Transform2<T>
Zero matrix.
Source§impl<T: Zero + One> Transform2<T>
impl<T: Zero + One> Transform2<T>
Sourcepub const IDENTITY: Transform2<T>
pub const IDENTITY: Transform2<T>
Identity matrix.
Source§impl<T: Scalar> Transform2<T>
impl<T: Scalar> Transform2<T>
Sourcepub fn translate(trans: impl Into<Vec2<T>>) -> Transform2<T>
pub fn translate(trans: impl Into<Vec2<T>>) -> Transform2<T>
Translation matrix.
Examples found in repository?
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}
Sourcepub fn scale(scale: impl Into<Vec2<T>>) -> Transform2<T>
pub fn scale(scale: impl Into<Vec2<T>>) -> Transform2<T>
Scaling matrix.
Scales around the origin.
Sourcepub fn rotate(angle: impl Angle<T = T>) -> Transform2<T>
pub fn rotate(angle: impl Angle<T = T>) -> Transform2<T>
Rotation matrix.
Rotates around the origin.
Sourcepub fn skew(skew: impl Into<Vec2<T>>) -> Transform2<T>
pub fn skew(skew: impl Into<Vec2<T>>) -> Transform2<T>
Skewing matrix.
Sourcepub fn reflect(line: impl Into<Vec2<T>>) -> Transform2<T>
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.
Sourcepub fn project(line: impl Into<Vec2<T>>) -> Transform2<T>
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.
Sourcepub fn remap(from: Bounds2<T>, to: Bounds2<T>) -> Transform2<T>
pub fn remap(from: Bounds2<T>, to: Bounds2<T>) -> Transform2<T>
Remap matrix.
Source§impl<T> Transform2<T>
impl<T> Transform2<T>
Sourcepub fn from_row_major(mat: [[T; 3]; 2]) -> Transform2<T>
pub fn from_row_major(mat: [[T; 3]; 2]) -> Transform2<T>
Imports the matrix from a row-major layout.
Sourcepub fn from_column_major(mat: [[T; 2]; 3]) -> Transform2<T>
pub fn from_column_major(mat: [[T; 2]; 3]) -> Transform2<T>
Imports the matrix from a column-major layout.
Sourcepub fn into_row_major(self) -> [[T; 3]; 2]
pub fn into_row_major(self) -> [[T; 3]; 2]
Exports the matrix as a row-major array.
Sourcepub fn into_column_major(self) -> [[T; 2]; 3]
pub fn into_column_major(self) -> [[T; 2]; 3]
Exports the matrix as a column-major array.
Source§impl<T> Transform2<T>
impl<T> Transform2<T>
Source§impl<T: Scalar> Transform2<T>
impl<T: Scalar> Transform2<T>
Sourcepub fn determinant(self) -> T
pub fn determinant(self) -> T
Computes the determinant.
Sourcepub fn inverse(self) -> Transform2<T>
pub fn inverse(self) -> Transform2<T>
Computes the inverse matrix.
Trait Implementations§
Source§impl<T: Clone> Clone for Transform2<T>
impl<T: Clone> Clone for Transform2<T>
Source§fn clone(&self) -> Transform2<T>
fn clone(&self) -> Transform2<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for Transform2<T>
impl<T: Debug> Debug for Transform2<T>
Source§impl<T: Default> Default for Transform2<T>
impl<T: Default> Default for Transform2<T>
Source§fn default() -> Transform2<T>
fn default() -> Transform2<T>
Source§impl<T: Zero + One> From<Transform2<T>> for Mat3<T>
impl<T: Zero + One> From<Transform2<T>> for Mat3<T>
Source§fn from(mat: Transform2<T>) -> Mat3<T>
fn from(mat: Transform2<T>) -> Mat3<T>
Source§impl<T: Hash> Hash for Transform2<T>
impl<T: Hash> Hash for Transform2<T>
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>
*
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>
*
operator.Source§fn mul(self, rhs: Transform2<T>) -> Transform2<T>
fn mul(self, rhs: Transform2<T>) -> Transform2<T>
*
operation. Read moreSource§impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul for Transform2<T>
impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul for Transform2<T>
Source§type Output = Transform2<T>
type Output = Transform2<T>
*
operator.Source§fn mul(self, rhs: Transform2<T>) -> Transform2<T>
fn mul(self, rhs: Transform2<T>) -> Transform2<T>
*
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>)
*=
operation. Read moreSource§impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Transform2<T>> for Mat3<T>
impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Transform2<T>> for Mat3<T>
Source§fn mul_assign(&mut self, rhs: Transform2<T>)
fn mul_assign(&mut self, rhs: Transform2<T>)
*=
operation. Read moreSource§impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign for Transform2<T>
impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign for Transform2<T>
Source§fn mul_assign(&mut self, rhs: Transform2<T>)
fn mul_assign(&mut self, rhs: Transform2<T>)
*=
operation. Read more