pub struct Affine { /* private fields */ }
Expand description
Affine transformations: move/scale/rotate
Note that the current representation is limited to transformations which preserve the angle: it cannot represent reflection or shear transformations.
An Affine
transform a
may be applied to a DVec2
coordinate v
via
multiplication: a * v
. This is equivalent to a.alpha() * v + a.delta()
.
Two transforms a
, b
may be combined via multiplication: a * b
. Note
that this is associative but not commutative:
b * (a * v) == (b * a) * v
but a * b != b * a
in general.
Implementations§
Source§impl Affine
impl Affine
Sourcepub fn from_vectors(x0: DVec2, x1: DVec2, y0: DVec2, y1: DVec2) -> Self
pub fn from_vectors(x0: DVec2, x1: DVec2, y0: DVec2, y1: DVec2) -> Self
Construct a scaling and rotation transform taking x0
to x1
and y0
to y1
This may be used to construct from two-finger touch motions. In this
case, x0 = old.finger1
, x1 = new.finger1
, y0 = old.finger2
and
y1 = new.finger2
.
Sourcepub fn pan(
x0: DVec2,
x1: DVec2,
y0: DVec2,
y1: DVec2,
(scale, rotate): (bool, bool),
) -> Self
pub fn pan( x0: DVec2, x1: DVec2, y0: DVec2, y1: DVec2, (scale, rotate): (bool, bool), ) -> Self
Construct from two vectors with optional scaling and rotation
This is a multiplexer over Self::from_vectors
and other methods,
making scaling and rotation optional (though unless both are true,
the transform won’t map x0
to x1
and y0
to y1
).
Sourcepub fn alpha(self) -> Linear
pub fn alpha(self) -> Linear
Get component alpha
This represents scaling and rotation transformations.
Sourcepub fn delta(self) -> DVec2
pub fn delta(self) -> DVec2
Get component delta
This is the translation, applied after rotation and scaling.
Sourcepub fn has_translation(self) -> bool
pub fn has_translation(self) -> bool
True if the transform translates its input
Sourcepub fn as_translation(self) -> Option<DVec2>
pub fn as_translation(self) -> Option<DVec2>
Get as delta
if self
represents a pure translation
Sourcepub fn as_scale_and_translation(self) -> Option<(f64, DVec2)>
pub fn as_scale_and_translation(self) -> Option<(f64, DVec2)>
Get as (scale, delta)
if self
represents a scaling and translation
Trait Implementations§
Source§impl AddAssign<DVec2> for Affine
impl AddAssign<DVec2> for Affine
Source§fn add_assign(&mut self, rhs: DVec2)
fn add_assign(&mut self, rhs: DVec2)
+=
operation. Read moreSource§impl DivAssign<Linear> for Affine
impl DivAssign<Linear> for Affine
Source§fn div_assign(&mut self, rhs: Linear)
fn div_assign(&mut self, rhs: Linear)
/=
operation. Read moreSource§impl MulAssign<Linear> for Affine
impl MulAssign<Linear> for Affine
Source§fn mul_assign(&mut self, rhs: Linear)
fn mul_assign(&mut self, rhs: Linear)
*=
operation. Read moreSource§impl SubAssign<DVec2> for Affine
impl SubAssign<DVec2> for Affine
Source§fn sub_assign(&mut self, rhs: DVec2)
fn sub_assign(&mut self, rhs: DVec2)
-=
operation. Read moreimpl Copy for Affine
impl StructuralPartialEq for Affine
Auto Trait Implementations§
impl Freeze for Affine
impl RefUnwindSafe for Affine
impl Send for Affine
impl Sync for Affine
impl Unpin for Affine
impl UnwindSafe for Affine
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more