1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppunit/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
28 class b2dpolypolygoncutter
: public CppUnit::TestFixture
31 void testMergeToSinglePolyPolygon()
33 { // Adjacent polygons merged to one, closed manually.
34 B2DPolygon poly1
{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 }, { 0, 0 } };
35 B2DPolygon poly2
{ { 0, 1 }, { 1, 1 }, { 1, 2 }, { 0, 2 }, { 0, 1 } };
36 B2DPolyPolygon
expected(
37 B2DPolygon
{ { 1, 0 }, { 1, 1 }, { 1, 2 }, { 0, 2 }, { 0, 1 }, { 0, 0 } });
38 expected
.setClosed(true);
40 = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1
), B2DPolyPolygon(poly2
) });
41 CPPUNIT_ASSERT_EQUAL(expected
, result
);
44 { // Adjacent polygons merged to one, closed using setClosed().
45 B2DPolygon poly1
{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
46 B2DPolygon poly2
{ { 0, 1 }, { 1, 1 }, { 1, 2 }, { 0, 2 } };
47 poly1
.setClosed(true);
48 poly2
.setClosed(true);
49 B2DPolyPolygon
expected(
50 B2DPolygon
{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 1, 2 }, { 0, 2 }, { 0, 1 } });
51 expected
.setClosed(true);
53 = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1
), B2DPolyPolygon(poly2
) });
54 CPPUNIT_ASSERT_EQUAL(expected
, result
);
57 { // Non-adjacent polygons, no merge.
58 B2DPolygon poly1
{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
59 B2DPolygon poly2
{ { 0, 2 }, { 1, 3 }, { 1, 3 }, { 0, 3 } };
60 poly1
.setClosed(true);
61 poly2
.setClosed(true);
62 B2DPolyPolygon expected
;
63 expected
.append(poly1
);
64 expected
.append(poly2
);
66 = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1
), B2DPolyPolygon(poly2
) });
67 CPPUNIT_ASSERT_EQUAL(expected
, result
);
70 { // Horizontal and vertical rectangle that together form a cross.
71 B2DPolygon poly1
{ { 1, 0 }, { 2, 0 }, { 2, 3 }, { 1, 3 } };
72 B2DPolygon poly2
{ { 0, 1 }, { 3, 1 }, { 3, 2 }, { 0, 2 } };
73 poly1
.setClosed(true);
74 poly2
.setClosed(true);
75 B2DPolyPolygon
expected(B2DPolygon
{ { 1, 0 },
87 expected
.setClosed(true);
89 = utils::mergeToSinglePolyPolygon({ B2DPolyPolygon(poly1
), B2DPolyPolygon(poly2
) });
90 CPPUNIT_ASSERT_EQUAL(expected
, result
);
94 CPPUNIT_TEST_SUITE(b2dpolypolygoncutter
);
95 CPPUNIT_TEST(testMergeToSinglePolyPolygon
);
96 CPPUNIT_TEST_SUITE_END();
99 } // namespace basegfx
101 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b2dpolypolygoncutter
);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */