diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-09-17 21:49:21 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-09-20 12:10:44 +0200 |
commit | b22d4785310eac35696df771803dfba0871a50ac (patch) | |
tree | 56e394a3c38a2e1f17530fbc18dd8e6b3c5d5098 /tools | |
parent | 3e2370260f2b79c43b4f8a86b123861aa95d3ef2 (diff) |
clean up ambiguous confusing rectangle APIs like IsInside()
Reading 'rectA.IsInside( rectB )' kind of suggests that the code
checks whether 'rectA is inside rectB', but it's actually the other
way around. Rename IsInside() -> Contains(), IsOver() -> Overlaps(),
which should make it clear which way the logic goes.
Change-Id: I9347450fe7dc34c96df6d636a4e3e660de1801ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122271
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qa/cppunit/test_rectangle.cxx | 15 | ||||
-rw-r--r-- | tools/source/generic/gen.cxx | 8 | ||||
-rw-r--r-- | tools/source/generic/poly.cxx | 4 | ||||
-rw-r--r-- | tools/source/memtools/multisel.cxx | 18 |
4 files changed, 30 insertions, 15 deletions
diff --git a/tools/qa/cppunit/test_rectangle.cxx b/tools/qa/cppunit/test_rectangle.cxx index e213ed28daf8..2b6518d797c4 100644 --- a/tools/qa/cppunit/test_rectangle.cxx +++ b/tools/qa/cppunit/test_rectangle.cxx @@ -92,6 +92,21 @@ void Test::test_rectangle() static_assert(aRectMm100.GetWidth() == 0); static_assert(aRectMm100.GetHeight() == 0); } + + { + constexpr tools::Rectangle rect(Point(0, 0), Size(20, 20)); + constexpr tools::Rectangle inside(Point(10, 10), Size(10, 10)); + constexpr tools::Rectangle overlap(Point(10, 10), Size(20, 20)); + constexpr tools::Rectangle outside(Point(20, 20), Size(10, 10)); + CPPUNIT_ASSERT(rect.Contains(inside)); + CPPUNIT_ASSERT(rect.Contains(rect)); + CPPUNIT_ASSERT(!rect.Contains(overlap)); + CPPUNIT_ASSERT(!rect.Contains(outside)); + CPPUNIT_ASSERT(rect.Overlaps(inside)); + CPPUNIT_ASSERT(rect.Overlaps(rect)); + CPPUNIT_ASSERT(rect.Overlaps(overlap)); + CPPUNIT_ASSERT(!rect.Overlaps(outside)); + } } CPPUNIT_TEST_SUITE_REGISTRATION(Test); diff --git a/tools/source/generic/gen.cxx b/tools/source/generic/gen.cxx index 9c9c04903f19..1fe47071d4ce 100644 --- a/tools/source/generic/gen.cxx +++ b/tools/source/generic/gen.cxx @@ -140,7 +140,7 @@ void tools::Rectangle::Justify() } } -bool tools::Rectangle::IsInside( const Point& rPoint ) const +bool tools::Rectangle::Contains( const Point& rPoint ) const { if ( IsEmpty() ) return false; @@ -168,12 +168,12 @@ bool tools::Rectangle::IsInside( const Point& rPoint ) const return true; } -bool tools::Rectangle::IsInside( const tools::Rectangle& rRect ) const +bool tools::Rectangle::Contains( const tools::Rectangle& rRect ) const { - return IsInside( rRect.TopLeft() ) && IsInside( rRect.BottomRight() ); + return Contains( rRect.TopLeft() ) && Contains( rRect.BottomRight() ); } -bool tools::Rectangle::IsOver( const tools::Rectangle& rRect ) const +bool tools::Rectangle::Overlaps( const tools::Rectangle& rRect ) const { // If there's no intersection, they don't overlap return !GetIntersection( rRect ).IsEmpty(); diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx index ab33eb61021b..8128491ac8cd 100644 --- a/tools/source/generic/poly.cxx +++ b/tools/source/generic/poly.cxx @@ -1494,7 +1494,7 @@ tools::Rectangle Polygon::GetBoundRect() const return tools::Rectangle( nXMin, nYMin, nXMax, nYMax ); } -bool Polygon::IsInside( const Point& rPoint ) const +bool Polygon::Contains( const Point& rPoint ) const { DBG_ASSERT( !mpImplPolygon->mxFlagAry, "IsInside could fail with beziers!" ); @@ -1503,7 +1503,7 @@ bool Polygon::IsInside( const Point& rPoint ) const sal_uInt16 nCount = mpImplPolygon->mnPoints; sal_uInt16 nPCounter = 0; - if ( ( nCount > 2 ) && aBound.IsInside( rPoint ) ) + if ( ( nCount > 2 ) && aBound.Contains( rPoint ) ) { Point aPt1( mpImplPolygon->mxPointAry[ 0 ] ); Point aIntersection; diff --git a/tools/source/memtools/multisel.cxx b/tools/source/memtools/multisel.cxx index 4f915da258a4..faa78f78144a 100644 --- a/tools/source/memtools/multisel.cxx +++ b/tools/source/memtools/multisel.cxx @@ -136,10 +136,10 @@ void MultiSelection::SelectAll( bool bSelect ) bool MultiSelection::Select( sal_Int32 nIndex, bool bSelect ) { - DBG_ASSERT( aTotRange.IsInside(nIndex), "selected index out of range" ); + DBG_ASSERT( aTotRange.Contains(nIndex), "selected index out of range" ); // out of range? - if ( !aTotRange.IsInside(nIndex) ) + if ( !aTotRange.Contains(nIndex) ) return false; // find the virtual target position @@ -148,7 +148,7 @@ bool MultiSelection::Select( sal_Int32 nIndex, bool bSelect ) if ( bSelect ) { // is it included in the found sub selection? - if ( nSubSelPos < sal_Int32(aSels.size()) && aSels[ nSubSelPos ].IsInside( nIndex ) ) + if ( nSubSelPos < sal_Int32(aSels.size()) && aSels[ nSubSelPos ].Contains( nIndex ) ) // already selected, nothing to do return false; @@ -187,7 +187,7 @@ bool MultiSelection::Select( sal_Int32 nIndex, bool bSelect ) { // is it excluded from the found sub selection? if ( nSubSelPos >= sal_Int32(aSels.size()) - || !aSels[ nSubSelPos ].IsInside( nIndex ) + || !aSels[ nSubSelPos ].Contains( nIndex ) ) { // not selected, nothing to do return false; @@ -234,8 +234,8 @@ void MultiSelection::Select( const Range& rIndexRange, bool bSelect ) sal_Int32 nTmpMax = rIndexRange.Max(); sal_Int32 nCurMin = FirstSelected(); sal_Int32 nCurMax = LastSelected(); - DBG_ASSERT(aTotRange.IsInside(nTmpMax), "selected index out of range" ); - DBG_ASSERT(aTotRange.IsInside(nTmpMin), "selected index out of range" ); + DBG_ASSERT(aTotRange.Contains(nTmpMax), "selected index out of range" ); + DBG_ASSERT(aTotRange.Contains(nTmpMin), "selected index out of range" ); // replace whole selection? if( aSels.empty() || (nTmpMin <= nCurMin && nTmpMax >= nCurMax ) ) @@ -306,7 +306,7 @@ bool MultiSelection::IsSelected( sal_Int32 nIndex ) const // find the virtual target position sal_Int32 nSubSelPos = ImplFindSubSelection( nIndex ); - return nSubSelPos < sal_Int32(aSels.size()) && aSels[ nSubSelPos ].IsInside(nIndex); + return nSubSelPos < sal_Int32(aSels.size()) && aSels[ nSubSelPos ].Contains(nIndex); } void MultiSelection::Insert( sal_Int32 nIndex, sal_Int32 nCount ) @@ -318,7 +318,7 @@ void MultiSelection::Insert( sal_Int32 nIndex, sal_Int32 nCount ) if ( nSubSelPos < sal_Int32(aSels.size()) ) { // did we insert an unselected into an existing sub selection? if ( aSels[ nSubSelPos ].Min() != nIndex - && aSels[ nSubSelPos ].IsInside(nIndex) + && aSels[ nSubSelPos ].Contains(nIndex) ) { // split the sub selection if ( nSubSelPos < sal_Int32(aSels.size()) ) { aSels.insert( aSels.begin() + nSubSelPos, Range( aSels[ nSubSelPos ].Min(), nIndex-1 ) ); @@ -348,7 +348,7 @@ void MultiSelection::Remove( sal_Int32 nIndex ) // did we remove from an existing sub selection? if ( nSubSelPos < sal_Int32(aSels.size()) - && aSels[ nSubSelPos ].IsInside(nIndex) + && aSels[ nSubSelPos ].Contains(nIndex) ) { // does this sub selection only contain the index to be deleted if ( aSels[ nSubSelPos ].Len() == 1 ) { |