pub struct Transform2D {
pub tx: f64,
pub ty: f64,
pub angle: f64,
}Expand description
A 2D rigid transformation (rotation + translation).
Internally uses nalgebra Isometry2 for correct composition
and inversion. The representation stores translation (tx, ty)
and rotation angle in radians.
§Example
use u_geometry::transform::Transform2D;
use std::f64::consts::PI;
let t = Transform2D::new(10.0, 20.0, PI / 2.0);
let (x, y) = t.apply(1.0, 0.0);
assert!((x - 10.0).abs() < 1e-10);
assert!((y - 21.0).abs() < 1e-10);Fields§
§tx: f64Translation x.
ty: f64Translation y.
angle: f64Rotation angle in radians.
Implementations§
Source§impl Transform2D
impl Transform2D
Sourcepub fn translation(tx: f64, ty: f64) -> Self
pub fn translation(tx: f64, ty: f64) -> Self
Creates a translation-only transform.
Sourcepub fn new(tx: f64, ty: f64, angle: f64) -> Self
pub fn new(tx: f64, ty: f64, angle: f64) -> Self
Creates a transform with translation and rotation.
Sourcepub fn to_isometry(&self) -> Isometry2<f64>
pub fn to_isometry(&self) -> Isometry2<f64>
Converts to a nalgebra Isometry2.
Sourcepub fn from_isometry(iso: &Isometry2<f64>) -> Self
pub fn from_isometry(iso: &Isometry2<f64>) -> Self
Creates from a nalgebra Isometry2.
Sourcepub fn apply_point(&self, p: &Point2) -> Point2
pub fn apply_point(&self, p: &Point2) -> Point2
Applies this transform to a Point2.
Sourcepub fn apply_points(&self, points: &[(f64, f64)]) -> Vec<(f64, f64)>
pub fn apply_points(&self, points: &[(f64, f64)]) -> Vec<(f64, f64)>
Transforms a slice of points.
Sourcepub fn then(&self, other: &Self) -> Self
pub fn then(&self, other: &Self) -> Self
Composes two transforms: applies self first, then other.
Sourcepub fn is_identity(&self, epsilon: f64) -> bool
pub fn is_identity(&self, epsilon: f64) -> bool
Whether this is approximately an identity transform.
Trait Implementations§
Source§impl Clone for Transform2D
impl Clone for Transform2D
Source§fn clone(&self) -> Transform2D
fn clone(&self) -> Transform2D
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Transform2D
impl Debug for Transform2D
Source§impl Default for Transform2D
impl Default for Transform2D
Source§impl PartialEq for Transform2D
impl PartialEq for Transform2D
impl Copy for Transform2D
impl StructuralPartialEq for Transform2D
Auto Trait Implementations§
impl Freeze for Transform2D
impl RefUnwindSafe for Transform2D
impl Send for Transform2D
impl Sync for Transform2D
impl Unpin for Transform2D
impl UnsafeUnpin for Transform2D
impl UnwindSafe for Transform2D
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.