include/svx/svdpagv.hxx | 10 +-- svx/source/svdraw/svdpagv.cxx | 14 ++-- tools/qa/cppunit/test_rectangle.cxx | 117 ++++++++++++++++++++++++------------ 3 files changed, 92 insertions(+), 49 deletions(-)
New commits: commit eff28a8a170759867916d7455b14e6a66a37daff Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Nov 22 13:13:53 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sun Jan 29 14:23:48 2023 +0000 tools: rearrange Rectangle test, add construction test case Change-Id: I735600181665100e8540b6f5f14ffebfe6f33371 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146305 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/tools/qa/cppunit/test_rectangle.cxx b/tools/qa/cppunit/test_rectangle.cxx index 02b355ad0576..12e46910bc2f 100644 --- a/tools/qa/cppunit/test_rectangle.cxx +++ b/tools/qa/cppunit/test_rectangle.cxx @@ -14,10 +14,13 @@ namespace { -class Test : public CppUnit::TestFixture +class RectangleTest : public CppUnit::TestFixture { public: - void test_rectangle(); + void testConstruction(); + void testOpenClosedSize(); + void testUnitConvesion(); + void testSetOperators(); void test_rectnormalize_alreadynormal(); void test_rectnormalize_zerorect(); void test_rectnormalize_reverse_topleft_bottomright(); @@ -26,8 +29,11 @@ public: void test_rectnormalize_zerowidth_top_bottom_reversed(); void test_rectnormalize_zeroheight_left_right_reversed(); - CPPUNIT_TEST_SUITE(Test); - CPPUNIT_TEST(test_rectangle); + CPPUNIT_TEST_SUITE(RectangleTest); + CPPUNIT_TEST(testConstruction); + CPPUNIT_TEST(testOpenClosedSize); + CPPUNIT_TEST(testUnitConvesion); + CPPUNIT_TEST(testSetOperators); CPPUNIT_TEST(test_rectnormalize_zerorect); CPPUNIT_TEST(test_rectnormalize_alreadynormal); CPPUNIT_TEST(test_rectnormalize_reverse_topleft_bottomright); @@ -38,7 +44,49 @@ public: CPPUNIT_TEST_SUITE_END(); }; -void Test::test_rectangle() +void RectangleTest::testConstruction() +{ + { + tools::Rectangle aRect1(Point(), Size(0, 20)); + CPPUNIT_ASSERT_EQUAL(true, aRect1.IsEmpty()); + CPPUNIT_ASSERT_EQUAL(tools::Long(0), aRect1.getOpenWidth()); + + tools::Rectangle aRect2{ Point(), Point(0, 20) }; + CPPUNIT_ASSERT_EQUAL(false, aRect2.IsEmpty()); + CPPUNIT_ASSERT_EQUAL(tools::Long(0), aRect2.getOpenWidth()); + + tools::Rectangle aRect3(0, 0, 0, 20); + CPPUNIT_ASSERT_EQUAL(false, aRect3.IsEmpty()); + CPPUNIT_ASSERT_EQUAL(tools::Long(0), aRect3.getOpenWidth()); + } + { + constexpr tools::Rectangle aRect(Point(), Size(-1, -2)); + static_assert(!aRect.IsEmpty()); + static_assert(aRect.Right() == 0); + static_assert(aRect.Bottom() == -1); + + tools::Rectangle aRect2; + aRect2.SetSize(Size(-1, -2)); + CPPUNIT_ASSERT_EQUAL(aRect, aRect2); + + constexpr tools::Rectangle aRect3(Point(), Size(0, 0)); + static_assert(aRect3.IsEmpty()); + static_assert(aRect3.Right() == 0); + static_assert(aRect3.Bottom() == 0); + + constexpr tools::Rectangle aRect4(Point(), Size(1, 1)); + static_assert(!aRect4.IsEmpty()); + static_assert(aRect4.Right() == 0); + static_assert(aRect4.Bottom() == 0); + + constexpr tools::Rectangle aRect5(Point(), Size(-1, -1)); + static_assert(!aRect5.IsEmpty()); + static_assert(aRect5.Right() == 0); + static_assert(aRect5.Bottom() == 0); + } +} + +void RectangleTest::testOpenClosedSize() { { tools::Rectangle aRect(1, 1, 1, 1); @@ -71,18 +119,10 @@ void Test::test_rectangle() aRect.SetPosY(12); CPPUNIT_ASSERT_EQUAL(tools::Long(1), aRect.GetWidth()); } +} - { - constexpr tools::Rectangle aRect(Point(), Size(-1, -2)); - static_assert(!aRect.IsEmpty()); - static_assert(aRect.Right() == 0); - static_assert(aRect.Bottom() == -1); - - tools::Rectangle aRect2; - aRect2.SetSize(Size(-1, -2)); - CPPUNIT_ASSERT_EQUAL(aRect, aRect2); - } - +void RectangleTest::testUnitConvesion() +{ { constexpr tools::Rectangle aRectTwip(100, 100, 100, 100); constexpr tools::Rectangle aRectMm100( @@ -106,24 +146,25 @@ 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)); - } +void RectangleTest::testSetOperators() +{ + 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)); } -void Test::test_rectnormalize_alreadynormal() +void RectangleTest::test_rectnormalize_alreadynormal() { Point aTopLeft(0, 0); Point aBottomRight(1, 1); @@ -135,7 +176,7 @@ void Test::test_rectnormalize_alreadynormal() CPPUNIT_ASSERT_EQUAL(aRect.BottomRight(), aBottomRight); } -void Test::test_rectnormalize_zerorect() +void RectangleTest::test_rectnormalize_zerorect() { Point aTopLeft(53, 53); Point aBottomRight(53, 53); @@ -147,7 +188,7 @@ void Test::test_rectnormalize_zerorect() CPPUNIT_ASSERT_EQUAL(aRect.BottomRight(), aBottomRight); } -void Test::test_rectnormalize_reverse_topleft_bottomright() +void RectangleTest::test_rectnormalize_reverse_topleft_bottomright() { Point aPoint1(1, 1); Point aPoint2(0, 0); @@ -159,7 +200,7 @@ void Test::test_rectnormalize_reverse_topleft_bottomright() CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 1), aRect.BottomRight()); } -void Test::test_rectnormalize_topright_bottomleft() +void RectangleTest::test_rectnormalize_topright_bottomleft() { Point aPoint1(1, 0); Point aPoint2(0, 1); @@ -171,7 +212,7 @@ void Test::test_rectnormalize_topright_bottomleft() CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 1), aRect.BottomRight()); } -void Test::test_rectnormalize_bottomleft_topright() +void RectangleTest::test_rectnormalize_bottomleft_topright() { Point aPoint1(0, 1); Point aPoint2(1, 0); @@ -183,7 +224,7 @@ void Test::test_rectnormalize_bottomleft_topright() CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 1), aRect.BottomRight()); } -void Test::test_rectnormalize_zerowidth_top_bottom_reversed() +void RectangleTest::test_rectnormalize_zerowidth_top_bottom_reversed() { Point aPoint1(0, 1); Point aPoint2(0, 0); @@ -195,7 +236,7 @@ void Test::test_rectnormalize_zerowidth_top_bottom_reversed() CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(0, 1), aRect.BottomRight()); } -void Test::test_rectnormalize_zeroheight_left_right_reversed() +void RectangleTest::test_rectnormalize_zeroheight_left_right_reversed() { Point aPoint1(1, 0); Point aPoint2(0, 0); @@ -207,7 +248,7 @@ void Test::test_rectnormalize_zeroheight_left_right_reversed() CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 0), aRect.BottomRight()); } -CPPUNIT_TEST_SUITE_REGISTRATION(Test); +CPPUNIT_TEST_SUITE_REGISTRATION(RectangleTest); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 0119d00daa9713ada2b92e38adeb083c0bdcba64 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Sep 16 13:33:09 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sun Jan 29 14:23:40 2023 +0000 svx: add prefix m to aPgOrg and rename to aPageOrigin Change-Id: I1df0c61aca724748680017472cde64832742eb97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146304 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/svdpagv.hxx b/include/svx/svdpagv.hxx index 2f77dfa6692a..777ca7d9b1b2 100644 --- a/include/svx/svdpagv.hxx +++ b/include/svx/svdpagv.hxx @@ -57,7 +57,7 @@ class SVXCORE_DLLPUBLIC SdrPageView private: SdrView& mrView; SdrPage* mpPage; - Point aPgOrg; // The Page's point of origin + Point maPageOrigin; // The Page's point of origin tools::Rectangle aMarkBound; tools::Rectangle aMarkSnap; @@ -199,12 +199,12 @@ public: bool IsReadOnly() const; /// The Origin always refers to the upper left corner of the Page - const Point& GetPageOrigin() const { return aPgOrg; } + const Point& GetPageOrigin() const { return maPageOrigin; } void SetPageOrigin(const Point& rOrg); - void LogicToPagePos(Point& rPnt) const { rPnt-=aPgOrg; } - void LogicToPagePos(tools::Rectangle& rRect) const { rRect.Move(-aPgOrg.X(),-aPgOrg.Y()); } - void PagePosToLogic(Point& rPnt) const { rPnt+=aPgOrg; } + void LogicToPagePos(Point& rPnt) const { rPnt-=maPageOrigin; } + void LogicToPagePos(tools::Rectangle& rRect) const { rRect.Move(-maPageOrigin.X(),-maPageOrigin.Y()); } + void PagePosToLogic(Point& rPnt) const { rPnt+=maPageOrigin; } void SetVisibleLayers(const SdrLayerIDSet& rSet) { aLayerVisi=rSet; } const SdrLayerIDSet& GetVisibleLayers() const { return aLayerVisi; } diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx index 60cd8cfe8ca0..14acfd4a993b 100644 --- a/svx/source/svdraw/svdpagv.cxx +++ b/svx/source/svdraw/svdpagv.cxx @@ -96,8 +96,8 @@ SdrPageView::SdrPageView(SdrPage* pPage1, SdrView& rNewView) if(mpPage) { - aPgOrg.setX(mpPage->GetLeftBorder() ); - aPgOrg.setY(mpPage->GetUpperBorder() ); + maPageOrigin.setX(mpPage->GetLeftBorder() ); + maPageOrigin.setY(mpPage->GetUpperBorder() ); } // For example, in the case of charts, there is a LayerAdmin, but it has no valid values. Therefore // a solution like pLayerAdmin->getVisibleLayersODF(aLayerVisi) is not possible. So use the @@ -439,7 +439,7 @@ void SdrPageView::DrawPageViewGrid(OutputDevice& rOut, const tools::Rectangle& r tools::Long nWrX=0; tools::Long nWrY=0; - Point aOrg(aPgOrg); + Point aOrg(maPageOrigin); tools::Long x1 = 0; tools::Long x2 = 0; if (GetPage()->GetWidth() < 0) // ScDrawPage of RTL sheet @@ -639,9 +639,11 @@ bool SdrPageView::IsObjMarkable(SdrObject const * pObj) const void SdrPageView::SetPageOrigin(const Point& rOrg) { - if (rOrg!=aPgOrg) { - aPgOrg=rOrg; - if (GetView().IsGridVisible()) { + if (rOrg != maPageOrigin) + { + maPageOrigin = rOrg; + if (GetView().IsGridVisible()) + { InvalidateAllWin(); } }