Struct glamour::Transform2

source ·
#[repr(transparent)]
pub struct Transform2<Src: Unit, Dst: Unit> { pub matrix: Matrix3<Src::Scalar>, /* private fields */ }
Expand description

2D transform represented as a 3x3 column-major matrix.

This is a strongly typed wrapper around a Matrix3, where that matrix describes how to map between units.

Fields§

§matrix: Matrix3<Src::Scalar>

Underlying matrix.

Implementations§

source§

impl<Src, Dst> Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

source

pub const IDENTITY: Self = _

Identity matrix.

source

pub const fn from_matrix_unchecked(matrix: Matrix3<Src::Scalar>) -> Self

Create from matrix.

source

pub fn from_matrix(matrix: Matrix3<Src::Scalar>) -> Option<Self>

Create from matrix, checking if the matrix is invertible.

source

pub fn from_angle(angle: Angle<Src::Scalar>) -> Self

Create rotation transform.

§Example
struct A;
impl Unit for A { type Scalar = f64; }
struct B;
impl Unit for B { type Scalar = f64; }

type Transform = Transform2<A, B>;

let translate = Transform::from_angle(Angle::FRAG_PI_2);
let a: Vector2<A> = Vector2 { x: 10.0, y: 20.0 };
let b: Vector2<B> = translate.map(a);
assert_abs_diff_eq!(b, vec2!(-20.0, 10.0), epsilon = 0.000001);
source

pub fn from_scale(scale: Vector2<Src>) -> Self

Create scaling transform.

§Example
struct A;
impl Unit for A { type Scalar = f32; }
struct B;
impl Unit for B { type Scalar = f32; }

type Transform = Transform2<A, B>;

let translate = Transform::from_scale(Vector2 { x: 2.0, y: 3.0 });
let a: Vector2<A> = Vector2 { x: 10.0, y: 20.0 };
let b: Vector2<B> = translate.map(a);
assert_abs_diff_eq!(b, vec2!(20.0, 60.0));
source

pub fn from_translation(translation: Vector2<Src>) -> Self

Create translation transform.

§Example
struct A;
impl Unit for A { type Scalar = f32; }
struct B;
impl Unit for B { type Scalar = f32; }

type Transform = Transform2<A, B>;

let translate = Transform::from_translation(Vector2 { x: 10.0, y: 20.0 });
let a: Point2<A> = Point2 { x: 1.0, y: 2.0 };
let b: Point2<B> = translate.map(a);
assert_abs_diff_eq!(b, point!(11.0, 22.0));
source

pub fn from_scale_angle_translation( scale: Vector2<Src>, angle: Angle<Src::Scalar>, translation: Vector2<Src> ) -> Self

Create scaling, rotation, and translation matrix.

§Example

type Transform = Transform2<f32, f32>;

let a = Transform::from_scale_angle_translation(
    (2.0, 3.0).into(),
    Angle::from_degrees(90.0),
    (10.0, 20.0).into(),
);

let b = Transform::from_scale((2.0, 3.0).into())
    .then_rotate(Angle::from_degrees(90.0))
    .then_translate((10.0, 20.0).into());

assert_abs_diff_eq!(a, b);
source§

impl<Src, Dst> Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

source

pub fn then<Dst2>(self, other: Transform2<Dst, Dst2>) -> Transform2<Src, Dst2>
where Dst2: Unit<Scalar = Dst::Scalar>,

Perform matrix multiplication such that other’s transformation applies after self.

This may change the target coordinate space - that is, the resulting transform takes points and vectors from Src to Dst2.

This operation is equivalent to other.matrix * self.matrix - that is, the multiplication order is the reverse of the order of the effects of the transformation.

source

pub fn then_rotate(self, angle: Angle<Src::Scalar>) -> Self

Shorthand for .then(Transform2::from_angle(angle)).

This does not change the target coordinate space.

source

pub fn then_scale(self, scale: Vector2<Dst>) -> Self

Shorthand for .then(Transform2::from_scale(scale)).

This does not change the target coordinate space.

§Example
let a = Transform2::<f32, f32>::IDENTITY
    .then_scale((2.0, 3.0).into());
let b = Transform2::<f32, f32>::from_scale((2.0, 3.0).into());
assert_eq!(a, b);
source

pub fn then_translate(self, translation: Vector2<Dst>) -> Self

Shorthand for .then(Transform2::from_scale(scale)).

This does not change the target coordinate space.

source

pub fn inverse(&self) -> Transform2<Dst, Src>

Invert the matrix.

See glam::Mat3::inverse() and glam::DMat3::inverse().

Trait Implementations§

source§

