diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-10-01 10:59:44 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-10-02 00:35:47 +0200 |
commit | 6702e8a93243c4807c80b53965a4397cdbfde8b5 (patch) | |
tree | 7a7d5a1329bd39976873233186f7967ddcc401fa /sw/inc/swrect.hxx | |
parent | 48895bef52bd59e30751ece0c8a8d57ef7864936 (diff) |
add GetUnion/Intersection() to SwRect
This is a more readable and efficient way of first constructing
a copy SwRect and then using Union/Intersection() on it. Named
Get* because that's how tools::Rectangle names them.
Change-Id: Ib3033f1900c48792b23526771a941b4d4c1c07bd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122913
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sw/inc/swrect.hxx')
-rw-r--r-- | sw/inc/swrect.hxx | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sw/inc/swrect.hxx b/sw/inc/swrect.hxx index 039d2b414704..83416cf3969f 100644 --- a/sw/inc/swrect.hxx +++ b/sw/inc/swrect.hxx @@ -79,6 +79,9 @@ public: SwRect &Union( const SwRect& rRect ); SwRect &Intersection( const SwRect& rRect ); + SwRect GetUnion( const SwRect& rRect ) const; + SwRect GetIntersection( const SwRect& rRect ) const; + // Same as Intersection, only assume that Rects are overlapping! SwRect &Intersection_( const SwRect &rRect ); @@ -359,6 +362,26 @@ inline bool SwRect::Overlaps( const SwRect& rRect ) const (Bottom()>= rRect.Top()); } +inline SwRect SwRect::GetUnion( const SwRect& rRect ) const +{ + return SwRect( + Point( std::min( Left(), rRect.Left()), + std::min( Top(), rRect.Top())), + Point( std::max( Right(), rRect.Right()), + std::max( Bottom(), rRect.Bottom()))); +} + +inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const +{ + return Overlaps( rRect ) + ? SwRect( + Point( std::max( Left(), rRect.Left()), + std::max( Top(), rRect.Top())), + Point( std::min( Right(), rRect.Right()), + std::min( Bottom(), rRect.Bottom()))) + : SwRect(); +} + template< typename charT, typename traits > inline std::basic_ostream<charT, traits> & operator <<( |