diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-06-05 14:23:02 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-06-06 08:26:10 +0200 |
commit | 039a18ff147be304966caf529e6f14ad4996a3e0 (patch) | |
tree | ddf88740ba7f070f2e8444f121d149820afcba41 /tools | |
parent | c32d97c5a5d6f94713feaf7867abb1ce11cf9a14 (diff) |
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 <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/generic/poly.cxx | 31 |
1 files changed, 5 insertions, 26 deletions
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) |