xref: /aoo42x/main/basegfx/test/genericclipper.cxx (revision 09dbbe93)
1*09dbbe93SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*09dbbe93SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*09dbbe93SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*09dbbe93SAndrew Rist  * distributed with this work for additional information
6*09dbbe93SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*09dbbe93SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*09dbbe93SAndrew Rist  * "License"); you may not use this file except in compliance
9*09dbbe93SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*09dbbe93SAndrew Rist  *
11*09dbbe93SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*09dbbe93SAndrew Rist  *
13*09dbbe93SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*09dbbe93SAndrew Rist  * software distributed under the License is distributed on an
15*09dbbe93SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*09dbbe93SAndrew Rist  * KIND, either express or implied.  See the License for the
17*09dbbe93SAndrew Rist  * specific language governing permissions and limitations
18*09dbbe93SAndrew Rist  * under the License.
19*09dbbe93SAndrew Rist  *
20*09dbbe93SAndrew Rist  *************************************************************/
21*09dbbe93SAndrew Rist 
22*09dbbe93SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_basegfx.hxx"
27cdf0e10cSrcweir // autogenerated file with codegen.pl
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "preextstl.h"
30cdf0e10cSrcweir #include "cppunit/TestAssert.h"
31cdf0e10cSrcweir #include "cppunit/TestFixture.h"
32cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h"
33cdf0e10cSrcweir #include "postextstl.h"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
36cdf0e10cSrcweir #include <basegfx/curve/b2dcubicbezier.hxx>
37cdf0e10cSrcweir #include <basegfx/curve/b2dbeziertools.hxx>
38cdf0e10cSrcweir #include <basegfx/range/b2dpolyrange.hxx>
39cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
40cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
41cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
42cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
43cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygonclipper.hxx>
44cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
45cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <boost/bind.hpp>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir using namespace ::basegfx;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace basegfx2d
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 
55cdf0e10cSrcweir class genericclipper : public CppUnit::TestFixture
56cdf0e10cSrcweir {
57cdf0e10cSrcweir private:
58cdf0e10cSrcweir     B2DPolygon aSelfIntersecting;
59cdf0e10cSrcweir     B2DPolygon aShiftedRectangle;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir public:
62cdf0e10cSrcweir     // initialise your test code values here.
63cdf0e10cSrcweir     void setUp()
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(0,  0));
66cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(0,  100));
67cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(75, 100));
68cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(75, 50));
69cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(25, 50));
70cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(25, 150));
71cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(100,150));
72cdf0e10cSrcweir         aSelfIntersecting.append(B2DPoint(100,0));
73cdf0e10cSrcweir         aSelfIntersecting.setClosed(true);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         aShiftedRectangle = tools::createPolygonFromRect(
76cdf0e10cSrcweir             B2DRange(0,90,20,150));
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     void tearDown()
80cdf0e10cSrcweir     {}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     void validate(const char* pName,
83cdf0e10cSrcweir                   const char* pValidSvgD,
84cdf0e10cSrcweir                   B2DPolyPolygon (*pFunc)(const B2DPolyPolygon&, const B2DPolyPolygon&))
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         const B2DPolyPolygon aSelfIntersect(
87cdf0e10cSrcweir             tools::prepareForPolygonOperation(aSelfIntersecting));
88cdf0e10cSrcweir         const B2DPolyPolygon aRect(
89cdf0e10cSrcweir             tools::prepareForPolygonOperation(aShiftedRectangle));
90cdf0e10cSrcweir #if defined(VERBOSE)
91cdf0e10cSrcweir         fprintf(stderr, "%s input LHS - svg:d=\"%s\"\n",
92cdf0e10cSrcweir                 pName, rtl::OUStringToOString(
93cdf0e10cSrcweir                     basegfx::tools::exportToSvgD(
94cdf0e10cSrcweir                         aSelfIntersect),
95cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8).getStr() );
96cdf0e10cSrcweir         fprintf(stderr, "%s input RHS - svg:d=\"%s\"\n",
97cdf0e10cSrcweir                 pName, rtl::OUStringToOString(
98cdf0e10cSrcweir                     basegfx::tools::exportToSvgD(
99cdf0e10cSrcweir                         aRect),
100cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8).getStr() );
101cdf0e10cSrcweir #endif
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         const B2DPolyPolygon aRes=
104cdf0e10cSrcweir             pFunc(aSelfIntersect, aRect);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir #if defined(VERBOSE)
107cdf0e10cSrcweir         fprintf(stderr, "%s - svg:d=\"%s\"\n",
108cdf0e10cSrcweir                 pName, rtl::OUStringToOString(
109cdf0e10cSrcweir                     basegfx::tools::exportToSvgD(aRes),
110cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8).getStr() );
111cdf0e10cSrcweir #endif
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         rtl::OUString aValid=rtl::OUString::createFromAscii(pValidSvgD);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE(pName,
116cdf0e10cSrcweir                                basegfx::tools::exportToSvgD(aRes) == aValid);
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     void validateOr()
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm75 10v-50h-50v50z";
122cdf0e10cSrcweir         validate("validateOr", pValid, &tools::solvePolygonOperationOr);
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     void validateXor()
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm0 10h20v-10h-20zm75 10v-50h-50v50z";
128cdf0e10cSrcweir         validate("validateXor", pValid, &tools::solvePolygonOperationXor);
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     void validateAnd()
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         const char* pValid="m0 100v-10h20v10z";
134cdf0e10cSrcweir         validate("validateAnd", pValid, &tools::solvePolygonOperationAnd);
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     void validateDiff()
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         const char* pValid="m0 90v-90h100v150h-75v-50h-5v-10zm55 10v-50h-50v50z";
140cdf0e10cSrcweir         validate("validateDiff", pValid, &tools::solvePolygonOperationDiff);
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
144cdf0e10cSrcweir     // member functions of the current class,
145cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(genericclipper);
148cdf0e10cSrcweir     CPPUNIT_TEST(validateOr);
149cdf0e10cSrcweir     CPPUNIT_TEST(validateXor);
150cdf0e10cSrcweir     CPPUNIT_TEST(validateAnd);
151cdf0e10cSrcweir     CPPUNIT_TEST(validateDiff);
152cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
153cdf0e10cSrcweir };
154cdf0e10cSrcweir 
155cdf0e10cSrcweir // -----------------------------------------------------------------------------
156cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::genericclipper);
157cdf0e10cSrcweir } // namespace basegfx2d
158