pub struct Linear(/* private fields */);
Expand description
Linear transformation: scaling and rotation
This represents scaling and rotation transformations (i.e. the linear
mappings on DVec2
in the mathematical sense, excluding skew).
A Linear
transform a
may be applied to a vector v
via multiplication:
a * v
. Multiple transforms can be combined: a * (b * v) == (a * b) * v
.
Linear
transforms are a ring algebra
with commutative operations. Both addition and multiplication operations are associative
and commutative, e.g. (a * b) * c == a * (b * c)
and a * b == b * c
. The operators are also
distributive: a * (b + c) == a * b + a * c
.
(Subject to the limitations of floating-point numbers.)
Implementations§
Source§impl Linear
impl Linear
Sourcepub fn new(u: f64, v: f64) -> Self
pub fn new(u: f64, v: f64) -> Self
Construct as a complex number
The state is treated as a complex number of the form
u + v*i = a * e^{i*t}
where a
is the scale component and t
is the
angle of rotation.
Sourcepub fn rotate(radians: f64) -> Self
pub fn rotate(radians: f64) -> Self
Construct a rotating transform
In case two vectors are available, it is preferable to use
Linear::from_vectors(a, b).normalize()
.
To also scale, use Linear::rotate(radians) * scale
.
Sourcepub fn from_vectors(a: DVec2, b: DVec2) -> Self
pub fn from_vectors(a: DVec2, b: DVec2) -> Self
Construct a scaling and rotation transform taking a
to b
This may be used to construct from two-finger touch motions. In this
case, a = old.finger1 - old.finger2
and
b = new.finger1 - new.finger2
.
Sourcepub fn pan(a: DVec2, b: DVec2, (scale, rotate): (bool, bool)) -> Self
pub fn pan(a: DVec2, b: 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 a
to b
).
Sourcepub fn get_complex(self) -> (f64, f64)
pub fn get_complex(self) -> (f64, f64)
Get the internal representation
The state is treated as a complex number of the form
u + v*i = a * e^{i*t}
where a
is the scale component and t
is the
angle of rotation. These components can be calculated as follows:
let (u, v) = alpha.get_complex();
let a = (u*u + v*v).sqrt();
let t = v.atan2(a);
The matrix form of this transform is:
u -v
v u
Sourcepub fn has_scale(self) -> bool
pub fn has_scale(self) -> bool
True if the transform scales its input
This is a non-trivial operation.
Sourcepub fn has_rotation(self) -> bool
pub fn has_rotation(self) -> bool
True if the transform rotates its input
This is a trivial operation.
Sourcepub fn is_bijective(self) -> bool
pub fn is_bijective(self) -> bool
True if the transform has an inverse
This test corresponds approximately but not exactly to self.inverse().is_finite()
.
Further, self.is_bijective()
approximately implies self.inverse().is_bijective()
.
Trait Implementations§
Source§impl AddAssign for Linear
impl AddAssign for Linear
Source§fn add_assign(&mut self, rhs: Linear)
fn add_assign(&mut self, rhs: Linear)
+=
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 DivAssign<f64> for Linear
impl DivAssign<f64> for Linear
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/=
operation. Read moreSource§impl DivAssign for Linear
impl DivAssign for Linear
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 MulAssign<f64> for Linear
impl MulAssign<f64> for Linear
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*=
operation. Read moreSource§impl MulAssign for Linear
impl MulAssign for Linear
Source§fn mul_assign(&mut self, rhs: Linear)
fn mul_assign(&mut self, rhs: Linear)
*=
operation. Read moreSource§impl SubAssign for Linear
impl SubAssign for Linear
Source§fn sub_assign(&mut self, rhs: Linear)
fn sub_assign(&mut self, rhs: Linear)
-=
operation. Read moreimpl Copy for Linear
impl StructuralPartialEq for Linear
Auto Trait Implementations§
impl Freeze for Linear
impl RefUnwindSafe for Linear
impl Send for Linear
impl Sync for Linear
impl Unpin for Linear
impl UnwindSafe for Linear
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