From db0ba9f64705ac9bf06a7294bec11c172e53ce11 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Wed, 13 Apr 2022 21:56:13 +0200 Subject: [PATCH] LibGfx: Use some AK/Math helpers in AffineTransform This makes us use AK::sincos and AK::hypot --- Userland/Libraries/LibGfx/AffineTransform.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibGfx/AffineTransform.cpp b/Userland/Libraries/LibGfx/AffineTransform.cpp index 70da1c749b..96cf0ec52b 100644 --- a/Userland/Libraries/LibGfx/AffineTransform.cpp +++ b/Userland/Libraries/LibGfx/AffineTransform.cpp @@ -21,20 +21,14 @@ bool AffineTransform::is_identity_or_translation() const return a() == 1 && b() == 0 && c() == 0 && d() == 1; } -static float hypotenuse(float x, float y) -{ - // FIXME: This won't handle overflow :( - return sqrtf(x * x + y * y); -} - float AffineTransform::x_scale() const { - return hypotenuse(m_values[0], m_values[1]); + return AK::hypot(m_values[0], m_values[1]); } float AffineTransform::y_scale() const { - return hypotenuse(m_values[2], m_values[3]); + return AK::hypot(m_values[2], m_values[3]); } FloatPoint AffineTransform::scale() const @@ -124,8 +118,9 @@ AffineTransform& AffineTransform::multiply(AffineTransform const& other) AffineTransform& AffineTransform::rotate_radians(float radians) { - float sin_angle = sinf(radians); - float cos_angle = cosf(radians); + float sin_angle; + float cos_angle; + AK::sincos(radians, sin_angle, cos_angle); AffineTransform rotation(cos_angle, sin_angle, -sin_angle, cos_angle, 0, 0); multiply(rotation); return *this;