From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- basegfx/test/B2DPolyPolygonCutterTest.cxx | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 basegfx/test/B2DPolyPolygonCutterTest.cxx (limited to 'basegfx/test/B2DPolyPolygonCutterTest.cxx') diff --git a/basegfx/test/B2DPolyPolygonCutterTest.cxx b/basegfx/test/B2DPolyPolygonCutterTest.cxx new file mode 100644 index 0000000000..b111bf469d --- /dev/null +++ b/basegfx/test/B2DPolyPolygonCutterTest.cxx @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include + +#include + +namespace basegfx +{ +class b2dpolypolygoncutter : public CppUnit::TestFixture +{ +public: + void testMergeToSinglePolyPolygon() + { + { // Adjacent polygons merged to one, closed manually. + B2DPolygon poly1{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 }, { 0, 0 } }; + B2DPolygon poly2{ { 0, 1 }, { 1, 1 }, { 1, 2 }, { 0, 2 }, { 0, 1 } }; + B2DPolyPolygon expected( + B2DPolygon{ { 1, 0 }, { 1, 1 }, { 1, 2 }, { 0, 2 }, { 0, 1 }, { 0, 0 } }); + expected.setClosed(true); + B2DPolyPolygon result + = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1), B2DPolyPolygon(poly2) }); + CPPUNIT_ASSERT_EQUAL(expected, result); + } + + { // Adjacent polygons merged to one, closed using setClosed(). + B2DPolygon poly1{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } }; + B2DPolygon poly2{ { 0, 1 }, { 1, 1 }, { 1, 2 }, { 0, 2 } }; + poly1.setClosed(true); + poly2.setClosed(true); + B2DPolyPolygon expected( + B2DPolygon{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 1, 2 }, { 0, 2 }, { 0, 1 } }); + expected.setClosed(true); + B2DPolyPolygon result + = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1), B2DPolyPolygon(poly2) }); + CPPUNIT_ASSERT_EQUAL(expected, result); + } + + { // Non-adjacent polygons, no merge. + B2DPolygon poly1{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } }; + B2DPolygon poly2{ { 0, 2 }, { 1, 3 }, { 1, 3 }, { 0, 3 } }; + poly1.setClosed(true); + poly2.setClosed(true); + B2DPolyPolygon expected; + expected.append(poly1); + expected.append(poly2); + B2DPolyPolygon result + = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1), B2DPolyPolygon(poly2) }); + CPPUNIT_ASSERT_EQUAL(expected, result); + } + + { // Horizontal and vertical rectangle that together form a cross. + B2DPolygon poly1{ { 1, 0 }, { 2, 0 }, { 2, 3 }, { 1, 3 } }; + B2DPolygon poly2{ { 0, 1 }, { 3, 1 }, { 3, 2 }, { 0, 2 } }; + poly1.setClosed(true); + poly2.setClosed(true); + B2DPolyPolygon expected(B2DPolygon{ { 1, 0 }, + { 2, 0 }, + { 2, 1 }, + { 3, 1 }, + { 3, 2 }, + { 2, 2 }, + { 2, 3 }, + { 1, 3 }, + { 1, 2 }, + { 0, 2 }, + { 0, 1 }, + { 1, 1 } }); + expected.setClosed(true); + B2DPolyPolygon result + = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1), B2DPolyPolygon(poly2) }); + CPPUNIT_ASSERT_EQUAL(expected, result); + } + } + + CPPUNIT_TEST_SUITE(b2dpolypolygoncutter); + CPPUNIT_TEST(testMergeToSinglePolyPolygon); + CPPUNIT_TEST_SUITE_END(); +}; + +} // namespace basegfx + +CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b2dpolypolygoncutter); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3