pub struct Transform { /* private fields */ }Expand description
A similarity transform: orthonormal rotation or reflection, uniform scale, translation.
Applied as p -> linear * (scale * p) + translation.
Implementations§
Source§impl Transform
impl Transform
Sourcepub fn from_parts(
linear: Matrix3,
scale: f64,
translation: Vector,
eps: f64,
) -> OgeomResult<Self>
pub fn from_parts( linear: Matrix3, scale: f64, translation: Vector, eps: f64, ) -> OgeomResult<Self>
A transform from the parts it is stored as.
linear is the orthonormal part alone and scale the uniform factor
beside it, which is how a Transform holds them. The kind is
re-derived rather than taken on trust, since it is a function of the
other three.
For reading a document back. Going the long way round (multiplying the
scale into the matrix and asking
GeneralTransform::to_similarity
to factor it out again) recovers a transform that is close, not the
one that was written, and a round trip that drifts a little each time is
not a round trip.
§Errors
OgeomError::Construction if linear is
not orthonormal within eps, or scale is not finite and non-zero; a
placement that squashes space is not a placement.
Sourcepub fn translation(v: Vector) -> Self
pub fn translation(v: Vector) -> Self
A translation.
Sourcepub fn from_quaternion(q: Quaternion) -> Self
pub fn from_quaternion(q: Quaternion) -> Self
A rotation given as a quaternion, about an axis through the origin.
Sourcepub fn scaling(centre: Point, factor: f64, tol: Tolerances) -> OgeomResult<Self>
pub fn scaling(centre: Point, factor: f64, tol: Tolerances) -> OgeomResult<Self>
A uniform scaling about centre.
§Errors
OgeomError::Construction if factor is
zero or non-finite. A zero scale collapses every shape to a point and is
not invertible, so it is refused rather than allowed to produce
degenerate geometry.
Sourcepub fn point_mirror(centre: Point) -> Self
pub fn point_mirror(centre: Point) -> Self
Reflection through a point.
Sourcepub fn plane_mirror(origin: Point, normal: Direction) -> Self
pub fn plane_mirror(origin: Point, normal: Direction) -> Self
Reflection in the plane through origin with the given normal.
Sourcepub fn axis_mirror(axis: Axis) -> Self
pub fn axis_mirror(axis: Axis) -> Self
Reflection in a line: a half turn about it.
Sourcepub fn to_frame(frame: &Frame) -> Self
pub fn to_frame(frame: &Frame) -> Self
The transform taking world coordinates into frame’s local coordinates.
Sourcepub fn from_frame(frame: &Frame) -> Self
pub fn from_frame(frame: &Frame) -> Self
The transform taking frame’s local coordinates into world coordinates.
Sourcepub fn between_frames(from: &Frame, to: &Frame) -> Self
pub fn between_frames(from: &Frame, to: &Frame) -> Self
The transform taking from’s local coordinates into to’s.
Sourcepub const fn kind(&self) -> TransformKind
pub const fn kind(&self) -> TransformKind
This transform’s classification.
Sourcepub const fn scale_factor(&self) -> f64
pub const fn scale_factor(&self) -> f64
The uniform scale factor. Negative for a point mirror.
Sourcepub const fn translation_vector(&self) -> Vector
pub const fn translation_vector(&self) -> Vector
The translation.
Sourcepub fn preserves_handedness(&self) -> bool
pub fn preserves_handedness(&self) -> bool
Whether this transform preserves handedness.
A shape transformed by a transform that does not must have its orientation flipped to stay consistent; otherwise a mirrored solid ends up inside out.
Sourcepub fn apply_vector(&self, v: Vector) -> Vector
pub fn apply_vector(&self, v: Vector) -> Vector
Apply to a free vector. Translation does not affect it.
Sourcepub fn apply_direction(
&self,
d: Direction,
tol: Tolerances,
) -> OgeomResult<Direction>
pub fn apply_direction( &self, d: Direction, tol: Tolerances, ) -> OgeomResult<Direction>
Apply to a direction, renormalizing.
A similarity maps unit vectors to vectors of length |scale|, so the
result is rescaled. Under a negative scale the direction reverses, which
is the correct behaviour and not a sign error.
§Errors
OgeomError::Construction if the result
cannot be normalized, which a valid similarity never produces.
Sourcepub fn apply_frame(&self, f: &Frame, tol: Tolerances) -> OgeomResult<Frame>
pub fn apply_frame(&self, f: &Frame, tol: Tolerances) -> OgeomResult<Frame>
Apply to a frame, transforming origin and all three axes.
§Errors
OgeomError::Construction if the
transformed axes cannot be renormalized.
Sourcepub fn inverse(&self) -> OgeomResult<Self>
pub fn inverse(&self) -> OgeomResult<Self>
The inverse.
§Errors
OgeomError::Numeric if the linear part is
singular, which a valid similarity never is.
Sourcepub fn is_equal(&self, other: &Self, tol: Tolerances) -> bool
pub fn is_equal(&self, other: &Self, tol: Tolerances) -> bool
Whether two transforms agree in effect.
Sourcepub fn to_general(&self) -> GeneralTransform
pub fn to_general(&self) -> GeneralTransform
This transform as a general affine one.
Trait Implementations§
impl Copy for Transform
Source§impl From<Transform> for GeneralTransform
impl From<Transform> for GeneralTransform
impl StructuralPartialEq for Transform
Auto Trait Implementations§
impl Freeze for Transform
impl RefUnwindSafe for Transform
impl Send for Transform
impl Sync for Transform
impl Unpin for Transform
impl UnsafeUnpin for Transform
impl UnwindSafe for Transform
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,
impl<T> Scalar for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.