From 83c7a8f6c3ca80f5876adfe7e2bca2efe79cc9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 7 Dec 2023 12:32:47 +0100 Subject: [PATCH] Math: simplify internals of Matrix[34]::rotation{,Normalized}(). It does exactly what these functions do, so delegate to them. --- src/Magnum/Math/Matrix3.h | 18 ++++++++---------- src/Magnum/Math/Matrix4.h | 20 ++++++++------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/Magnum/Math/Matrix3.h b/src/Magnum/Math/Matrix3.h index c37d31738..245b19229 100644 --- a/src/Magnum/Math/Matrix3.h +++ b/src/Magnum/Math/Matrix3.h @@ -766,19 +766,17 @@ template Matrix3 Matrix3::projection(const Vector2& bottomLeft } template Matrix2x2 Matrix3::rotation() const { - Matrix2x2 rotation{(*this)[0].xy().normalized(), - (*this)[1].xy().normalized()}; - CORRADE_DEBUG_ASSERT(rotation.isOrthogonal(), - "Math::Matrix3::rotation(): the normalized rotation part is not orthogonal:" << Debug::newline << rotation, {}); - return rotation; + Matrix2x2 rotationShear = this->rotationShear(); + CORRADE_DEBUG_ASSERT(rotationShear.isOrthogonal(), + "Math::Matrix3::rotation(): the normalized rotation part is not orthogonal:" << Debug::newline << rotationShear, {}); + return rotationShear; } template Matrix2x2 Matrix3::rotationNormalized() const { - Matrix2x2 rotation{(*this)[0].xy(), - (*this)[1].xy()}; - CORRADE_DEBUG_ASSERT(rotation.isOrthogonal(), - "Math::Matrix3::rotationNormalized(): the rotation part is not orthogonal:" << Debug::newline << rotation, {}); - return rotation; + Matrix2x2 rotationScaling = this->rotationScaling(); + CORRADE_DEBUG_ASSERT(rotationScaling.isOrthogonal(), + "Math::Matrix3::rotationNormalized(): the rotation part is not orthogonal:" << Debug::newline << rotationScaling, {}); + return rotationScaling; } template T Matrix3::uniformScalingSquared() const { diff --git a/src/Magnum/Math/Matrix4.h b/src/Magnum/Math/Matrix4.h index 5cd930cb4..ca4bab468 100644 --- a/src/Magnum/Math/Matrix4.h +++ b/src/Magnum/Math/Matrix4.h @@ -1328,21 +1328,17 @@ template Matrix4 Matrix4::lookAt(const Vector3& eye, const Vec } template Matrix3x3 Matrix4::rotation() const { - Matrix3x3 rotation{(*this)[0].xyz().normalized(), - (*this)[1].xyz().normalized(), - (*this)[2].xyz().normalized()}; - CORRADE_DEBUG_ASSERT(rotation.isOrthogonal(), - "Math::Matrix4::rotation(): the normalized rotation part is not orthogonal:" << Debug::newline << rotation, {}); - return rotation; + Matrix3x3 rotationShear = this->rotationShear(); + CORRADE_DEBUG_ASSERT(rotationShear.isOrthogonal(), + "Math::Matrix4::rotation(): the normalized rotation part is not orthogonal:" << Debug::newline << rotationShear, {}); + return rotationShear; } template Matrix3x3 Matrix4::rotationNormalized() const { - Matrix3x3 rotation{(*this)[0].xyz(), - (*this)[1].xyz(), - (*this)[2].xyz()}; - CORRADE_DEBUG_ASSERT(rotation.isOrthogonal(), - "Math::Matrix4::rotationNormalized(): the rotation part is not orthogonal:" << Debug::newline << rotation, {}); - return rotation; + Matrix3x3 rotationScaling = this->rotationScaling(); + CORRADE_DEBUG_ASSERT(rotationScaling.isOrthogonal(), + "Math::Matrix4::rotationNormalized(): the rotation part is not orthogonal:" << Debug::newline << rotationScaling, {}); + return rotationScaling; } template T Matrix4::uniformScalingSquared() const {