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>
This commit is contained in:
Noel Grandin 2024-06-05 14:23:02 +02:00
parent c32d97c5a5
commit 039a18ff14

View file

@ -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)