From 039a18ff147be304966caf529e6f14ad4996a3e0 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 5 Jun 2024 14:23:02 +0200 Subject: compute these using floating point which means we can avoid the checked_multiply complexity Change-Id: I2badbde7bf9c6f18337913034b24672fddce3af8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168472 Tested-by: Jenkins Reviewed-by: Noel Grandin --- tools/source/generic/poly.cxx | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'tools') diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx index b6b00bc2ca34..fc09038bca7e 100644 --- a/tools/source/generic/poly.cxx +++ b/tools/source/generic/poly.cxx @@ -172,20 +172,10 @@ ImplPolygon::ImplPolygon( const Point& rCenter, tools::Long nRadX, tools::Long n { if( nRadX && nRadY ) { - sal_uInt16 nPoints; // Compute default (depends on size) - tools::Long nRadXY; - const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY); - if (!bOverflow) - { - nPoints = std::clamp( - ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( std::fabs(nRadXY) ) ) ), - 32.0, 256.0 ); - } - else - { - nPoints = 256; - } + sal_uInt16 nPoints = std::clamp( + ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( std::fabs(double(nRadX) * nRadY) ) ) ), + 32.0, 256.0 ); if( ( nRadX > 32 ) && ( nRadY > 32 ) && ( nRadX + nRadY ) < 8192 ) nPoints >>= 1; @@ -237,20 +227,9 @@ ImplPolygon::ImplPolygon(const tools::Rectangle& rBound, const Point& rStart, co const auto aBoundTop = rBound.Top() < aCenter.Y() ? rBound.Top() : rBound.Bottom(); const auto nRadX = o3tl::saturating_sub(aCenter.X(), aBoundLeft); const auto nRadY = o3tl::saturating_sub(aCenter.Y(), aBoundTop); - sal_uInt16 nPoints; - - tools::Long nRadXY; - const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY); - if (!bOverflow) - { - nPoints = std::clamp( - ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( std::fabs(nRadXY) ) ) ), + sal_uInt16 nPoints = std::clamp( + ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( std::fabs(double(nRadX) * nRadY) ) ) ), 32.0, 256.0 ); - } - else - { - nPoints = 256; - } if (nRadX > 32 && nRadY > 32 && o3tl::saturating_add(nRadX, nRadY) < 8192) -- cgit