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

source

pub const fn new(translation: Vec2, scale: f64) -> TranslateScale

Create a new transformation from translation and scale.

source

pub const fn scale(s: f64) -> TranslateScale

Create a new transformation with scale only.

source

pub fn translate(translation: impl Into<Vec2>) -> TranslateScale

Create a new transformation with translation only.

source

pub const fn as_tuple(self) -> (Vec2, f64)

👎Deprecated: use the struct fields directly

Decompose transformation into translation and scale.

source

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.));
source

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.

source

pub fn is_finite(&self) -> bool

Is this translate/scale finite?

source

pub fn is_nan(&self) -> bool

Is this translate/scale NaN?

Trait Implementations§

source§

impl Add<TranslateScale> for Vec2

§

type Output = TranslateScale

The resulting type after applying the + operator.
source§

fn add(self, other: TranslateScale) -> TranslateScale

Performs the + operation. Read more
source§

impl Add<Vec2> for TranslateScale

§

type Output = TranslateScale

The resulting type after applying the + operator.
source§

fn add(self, other: Vec2) -> TranslateScale

Performs the + operation. Read more
source§

impl AddAssign<Vec2> for TranslateScale

source§

fn add_assign(&mut self, other: Vec2)

Performs the += operation. Read more
source§

impl Clone for TranslateScale

source§

fn clone(&self) -> TranslateScale

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 Debug for TranslateScale

source§

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

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

impl Default for TranslateScale

source§

fn default() -> TranslateScale

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

impl<'de> Deserialize<'de> for TranslateScale

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<TranslateScale> for Affine

source§

fn from(ts: TranslateScale) -> Affine

Converts to this type from the input type.
source§

impl JsonSchema for TranslateScale

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
source§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

impl<'a> Mul<&'a BezPath> for TranslateScale

§

type Output = BezPath

The resulting type after applying the * operator.
source§

fn mul(self, other: &BezPath) -> BezPath

Performs the * operation. Read more
source§

impl Mul<BezPath> for TranslateScale

§

type Output = BezPath

The resulting type after applying the * operator.
source§

fn mul(self, other: BezPath) -> BezPath

Performs the * operation. Read more
source§

impl Mul<Circle> for TranslateScale

§

type Output = Circle

The resulting type after applying the * operator.
source§

fn mul(self, other: Circle) -> Circle

Performs the * operation. Read more
source§

impl Mul<CubicBez> for TranslateScale

§

type Output = CubicBez

The resulting type after applying the * operator.
source§

fn mul(self, other: CubicBez) -> CubicBez

Performs the * operation. Read more
source§

impl Mul<Line> for TranslateScale

§

type Output = Line

The resulting type after applying the * operator.
source§

fn mul(self, other: Line) -> Line

Performs the * operation. Read more
source§

impl Mul<PathEl> for TranslateScale

§

type Output = PathEl

The resulting type after applying the * operator.
source§

fn mul(self, other: PathEl) -> PathEl

Performs the * operation. Read more
source§

impl Mul<PathSeg> for TranslateScale

§

type Output = PathSeg

The resulting type after applying the * operator.
source§

fn mul(self, other: PathSeg) -> PathSeg

Performs the * operation. Read more
source§

impl Mul<Point> for TranslateScale

§

type Output = Point

The resulting type after applying the * operator.
source§

fn mul(self, other: Point) -> Point

Performs the * operation. Read more
source§

impl Mul<QuadBez> for TranslateScale

§

type Output = QuadBez

The resulting type after applying the * operator.
source§

fn mul(self, other: QuadBez) -> QuadBez

Performs the * operation. Read more
source§

impl Mul<Rect> for TranslateScale

§

type Output = Rect

The resulting type after applying the * operator.
source§

fn mul(self, other: Rect) -> Rect

Performs the * operation. Read more
source§

impl Mul<RoundedRect> for TranslateScale

§

type Output = RoundedRect

The resulting type after applying the * operator.
source§

fn mul(self, other: RoundedRect) -> RoundedRect

Performs the * operation. Read more
source§

impl Mul<RoundedRectRadii> for TranslateScale

§

type Output = RoundedRectRadii

The resulting type after applying the * operator.
source§

fn mul(self, other: RoundedRectRadii) -> RoundedRectRadii

Performs the * operation. Read more
source§

impl Mul<TranslateScale> for f64

§

type Output = TranslateScale

The resulting type after applying the * operator.
source§

fn mul(self, other: TranslateScale) -> TranslateScale

Performs the * operation. Read more
source§

impl Mul for TranslateScale

§

type Output = TranslateScale

The resulting type after applying the * operator.
source§

fn mul(self, other: TranslateScale) -> TranslateScale

Performs the * operation. Read more
source§

impl MulAssign for TranslateScale

source§

fn mul_assign(&mut self, other: TranslateScale)

Performs the *= operation. Read more
source§

impl Serialize for TranslateScale

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub<Vec2> for TranslateScale

§

type Output = TranslateScale

The resulting type after applying the - operator.
source§

fn sub(self, other: Vec2) -> TranslateScale

Performs the - operation. Read more
source§

impl SubAssign<Vec2> for TranslateScale

source§

fn sub_assign(&mut self, other: Vec2)

Performs the -= operation. Read more
source§

impl Copy for TranslateScale

Auto Trait Implementations§

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,