summaryrefslogtreecommitdiff
path: root/include/tools/gen.hxx
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-08-12 03:43:27 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-08-12 04:48:48 +0200
commit5351e837a11fb9d19759cd1b91ca4b5d43e2f75a (patch)
tree25a8e0702d7d9e613fe62c90a9207f57e87d6834 /include/tools/gen.hxx
parent7ddf7375fb5a8c6699d4128a80b9f24ec6b914ae (diff)
Unify and simplify tools::Rectangle methods returning Point
Make the methods use Left()/Top()/Right()/Bottom(), allowing to avoid explicit checks for emptiness. Also do not use std::min/max in *Center(), so that e.g. TopCenter returns top value the same way as TopLeft and TopRight do. Change-Id: Ie1edd7a0ab7e32b4f98d0c2fb3917ce2902bdf7b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120353 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/tools/gen.hxx')
-rw-r--r--include/tools/gen.hxx93
1 files changed, 15 insertions, 78 deletions
diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx
index 5386de129c56..b8bd6eeb35d4 100644
--- a/include/tools/gen.hxx
+++ b/include/tools/gen.hxx
@@ -474,37 +474,25 @@ public:
static Rectangle Justify( const Point& rLT, const Point& rRB );
- tools::Long Left() const { return nLeft; }
- tools::Long Right() const;
- tools::Long Top() const { return nTop; }
- tools::Long Bottom() const;
+ constexpr tools::Long Left() const { return nLeft; }
+ constexpr tools::Long Right() const { return nRight == RECT_EMPTY ? nLeft : nRight; }
+ constexpr tools::Long Top() const { return nTop; }
+ constexpr tools::Long Bottom() const { return nBottom == RECT_EMPTY ? nTop : nBottom; }
void SetLeft(tools::Long v) { nLeft = v; }
void SetRight(tools::Long v) { nRight = v; }
void SetTop(tools::Long v) { nTop = v; }
void SetBottom(tools::Long v) { nBottom = v; }
- constexpr Point TopLeft() const
- {
- return Point( nLeft, nTop );
- }
- constexpr Point TopRight() const
- {
- return Point( (nRight == RECT_EMPTY) ? nLeft : nRight, nTop );
- }
- constexpr Point TopCenter() const
- {
- if (IsEmpty())
- return Point(nLeft, nTop);
- else
- return Point((nLeft + nRight) / 2, std::min(nTop, nBottom));
- }
- inline Point BottomLeft() const;
- inline Point BottomRight() const;
- inline Point BottomCenter() const;
- inline Point LeftCenter() const;
- inline Point RightCenter() const;
- inline Point Center() const;
+ constexpr Point TopLeft() const { return { Left(), Top() }; }
+ constexpr Point TopRight() const { return { Right(), Top() }; }
+ constexpr Point TopCenter() const { return { (Left() + Right()) / 2, Top() }; }
+ constexpr Point BottomLeft() const { return { Left(), Bottom() }; }
+ constexpr Point BottomRight() const { return { Right(), Bottom() }; }
+ constexpr Point BottomCenter() const { return { (Left() + Right()) / 2, Bottom() }; }
+ constexpr Point LeftCenter() const { return { Left(), (Top() + Bottom()) / 2 }; }
+ constexpr Point RightCenter() const { return { Right(), (Top() + Bottom()) / 2 }; }
+ constexpr Point Center() const { return { (Left() + Right()) / 2, (Top() + Bottom()) / 2 }; }
/// Move the top and left edges by a delta, preserving width and height
inline void Move( tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta );
@@ -516,10 +504,7 @@ public:
inline void SetPos( const Point& rPoint );
void SetSize( const Size& rSize );
- constexpr Size GetSize() const
- {
- return Size(GetWidth(), GetHeight());
- }
+ constexpr Size GetSize() const { return { GetWidth(), GetHeight() }; }
/// Returns the difference between right and left, assuming the range is inclusive.
constexpr tools::Long GetWidth() const
@@ -569,7 +554,7 @@ public:
void SetEmpty() { nRight = nBottom = RECT_EMPTY; }
void SetWidthEmpty() { nRight = RECT_EMPTY; }
void SetHeightEmpty() { nBottom = RECT_EMPTY; }
- constexpr bool IsEmpty() const;
+ constexpr bool IsEmpty() const { return (nRight == RECT_EMPTY) || (nBottom == RECT_EMPTY); }
bool IsWidthEmpty() const { return nRight == RECT_EMPTY; }
bool IsHeightEmpty() const { return nBottom == RECT_EMPTY; }
@@ -655,54 +640,6 @@ constexpr inline tools::Rectangle::Rectangle( const Point& rLT, const Size& rSiz
, nBottom( rSize.Height() ? nTop+(rSize.Height()-1) : RECT_EMPTY )
{}
-constexpr inline bool tools::Rectangle::IsEmpty() const
-{
- return (nRight == RECT_EMPTY) || (nBottom == RECT_EMPTY);
-}
-
-inline Point tools::Rectangle::BottomLeft() const
-{
- return Point( nLeft, (nBottom == RECT_EMPTY) ? nTop : nBottom );
-}
-
-inline Point tools::Rectangle::BottomRight() const
-{
- return Point( (nRight == RECT_EMPTY) ? nLeft : nRight,
- (nBottom == RECT_EMPTY) ? nTop : nBottom );
-}
-
-inline Point tools::Rectangle::BottomCenter() const
-{
- if ( IsEmpty() )
- return Point( nLeft, nTop );
- else
- return Point((nLeft + nRight) / 2, std::max(nTop, nBottom));
-}
-
-inline Point tools::Rectangle::LeftCenter() const
-{
- if ( IsEmpty() )
- return Point( nLeft, nTop );
- else
- return Point(std::min(nLeft, nRight), (nTop + nBottom) / 2);
-}
-
-inline Point tools::Rectangle::RightCenter() const
-{
- if ( IsEmpty() )
- return Point( nLeft, nTop );
- else
- return Point(std::max(nLeft, nRight), (nTop + nBottom) / 2);
-}
-
-inline Point tools::Rectangle::Center() const
-{
- if ( IsEmpty() )
- return Point( nLeft, nTop );
- else
- return Point((nLeft + nRight) / 2, (nTop + nBottom) / 2);
-}
-
inline void tools::Rectangle::Move( tools::Long nHorzMove, tools::Long nVertMove )
{
nLeft += nHorzMove;