pub struct Transformation { /* private fields */ }
Expand description

A transformation representing translation, rotation, and reflection of geometry.

This object does not support scaling of geometry, and as such all transformation matrices should be unitary.

Implementations§

source§

impl Transformation

source

pub fn identity() -> Self

Returns the identity transform, leaving any transformed object unmodified.

source

pub fn translate(x: f64, y: f64) -> Self

Returns a translation by (x,y).

source

pub fn rotate(angle: f64) -> Self

Returns a rotatation by angle degrees.

source

pub fn reflect_vert() -> Self

Returns a reflection about the x-axis.

source

pub fn builder() -> TransformationBuilder

Returns a new TransformationBuilder.

source

pub fn from_offset(offset: Point) -> Self

Creates a transform from only an offset.

The resulting transformation will apply only a translation (i.e. no rotations/reflections).

source

pub fn from_offset_and_orientation( offset: Point, orientation: impl Into<Orientation> ) -> Self

Creates a transform from an offset and Orientation.

source

pub fn from_opts(offset: Point, reflect_vert: bool, angle: f64) -> Self

Creates a transform from an offset, angle, and a bool indicating whether or not to reflect vertically.

source

pub fn cascade(parent: Transformation, child: Transformation) -> Transformation

Create a new Transformation that is the cascade of parent and child.

“Parents” and “children” refer to typical layout-instance hierarchies, in which each layer of instance has a nested set of transformations relative to its top-level parent.

Note this operation is not commutative. For example the set of transformations:

  • (a) Reflect vertically, then
  • (b) Translate by (1,1)
  • (c) Place a point at (local coordinate) (1,1) Lands said point at (2,-2) in top-level space, whereas reversing the order of (a) and (b) lands it at (2,0).
source

pub fn offset_point(&self) -> Point

The point representing the translation of this transformation.

source

pub fn orientation(&self) -> Orientation

Returns an Orientation corresponding to this transformation.

source

pub fn inv(&self) -> Transformation

Returns the inverse Transformation of self.

§Examples
use geometry::transform::Transformation;
use approx::assert_relative_eq;

let trans = Transformation::cascade(
    Transformation::rotate(90.),
    Transformation::translate(5., 10.),
);
let inv = trans.inv();

assert_relative_eq!(Transformation::cascade(inv, trans), Transformation::identity());

Trait Implementations§

source§

impl AbsDiffEq for Transformation

§

type Epsilon = f64

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_eq(&self, other: &Self, epsilon: f64) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of [AbsDiffEq::abs_diff_eq].
source§

impl Clone for Transformation

source§

fn clone(&self) -> Transformation

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 Transformation

source§

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

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

impl Default for Transformation

source§

fn default() -> Self

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

impl<T> From<T> for Transformation
where T: Into<Orientation>,

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Transformation

source§

fn eq(&self, other: &Transformation) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RelativeEq for Transformation

source§

fn default_max_relative() -> f64

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_eq(&self, other: &Self, epsilon: f64, max_relative: f64) -> bool

A test for equality that uses a relative comparison if the values are far apart.
§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

The inverse of [RelativeEq::relative_eq].
source§

impl UlpsEq for Transformation

source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
source§

fn ulps_eq(&self, other: &Self, epsilon: f64, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of [UlpsEq::ulps_eq].
source§

impl Copy for Transformation

source§

impl StructuralPartialEq for Transformation

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> 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.