diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 1b908f33..7424e16e 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -66,6 +66,30 @@ impl<'a, T: RealField + Deserialize<'a>> Deserialize<'a> for Orthographic3 { } } +impl Orthographic3 { + /// Wraps the given matrix to interpret it as a 3D orthographic matrix. + /// + /// It is not checked whether or not the given matrix actually represents an orthographic + /// projection. + /// + /// # Example + /// ``` + /// # use nalgebra::{Orthographic3, Point3, Matrix4}; + /// let mat = Matrix4::new( + /// 2.0 / 9.0, 0.0, 0.0, -11.0 / 9.0, + /// 0.0, 2.0 / 18.0, 0.0, -22.0 / 18.0, + /// 0.0, 0.0, -2.0 / 999.9, -1000.1 / 999.9, + /// 0.0, 0.0, 0.0, 1.0 + /// ); + /// let proj = Orthographic3::from_matrix_unchecked(mat); + /// assert_eq!(proj, Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0)); + /// ``` + #[inline] + pub const fn from_matrix_unchecked(matrix: Matrix4) -> Self { + Self { matrix } + } +} + impl Orthographic3 { /// Creates a new orthographic projection matrix. /// @@ -121,28 +145,6 @@ impl Orthographic3 { res } - /// Wraps the given matrix to interpret it as a 3D orthographic matrix. - /// - /// It is not checked whether or not the given matrix actually represents an orthographic - /// projection. - /// - /// # Example - /// ``` - /// # use nalgebra::{Orthographic3, Point3, Matrix4}; - /// let mat = Matrix4::new( - /// 2.0 / 9.0, 0.0, 0.0, -11.0 / 9.0, - /// 0.0, 2.0 / 18.0, 0.0, -22.0 / 18.0, - /// 0.0, 0.0, -2.0 / 999.9, -1000.1 / 999.9, - /// 0.0, 0.0, 0.0, 1.0 - /// ); - /// let proj = Orthographic3::from_matrix_unchecked(mat); - /// assert_eq!(proj, Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0)); - /// ``` - #[inline] - pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { - Self { matrix } - } - /// Creates a new orthographic projection matrix from an aspect ratio and the vertical field of view. #[inline] pub fn from_fov(aspect: T, vfov: T, znear: T, zfar: T) -> Self { diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index f9246af1..7f763c69 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -67,6 +67,17 @@ impl<'a, T: RealField + Deserialize<'a>> Deserialize<'a> for Perspective3 { } } +impl Perspective3 { + /// Wraps the given matrix to interpret it as a 3D perspective matrix. + /// + /// It is not checked whether or not the given matrix actually represents a perspective + /// projection. + #[inline] + pub const fn from_matrix_unchecked(matrix: Matrix4) -> Self { + Self { matrix } + } +} + impl Perspective3 { /// Creates a new perspective matrix from the aspect ratio, y field of view, and near/far planes. pub fn new(aspect: T, fovy: T, znear: T, zfar: T) -> Self { @@ -92,15 +103,6 @@ impl Perspective3 { res } - /// Wraps the given matrix to interpret it as a 3D perspective matrix. - /// - /// It is not checked whether or not the given matrix actually represents a perspective - /// projection. - #[inline] - pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { - Self { matrix } - } - /// Retrieves the inverse of the underlying homogeneous matrix. #[inline] #[must_use] diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index bbe6f60b..32e216d8 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -130,10 +130,10 @@ where } } -impl Rotation { +impl Rotation { /// Creates a new rotation from the given square matrix. /// - /// The matrix squareness is checked but not its orthonormality. + /// The matrix orthonormality is not checked. /// /// # Example /// ``` @@ -154,12 +154,7 @@ impl Rotation { /// assert_eq!(*rot.matrix(), mat); /// ``` #[inline] - pub fn from_matrix_unchecked(matrix: SMatrix) -> Self { - assert!( - matrix.is_square(), - "Unable to create a rotation from a non-square matrix." - ); - + pub const fn from_matrix_unchecked(matrix: SMatrix) -> Self { Self { matrix } } }