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>
impl<Src, Dst> Transform2<Src, Dst>
sourcepub const fn from_matrix_unchecked(matrix: Matrix3<Src::Scalar>) -> Self
pub const fn from_matrix_unchecked(matrix: Matrix3<Src::Scalar>) -> Self
Create from matrix.
sourcepub fn from_matrix(matrix: Matrix3<Src::Scalar>) -> Option<Self>
pub fn from_matrix(matrix: Matrix3<Src::Scalar>) -> Option<Self>
Create from matrix, checking if the matrix is invertible.
sourcepub fn from_angle(angle: Angle<Src::Scalar>) -> Self
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);
sourcepub fn from_scale(scale: Vector2<Src>) -> Self
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));
sourcepub fn from_translation(translation: Vector2<Src>) -> Self
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));
sourcepub fn from_scale_angle_translation(
scale: Vector2<Src>,
angle: Angle<Src::Scalar>,
translation: Vector2<Src>
) -> Self
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>
impl<Src, Dst> Transform2<Src, Dst>
sourcepub fn then<Dst2>(self, other: Transform2<Dst, Dst2>) -> Transform2<Src, Dst2>
pub fn then<Dst2>(self, other: Transform2<Dst, Dst2>) -> Transform2<Src, Dst2>
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.
sourcepub fn then_rotate(self, angle: Angle<Src::Scalar>) -> Self
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.
sourcepub fn then_scale(self, scale: Vector2<Dst>) -> Self
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);
sourcepub fn then_translate(self, translation: Vector2<Dst>) -> Self
pub fn then_translate(self, translation: Vector2<Dst>) -> Self
Shorthand for .then(Transform2::from_scale(scale))
.
This does not change the target coordinate space.
sourcepub fn inverse(&self) -> Transform2<Dst, Src>
pub fn inverse(&self) -> Transform2<Dst, Src>
Invert the matrix.
Trait Implementations§
source§impl<Src, Dst> AbsDiffEq for Transform2<Src, Dst>
impl<Src, Dst> AbsDiffEq for Transform2<Src, Dst>
§type Epsilon = <Matrix3<<Src as Unit>::Scalar> as AbsDiffEq>::Epsilon
type Epsilon = <Matrix3<<Src as Unit>::Scalar> as AbsDiffEq>::Epsilon
source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.source§impl<Src, Dst> Debug for Transform2<Src, Dst>
impl<Src, Dst> Debug for Transform2<Src, Dst>
source§impl<Src, Dst> Default for Transform2<Src, Dst>
impl<Src, Dst> Default for Transform2<Src, Dst>
source§impl<Src, Dst, Dst2> Mul<Transform2<Dst, Dst2>> for Transform2<Src, Dst>
impl<Src, Dst, Dst2> Mul<Transform2<Dst, Dst2>> for Transform2<Src, Dst>
§type Output = Transform2<Src, Dst2>
type Output = Transform2<Src, Dst2>
*
operator.source§impl<Src, Dst> PartialEq for Transform2<Src, Dst>
impl<Src, Dst> PartialEq for Transform2<Src, Dst>
source§impl<Src, Dst> RelativeEq for Transform2<Src, Dst>
impl<Src, Dst> RelativeEq for Transform2<Src, Dst>
source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
RelativeEq::relative_eq
.source§impl<Src, Dst> TransformMap<Point2<Src>> for Transform2<Src, Dst>
impl<Src, Dst> TransformMap<Point2<Src>> for Transform2<Src, Dst>
source§impl<Src, Dst> TransformMap<Vector2<Src>> for Transform2<Src, Dst>
impl<Src, Dst> TransformMap<Vector2<Src>> for Transform2<Src, Dst>
source§impl<Src: Unit, Dst: Unit> TransparentWrapper<Matrix3<<Src as Unit>::Scalar>> for Transform2<Src, Dst>
impl<Src: Unit, Dst: Unit> TransparentWrapper<Matrix3<<Src as Unit>::Scalar>> for Transform2<Src, Dst>
source§fn wrap_ref(s: &Inner) -> &Self
fn wrap_ref(s: &Inner) -> &Self
source§fn wrap_mut(s: &mut Inner) -> &mut Self
fn wrap_mut(s: &mut Inner) -> &mut Self
source§fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
source§fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
source§fn peel_ref(s: &Self) -> &Inner
fn peel_ref(s: &Self) -> &Inner
source§fn peel_mut(s: &mut Self) -> &mut Inner
fn peel_mut(s: &mut Self) -> &mut Inner
source§impl<Src, Dst> UlpsEq for Transform2<Src, Dst>
impl<Src, Dst> UlpsEq for Transform2<Src, Dst>
impl<Src: Unit, Dst: Unit> Copy for Transform2<Src, Dst>
impl<Src: Unit, Dst: Unit> Pod for Transform2<Src, Dst>
Auto Trait Implementations§
impl<Src, Dst> Freeze for Transform2<Src, Dst>
impl<Src, Dst> RefUnwindSafe for Transform2<Src, Dst>
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>
impl<Src, Dst> UnwindSafe for Transform2<Src, Dst>
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
source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.