diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-08-14 03:20:01 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-08-15 10:18:49 +0200 |
commit | 6c12c659fb22aeab1d1d5d0e8298662e2a602499 (patch) | |
tree | cb2ed47b989a24ec4d7a8944d87520533ae7b186 /tools/source/generic | |
parent | ffaaec23ad94f9bec5fd0fcb02603270eb660b81 (diff) |
Simplify tools::Rectangle a bit
1. Simplify/delegate ctors
2. Simplify getWidth/getHeight
3. Simplify expand
4. Simplify operators += / -= / + / -
Change-Id: I023aa1bb2905394fbbd29adc7c544d629f9ae2d6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120476
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'tools/source/generic')
-rw-r--r-- | tools/source/generic/gen.cxx | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/tools/source/generic/gen.cxx b/tools/source/generic/gen.cxx index 2edb63c465d9..5196ef0bd96e 100644 --- a/tools/source/generic/gen.cxx +++ b/tools/source/generic/gen.cxx @@ -51,14 +51,14 @@ void tools::Rectangle::SetSize( const Size& rSize ) else if ( rSize.Width() > 0 ) nRight = nLeft + rSize.Width() -1; else - nRight = RECT_EMPTY; + SetWidthEmpty(); if ( rSize.Height() < 0 ) nBottom = nTop + rSize.Height() +1; else if ( rSize.Height() > 0 ) nBottom = nTop + rSize.Height() -1; else - nBottom = RECT_EMPTY; + SetHeightEmpty(); } void tools::Rectangle::SaturatingSetSize(const Size& rSize) @@ -68,26 +68,26 @@ void tools::Rectangle::SaturatingSetSize(const Size& rSize) else if ( rSize.Width() > 0 ) nRight = o3tl::saturating_add(nLeft, (rSize.Width() - 1)); else - nRight = RECT_EMPTY; + SetWidthEmpty(); if ( rSize.Height() < 0 ) nBottom = o3tl::saturating_add(nTop, (rSize.Height() + 1)); else if ( rSize.Height() > 0 ) nBottom = o3tl::saturating_add(nTop, (rSize.Height() - 1)); else - nBottom = RECT_EMPTY; + SetHeightEmpty(); } void tools::Rectangle::SaturatingSetX(tools::Long x) { - if (nRight != RECT_EMPTY) + if (!IsWidthEmpty()) nRight = o3tl::saturating_add(nRight, x - nLeft); nLeft = x; } void tools::Rectangle::SaturatingSetY(tools::Long y) { - if (nBottom != RECT_EMPTY) + if (!IsHeightEmpty()) nBottom = o3tl::saturating_add(nBottom, y - nTop); nTop = y; } @@ -138,12 +138,12 @@ tools::Rectangle& tools::Rectangle::Intersection( const tools::Rectangle& rRect void tools::Rectangle::Justify() { - if ( (nRight < nLeft) && (nRight != RECT_EMPTY) ) + if ((nRight < nLeft) && (!IsWidthEmpty())) { std::swap(nLeft, nRight); } - if ( (nBottom < nTop) && (nBottom != RECT_EMPTY) ) + if ((nBottom < nTop) && (!IsHeightEmpty())) { std::swap(nBottom, nTop); } @@ -198,31 +198,25 @@ OString tools::Rectangle::toString() const void tools::Rectangle::expand(tools::Long nExpandBy) { - nLeft -= nExpandBy; - nTop -= nExpandBy; - if (nRight == RECT_EMPTY) - nRight = nLeft + nExpandBy - 1; - else - nRight += nExpandBy; - if (nBottom == RECT_EMPTY) - nBottom = nTop + nExpandBy - 1; - else - nBottom += nExpandBy; + AdjustLeft(-nExpandBy); + AdjustTop(-nExpandBy); + AdjustRight(nExpandBy); + AdjustBottom(nExpandBy); } void tools::Rectangle::shrink(tools::Long nShrinkBy) { nLeft += nShrinkBy; nTop += nShrinkBy; - if (nRight != RECT_EMPTY) + if (!IsWidthEmpty()) nRight -= nShrinkBy; - if (nBottom != RECT_EMPTY) + if (!IsHeightEmpty()) nBottom -= nShrinkBy; } tools::Long tools::Rectangle::AdjustRight(tools::Long nHorzMoveDelta) { - if (nRight == RECT_EMPTY) + if (IsWidthEmpty()) nRight = nLeft + nHorzMoveDelta - 1; else nRight += nHorzMoveDelta; @@ -231,7 +225,7 @@ tools::Long tools::Rectangle::AdjustRight(tools::Long nHorzMoveDelta) tools::Long tools::Rectangle::AdjustBottom( tools::Long nVertMoveDelta ) { - if (nBottom == RECT_EMPTY) + if (IsHeightEmpty()) nBottom = nTop + nVertMoveDelta - 1; else nBottom += nVertMoveDelta; @@ -240,28 +234,16 @@ tools::Long tools::Rectangle::AdjustBottom( tools::Long nVertMoveDelta ) void tools::Rectangle::setX( tools::Long x ) { - if (nRight != RECT_EMPTY) + if (!IsWidthEmpty()) nRight += x - nLeft; nLeft = x; } void tools::Rectangle::setY( tools::Long y ) { - if (nBottom != RECT_EMPTY) + if (!IsHeightEmpty()) nBottom += y - nTop; nTop = y; } -/// Returns the difference between right and left, assuming the range includes one end, but not the other. -tools::Long tools::Rectangle::getWidth() const -{ - return nRight == RECT_EMPTY ? 0 : nRight - nLeft; -} - -/// Returns the difference between bottom and top, assuming the range includes one end, but not the other. -tools::Long tools::Rectangle::getHeight() const -{ - return nBottom == RECT_EMPTY ? 0 : nBottom - nTop; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |