summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-06-05 15:24:04 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-06-07 11:01:37 +0200
commita46a257794f1f53b294735fc876c394be23a3811 (patch)
tree9eb4fb72df2cc9e2acdf3edffe0a72f67f90b9fa /tools
parent43ddddb703bcdb9430752af63ae46527f737f874 (diff)
improve empty tools::Rectangle (width)
This is the width part, the height part will come next. Instead of storing "empty" as a special value (which is easy to get wrong, eg. some image filters pass in that special value, expecting it to be a valid width), just use separate boolean values for width and height empty. Also lots of code was calling GetBottom() or GetRight() on an empty rectangle, getting back that magic value and doing calculations on it, resulting in completely bogus data. So (1) make the various Rectangle methods do something reasonable when the empty flags are set (2) fix various other code to handle empty better (3) assert when code accesses Bottom or Right and the empty flag is set. Change-Id: I1163378cd2773dd8b386210f83400bb6b4701069 Reviewed-on: https://gerrit.libreoffice.org/73564 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools')
-rw-r--r--tools/source/generic/gen.cxx32
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/source/generic/gen.cxx b/tools/source/generic/gen.cxx
index 3593801579ac..6438405c99e2 100644
--- a/tools/source/generic/gen.cxx
+++ b/tools/source/generic/gen.cxx
@@ -55,11 +55,20 @@ OString Pair::toString() const
void tools::Rectangle::SetSize( const Size& rSize )
{
if ( rSize.Width() < 0 )
+ {
nRight = nLeft + rSize.Width() +1;
+ mbWidthEmpty = false;
+ }
else if ( rSize.Width() > 0 )
+ {
nRight = nLeft + rSize.Width() -1;
+ mbWidthEmpty = false;
+ }
else
- nRight = RECT_EMPTY;
+ {
+ nRight = 0;
+ mbWidthEmpty = true;
+ }
if ( rSize.Height() < 0 )
nBottom = nTop + rSize.Height() +1;
@@ -72,11 +81,20 @@ void tools::Rectangle::SetSize( const Size& rSize )
void tools::Rectangle::SaturatingSetSize(const Size& rSize)
{
if (rSize.Width() < 0)
+ {
nRight = o3tl::saturating_add(nLeft, (rSize.Width() + 1));
+ mbWidthEmpty = false;
+ }
else if ( rSize.Width() > 0 )
+ {
nRight = o3tl::saturating_add(nLeft, (rSize.Width() - 1));
+ mbWidthEmpty = false;
+ }
else
- nRight = RECT_EMPTY;
+ {
+ nRight = 0;
+ mbWidthEmpty = true;
+ }
if ( rSize.Height() < 0 )
nBottom = o3tl::saturating_add(nTop, (rSize.Height() + 1));
@@ -88,7 +106,8 @@ void tools::Rectangle::SaturatingSetSize(const Size& rSize)
void tools::Rectangle::SaturatingSetX(long x)
{
- nRight = o3tl::saturating_add(nRight, x - nLeft);
+ if (!mbWidthEmpty)
+ nRight = o3tl::saturating_add(nRight, x - nLeft);
nLeft = x;
}
@@ -146,7 +165,7 @@ tools::Rectangle& tools::Rectangle::Intersection( const tools::Rectangle& rRect
void tools::Rectangle::Justify()
{
- if ( (nRight < nLeft) && (nRight != RECT_EMPTY) )
+ if ( (nRight < nLeft) && !mbWidthEmpty )
{
std::swap(nLeft, nRight);
}
@@ -206,8 +225,9 @@ SvStream& ReadRectangle( SvStream& rIStream, tools::Rectangle& rRect )
rRect.nLeft = nTmpL;
rRect.nTop = nTmpT;
- rRect.nRight = nTmpR;
+ rRect.nRight = nTmpR == Rectangle::RECT_EMPTY ? 0 : nTmpR;
rRect.nBottom = nTmpB;
+ rRect.mbWidthEmpty = nTmpR == Rectangle::RECT_EMPTY;
return rIStream;
}
@@ -216,7 +236,7 @@ SvStream& WriteRectangle( SvStream& rOStream, const tools::Rectangle& rRect )
{
rOStream.WriteInt32( rRect.nLeft )
.WriteInt32( rRect.nTop )
- .WriteInt32( rRect.nRight )
+ .WriteInt32( rRect.mbWidthEmpty ? Rectangle::RECT_EMPTY : rRect.nRight )
.WriteInt32( rRect.nBottom );
return rOStream;