include/tools/gen.hxx        |   93 ++++++-------------------------------------
 tools/source/generic/gen.cxx |   10 ----
 2 files changed, 15 insertions(+), 88 deletions(-)

New commits:
commit 5351e837a11fb9d19759cd1b91ca4b5d43e2f75a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Aug 12 03:43:27 2021 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Aug 12 04:48:48 2021 +0200

    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.kagan...@collabora.com>

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;
diff --git a/tools/source/generic/gen.cxx b/tools/source/generic/gen.cxx
index 1740f4b306f1..2edb63c465d9 100644
--- a/tools/source/generic/gen.cxx
+++ b/tools/source/generic/gen.cxx
@@ -252,16 +252,6 @@ void tools::Rectangle::setY( tools::Long y )
     nTop  = y;
 }
 
-tools::Long tools::Rectangle::Right() const
-{
-    return nRight == RECT_EMPTY ? nLeft : nRight;
-}
-
-tools::Long tools::Rectangle::Bottom() const
-{
-    return nBottom == RECT_EMPTY ? nTop : nBottom;
-}
-
 /// Returns the difference between right and left, assuming the range includes 
one end, but not the other.
 tools::Long tools::Rectangle::getWidth() const
 {

Reply via email to