Struct kurbo::TranslateScale
source · pub struct TranslateScale {
pub translation: Vec2,
pub scale: f64,
}
Expand description
A transformation consisting of a uniform scaling followed by a translation.
If the translation is (x, y)
and the scale is s
, then this
transformation represents this augmented matrix:
| s 0 x |
| 0 s y |
| 0 0 1 |
See Affine
for more details about the
equivalence with augmented matrices.
Various multiplication ops are defined, and these are all defined
to be consistent with matrix multiplication. Therefore,
TranslateScale * Point
is defined but not the other way around.
Also note that multiplication is not commutative. Thus,
TranslateScale::scale(2.0) * TranslateScale::translate(Vec2::new(1.0, 0.0))
has a translation of (2, 0), while
TranslateScale::translate(Vec2::new(1.0, 0.0)) * TranslateScale::scale(2.0)
has a translation of (1, 0). (Both have a scale of 2; also note that
the first case can be written
2.0 * TranslateScale::translate(Vec2::new(1.0, 0.0))
as this case
has an implicit conversion).
This transformation is less powerful than Affine
, but can be applied
to more primitives, especially including Rect
.
Fields§
§translation: Vec2
The translation component of this transformation
scale: f64
The scale component of this transformation
Implementations§
source§impl TranslateScale
impl TranslateScale
sourcepub const fn new(translation: Vec2, scale: f64) -> TranslateScale
pub const fn new(translation: Vec2, scale: f64) -> TranslateScale
Create a new transformation from translation and scale.
sourcepub const fn scale(s: f64) -> TranslateScale
pub const fn scale(s: f64) -> TranslateScale
Create a new transformation with scale only.
sourcepub fn translate(translation: impl Into<Vec2>) -> TranslateScale
pub fn translate(translation: impl Into<Vec2>) -> TranslateScale
Create a new transformation with translation only.
sourcepub const fn as_tuple(self) -> (Vec2, f64)
👎Deprecated: use the struct fields directly
pub const fn as_tuple(self) -> (Vec2, f64)
Decompose transformation into translation and scale.
sourcepub fn from_scale_about(scale: f64, focus: impl Into<Point>) -> Self
pub fn from_scale_about(scale: f64, focus: impl Into<Point>) -> Self
Create a transform that scales about a point other than the origin.
§Examples
let center = Point::new(1., 1.);
let ts = TranslateScale::from_scale_about(2., center);
// Should keep the point (1., 1.) stationary
assert_near(ts * center, center);
// (2., 2.) -> (3., 3.)
assert_near(ts * Point::new(2., 2.), Point::new(3., 3.));
sourcepub fn inverse(self) -> TranslateScale
pub fn inverse(self) -> TranslateScale
Compute the inverse transform.
Multiplying a transform with its inverse (either on the left or right) results in the identity transform (modulo floating point rounding errors).
Produces NaN values when scale is zero.
Trait Implementations§
source§impl Add<TranslateScale> for Vec2
impl Add<TranslateScale> for Vec2
source§type Output = TranslateScale
type Output = TranslateScale
+
operator.source§fn add(self, other: TranslateScale) -> TranslateScale
fn add(self, other: TranslateScale) -> TranslateScale
+
operation. Read moresource§impl Add<Vec2> for TranslateScale
impl Add<Vec2> for TranslateScale
source§type Output = TranslateScale
type Output = TranslateScale
+
operator.source§impl AddAssign<Vec2> for TranslateScale
impl AddAssign<Vec2> for TranslateScale
source§fn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
+=
operation. Read moresource§impl Clone for TranslateScale
impl Clone for TranslateScale
source§fn clone(&self) -> TranslateScale
fn clone(&self) -> TranslateScale
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TranslateScale
impl Debug for TranslateScale
source§impl Default for TranslateScale
impl Default for TranslateScale
source§fn default() -> TranslateScale
fn default() -> TranslateScale
source§impl<'de> Deserialize<'de> for TranslateScale
impl<'de> Deserialize<'de> for TranslateScale
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<TranslateScale> for Affine
impl From<TranslateScale> for Affine
source§fn from(ts: TranslateScale) -> Affine
fn from(ts: TranslateScale) -> Affine
source§impl JsonSchema for TranslateScale
impl JsonSchema for TranslateScale
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl<'a> Mul<&'a BezPath> for TranslateScale
impl<'a> Mul<&'a BezPath> for TranslateScale
source§impl Mul<BezPath> for TranslateScale
impl Mul<BezPath> for TranslateScale
source§impl Mul<Circle> for TranslateScale
impl Mul<Circle> for TranslateScale
source§impl Mul<CubicBez> for TranslateScale
impl Mul<CubicBez> for TranslateScale
source§impl Mul<Line> for TranslateScale
impl Mul<Line> for TranslateScale
source§impl Mul<PathEl> for TranslateScale
impl Mul<PathEl> for TranslateScale
source§impl Mul<PathSeg> for TranslateScale
impl Mul<PathSeg> for TranslateScale
source§impl Mul<Point> for TranslateScale
impl Mul<Point> for TranslateScale
source§impl Mul<QuadBez> for TranslateScale
impl Mul<QuadBez> for TranslateScale
source§impl Mul<Rect> for TranslateScale
impl Mul<Rect> for TranslateScale
source§impl Mul<RoundedRect> for TranslateScale
impl Mul<RoundedRect> for TranslateScale
source§type Output = RoundedRect
type Output = RoundedRect
*
operator.source§fn mul(self, other: RoundedRect) -> RoundedRect
fn mul(self, other: RoundedRect) -> RoundedRect
*
operation. Read moresource§impl Mul<RoundedRectRadii> for TranslateScale
impl Mul<RoundedRectRadii> for TranslateScale
source§type Output = RoundedRectRadii
type Output = RoundedRectRadii
*
operator.source§fn mul(self, other: RoundedRectRadii) -> RoundedRectRadii
fn mul(self, other: RoundedRectRadii) -> RoundedRectRadii
*
operation. Read moresource§impl Mul<TranslateScale> for f64
impl Mul<TranslateScale> for f64
source§type Output = TranslateScale
type Output = TranslateScale
*
operator.source§fn mul(self, other: TranslateScale) -> TranslateScale
fn mul(self, other: TranslateScale) -> TranslateScale
*
operation. Read moresource§impl Mul for TranslateScale
impl Mul for TranslateScale
source§type Output = TranslateScale
type Output = TranslateScale
*
operator.source§fn mul(self, other: TranslateScale) -> TranslateScale
fn mul(self, other: TranslateScale) -> TranslateScale
*
operation. Read moresource§impl MulAssign for TranslateScale
impl MulAssign for TranslateScale
source§fn mul_assign(&mut self, other: TranslateScale)
fn mul_assign(&mut self, other: TranslateScale)
*=
operation. Read moresource§impl Serialize for TranslateScale
impl Serialize for TranslateScale
source§impl Sub<Vec2> for TranslateScale
impl Sub<Vec2> for TranslateScale
source§type Output = TranslateScale
type Output = TranslateScale
-
operator.source§impl SubAssign<Vec2> for TranslateScale
impl SubAssign<Vec2> for TranslateScale
source§fn sub_assign(&mut self, other: Vec2)
fn sub_assign(&mut self, other: Vec2)
-=
operation. Read moreimpl Copy for TranslateScale
Auto Trait Implementations§
impl Freeze for TranslateScale
impl RefUnwindSafe for TranslateScale
impl Send for TranslateScale
impl Sync for TranslateScale
impl Unpin for TranslateScale
impl UnwindSafe for TranslateScale
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)