pub struct Transformation { /* private fields */ }
Expand description
A transformation representing a Manhattan translation, rotation, and/or reflection of geometry.
This object does not support scaling of geometry, and as such all transformation matrices should be unitary.
Implementations§
Source§impl Transformation
impl Transformation
Sourcepub fn identity() -> Self
pub fn identity() -> Self
Returns the identity transform, leaving any transformed object unmodified.
Sourcepub fn translate_ref(&self, x: i64, y: i64) -> Self
pub fn translate_ref(&self, x: i64, y: i64) -> Self
Translates the current transformation by (x, y)
, returning a new Transformation
.
Sourcepub fn reflect_vert() -> Self
pub fn reflect_vert() -> Self
Returns a reflection about the x-axis.
Sourcepub fn builder() -> TransformationBuilder
pub fn builder() -> TransformationBuilder
Returns a new TransformationBuilder
.
Sourcepub fn from_offset(offset: Point) -> Self
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).
Sourcepub fn from_offset_and_orientation(
offset: Point,
orientation: impl Into<Orientation>,
) -> Self
pub fn from_offset_and_orientation( offset: Point, orientation: impl Into<Orientation>, ) -> Self
Creates a transform from an offset and Orientation
.
Sourcepub fn from_opts(offset: Point, reflect_vert: bool, angle: Rotation) -> Self
pub fn from_opts(offset: Point, reflect_vert: bool, angle: Rotation) -> Self
Creates a transform from an offset, angle, and a bool indicating whether or not to reflect vertically.
Sourcepub fn cascade(parent: Transformation, child: Transformation) -> Transformation
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).
Sourcepub fn offset_point(&self) -> Point
pub fn offset_point(&self) -> Point
The point representing the translation of this transformation.
Sourcepub fn orientation(&self) -> Orientation
pub fn orientation(&self) -> Orientation
Returns an Orientation
corresponding to this transformation.
Sourcepub fn inv(&self) -> Transformation
pub fn inv(&self) -> Transformation
Returns the inverse Transformation
of self
.
§Examples
use geometry::transform::Transformation;
use geometry::transform::Rotation;
let trans = Transformation::cascade(
Transformation::rotate(Rotation::R90),
Transformation::translate(5, 10),
);
let inv = trans.inv();
assert_eq!(Transformation::cascade(inv, trans), Transformation::identity());
assert_eq!(Transformation::cascade(trans, inv), Transformation::identity());
Trait Implementations§
Source§impl Clone for Transformation
impl Clone for Transformation
Source§fn clone(&self) -> Transformation
fn clone(&self) -> Transformation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more