impl<Src, Dst> AbsDiffEq for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

§

type Epsilon = <Matrix3<<Src as Unit>::Scalar> as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

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

fn abs_diff_eq(&self, other: &Self, epsilon: Self::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<Src: Unit, Dst: Unit> Clone for Transform2<Src, Dst>

source§

fn clone(&self) -> Self

Returns a copy 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<Src, Dst> Debug for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit,

source§

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

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

impl<Src, Dst> Default for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit,

source§

fn default() -> Self

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

impl<Src, Dst, Dst2> Mul<Transform2<Dst, Dst2>> for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>, Dst2: Unit<Scalar = Src::Scalar>,

§

type Output = Transform2<Src, Dst2>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Transform2<Dst, Dst2>) -> Self::Output

Performs the * operation. Read more
source§

impl<Src, Dst> PartialEq for Transform2<Src, Dst>
where Src: Unit, Dst: Unit,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Src, Dst> RelativeEq for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

source§

fn default_max_relative() -> Self::Epsilon

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

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::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<Src, Dst> TransformMap<Point2<Src>> for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

§

type Output = Point2<Dst>

Result type of the transformation.
source§

fn map(&self, value: Point2<Src>) -> Self::Output

Map T to Self::Output.
source§

impl<Src, Dst> TransformMap<Vector2<Src>> for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

§

type Output = Vector2<Dst>

Result type of the transformation.
source§

fn map(&self, value: Vector2<Src>) -> Self::Output

Map T to Self::Output.
source§

impl<Src: Unit, Dst: Unit> TransparentWrapper<Matrix3<<Src as Unit>::Scalar>> for Transform2<Src, Dst>

source§

fn wrap(s: Inner) -> Self
where Self: Sized,

Convert the inner type into the wrapper type.
source§

fn wrap_ref(s: &Inner) -> &Self

Convert a reference to the inner type into a reference to the wrapper type.
source§

fn wrap_mut(s: &mut Inner) -> &mut Self

Convert a mutable reference to the inner type into a mutable reference to the wrapper type.
source§

fn wrap_slice(s: &[Inner]) -> &[Self]
where Self: Sized,

Convert a slice to the inner type into a slice to the wrapper type.
source§

fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]
where Self: Sized,

Convert a mutable slice to the inner type into a mutable slice to the wrapper type.
source§

fn peel(s: Self) -> Inner
where Self: Sized,

Convert the wrapper type into the inner type.
source§

fn peel_ref(s: &Self) -> &Inner

Convert a reference to the wrapper type into a reference to the inner type.
source§

fn peel_mut(s: &mut Self) -> &mut Inner

Convert a mutable reference to the wrapper type into a mutable reference to the inner type.
source§

fn peel_slice(s: &[Self]) -> &[Inner]
where Self: Sized,

Convert a slice to the wrapped type into a slice to the inner type.
source§

fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]
where Self: Sized,

Convert a mutable slice to the wrapped type into a mutable slice to the inner type.
source§

impl<Src, Dst> UlpsEq for Transform2<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

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: &Self, epsilon: Self::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<Src: Unit, Dst: Unit> Zeroable for Transform2<Src, Dst>

source§

fn zeroed() -> Self

source§

impl<Src: Unit, Dst: Unit> Copy for Transform2<Src, Dst>

source§

impl<Src: Unit, Dst: Unit> Pod for Transform2<Src, Dst>

Auto Trait Implementations§

§

impl<Src, Dst> Freeze for Transform2<Src, Dst>
where <Src as Unit>::Scalar: Freeze,

§

impl<Src, Dst> RefUnwindSafe for Transform2<Src, Dst>
where Dst: RefUnwindSafe, <Src as Unit>::Scalar: RefUnwindSafe,

§

impl<Src, Dst> Send for Transform2<Src, Dst>
where Dst: Send,

§

impl<Src, Dst> Sync for Transform2<Src, Dst>
where Dst: Sync,

§

impl<Src, Dst> Unpin for Transform2<Src, Dst>
where Dst: Unpin, <Src as Unit>::Scalar: Unpin,

§

impl<Src, Dst> UnwindSafe for Transform2<Src, Dst>
where Dst: UnwindSafe, <Src as Unit>::Scalar: 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> CheckedBitPattern for T
where T: AnyBitPattern,

§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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,

§

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>,

§

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>,

§

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> AnyBitPattern for T
where T: Pod,

source§

impl<T> NoUninit for T
where T: Pod,

source§

impl<T> PodValue for T
where T: Copy + Debug + Default + PartialEq + Pod + Send + Sync + Serializable + 'static,

source§

impl<T> Serializable for T