[Libreoffice-commits] core.git: sw/inc sw/qa sw/source
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Fri Oct 1 22:36:37 UTC 2021
sw/inc/swrect.hxx | 2 +-
sw/qa/core/test_rect.cxx | 18 ++++++++++++++++++
sw/source/core/bastyp/swrect.cxx | 7 +++++++
3 files changed, 26 insertions(+), 1 deletion(-)
New commits:
commit 01807ad5e04966abeb396b7599cbbbf822de6a03
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Oct 1 12:30:15 2021 +0200
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Sat Oct 2 00:36:00 2021 +0200
fix SwRect::Union() with empty SwRect
Empty SwRect is technically located at (0,0), so make sure
the position of the union is not moved to include that.
Change-Id: I4905c11c3d9f989d4448704e3cb8b297e45bc569
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122914
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/sw/inc/swrect.hxx b/sw/inc/swrect.hxx
index 83416cf3969f..f6d8430b9d11 100644
--- a/sw/inc/swrect.hxx
+++ b/sw/inc/swrect.hxx
@@ -364,7 +364,7 @@ inline bool SwRect::Overlaps( const SwRect& rRect ) const
inline SwRect SwRect::GetUnion( const SwRect& rRect ) const
{
- return SwRect(
+ return IsEmpty() ? rRect : rRect.IsEmpty() ? *this : SwRect(
Point( std::min( Left(), rRect.Left()),
std::min( Top(), rRect.Top())),
Point( std::max( Right(), rRect.Right()),
diff --git a/sw/qa/core/test_rect.cxx b/sw/qa/core/test_rect.cxx
index 3c6a47907915..755dbb91bb6e 100644
--- a/sw/qa/core/test_rect.cxx
+++ b/sw/qa/core/test_rect.cxx
@@ -42,6 +42,15 @@ void RectUnittest::testUnion()
tmp.Union(rect3);
CPPUNIT_ASSERT_EQUAL(SwRect(Point(10, 10), Size(30, 30)), tmp);
CPPUNIT_ASSERT_EQUAL(SwRect(Point(10, 10), Size(30, 30)), rect1.GetUnion(rect3));
+
+ tmp = rect1;
+ tmp.Union(SwRect());
+ CPPUNIT_ASSERT_EQUAL(rect1, tmp);
+ CPPUNIT_ASSERT_EQUAL(rect1, rect1.GetUnion(SwRect()));
+ tmp = SwRect();
+ tmp.Union(rect1);
+ CPPUNIT_ASSERT_EQUAL(rect1, tmp);
+ CPPUNIT_ASSERT_EQUAL(rect1, SwRect().GetUnion(rect1));
}
void RectUnittest::testIntersection()
@@ -60,6 +69,15 @@ void RectUnittest::testIntersection()
tmp.Intersection(rect3);
CPPUNIT_ASSERT(tmp.IsEmpty());
CPPUNIT_ASSERT(rect1.GetIntersection(rect3).IsEmpty());
+
+ tmp = rect1;
+ tmp.Intersection(SwRect());
+ CPPUNIT_ASSERT(tmp.IsEmpty());
+ CPPUNIT_ASSERT(rect1.GetIntersection(SwRect()).IsEmpty());
+ tmp = SwRect();
+ tmp.Intersection(rect1);
+ CPPUNIT_ASSERT(tmp.IsEmpty());
+ CPPUNIT_ASSERT(SwRect().GetIntersection(rect1).IsEmpty());
}
CPPUNIT_TEST_SUITE_REGISTRATION(RectUnittest);
diff --git a/sw/source/core/bastyp/swrect.cxx b/sw/source/core/bastyp/swrect.cxx
index 0825696f45c6..8f7131aae47c 100644
--- a/sw/source/core/bastyp/swrect.cxx
+++ b/sw/source/core/bastyp/swrect.cxx
@@ -34,6 +34,13 @@ SwRect::SwRect( const tools::Rectangle &rRect ) :
SwRect& SwRect::Union( const SwRect& rRect )
{
+ if( rRect.IsEmpty())
+ return *this;
+ if( IsEmpty())
+ {
+ *this = rRect;
+ return *this;
+ }
if ( Top() > rRect.Top() )
Top( rRect.Top() );
if ( Left() > rRect.Left() )
More information about the Libreoffice-commits
mailing list