diff --git a/src/box2d.rs b/src/box2d.rs index 685f6aa..e4dec69 100644 --- a/src/box2d.rs +++ b/src/box2d.rs @@ -787,6 +787,15 @@ where } } +impl From> for Box2D +where + T: Copy + Add, +{ + fn from(r: Rect) -> Self { + r.to_box2d() + } +} + impl Default for Box2D { fn default() -> Self { Box2D { diff --git a/src/rect.rs b/src/rect.rs index 1b870ba..7e8cdf0 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -671,6 +671,15 @@ where } } +impl From> for Rect +where + T: Copy + Sub, +{ + fn from(b: Box2D) -> Self { + b.to_rect() + } +} + /// Shorthand for `Rect::new(Point2D::new(x, y), Size2D::new(w, h))`. pub const fn rect(x: T, y: T, w: T, h: T) -> Rect { Rect::new(Point2D::new(x, y), Size2D::new(w, h)) diff --git a/src/rotation.rs b/src/rotation.rs index 7103fd9..260b7e7 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -8,6 +8,7 @@ // except according to those terms. use crate::approxeq::ApproxEq; +use crate::num::{One, Zero}; use crate::trig::Trig; use crate::{point2, point3, vec3, Angle, Point2D, Point3D, Vector2D, Vector3D}; use crate::{Transform2D, Transform3D, UnknownUnit}; @@ -23,7 +24,7 @@ use bytemuck::{Pod, Zeroable}; #[cfg(feature = "malloc_size_of")] use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use num_traits::real::Real; -use num_traits::{NumCast, One, Zero}; +use num_traits::NumCast; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -807,6 +808,15 @@ where } } +impl From> for Transform3D +where + T: Real + ApproxEq, +{ + fn from(r: Rotation3D) -> Self { + r.to_transform() + } +} + #[test] fn simple_rotation_2d() { use crate::default::Rotation2D; diff --git a/src/transform2d.rs b/src/transform2d.rs index 87c6230..716d34c 100644 --- a/src/transform2d.rs +++ b/src/transform2d.rs @@ -15,9 +15,12 @@ use crate::box2d::Box2D; use crate::num::{One, Zero}; use crate::point::{point2, Point2D}; use crate::rect::Rect; +use crate::scale::Scale; use crate::transform3d::Transform3D; +use crate::translation::Translation2D; use crate::trig::Trig; use crate::vector::{vec2, Vector2D}; +use crate::Rotation2D; use core::cmp::{Eq, PartialEq}; use core::fmt; use core::hash::Hash; @@ -742,6 +745,27 @@ impl From> for mint::RowMatrix3x2 { } } +impl From> for Transform2D +where + T: Copy + Add + Sub + Mul + Zero + Trig, +{ + fn from(r: Rotation2D) -> Self { + r.to_transform() + } +} + +impl From> for Transform2D { + fn from(t: ScaleOffset2D) -> Self { + t.to_transform2d() + } +} + +impl From> for Transform2D { + fn from(s: Scale) -> Self { + Transform2D::scale(s.0, s.0) + } +} + #[repr(C)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr( @@ -1134,6 +1158,18 @@ where } } +impl From> for ScaleOffset2D { + fn from(s: Scale) -> Self { + ScaleOffset2D::scale(s.0, s.0) + } +} + +impl From> for ScaleOffset2D { + fn from(t: Translation2D) -> Self { + ScaleOffset2D::offset(t.x, t.y) + } +} + #[cfg(feature = "arbitrary")] impl<'a, T, Src, Dst> arbitrary::Arbitrary<'a> for ScaleOffset2D where diff --git a/src/transform3d.rs b/src/transform3d.rs index 9db83ad..075ad10 100644 --- a/src/transform3d.rs +++ b/src/transform3d.rs @@ -1269,6 +1269,18 @@ impl From> for mint::RowMatrix4 { } } +impl From> for Transform3D { + fn from(t: Transform2D) -> Self { + t.to_3d() + } +} + +impl From> for Transform3D { + fn from(s: Scale) -> Self { + Transform3D::scale(s.get(), s.get(), s.get()) + } +} + #[cfg(test)] mod tests { use super::*;