xref: /aoo42x/main/basegfx/test/genericclipper.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_basegfx.hxx"
31 // autogenerated file with codegen.pl
32 
33 #include "preextstl.h"
34 #include "cppunit/TestAssert.h"
35 #include "cppunit/TestFixture.h"
36 #include "cppunit/extensions/HelperMacros.h"
37 #include "postextstl.h"
38 
39 #include <basegfx/matrix/b2dhommatrix.hxx>
40 #include <basegfx/curve/b2dcubicbezier.hxx>
41 #include <basegfx/curve/b2dbeziertools.hxx>
42 #include <basegfx/range/b2dpolyrange.hxx>
43 #include <basegfx/polygon/b2dpolygon.hxx>
44 #include <basegfx/polygon/b2dpolygontools.hxx>
45 #include <basegfx/polygon/b2dpolypolygontools.hxx>
46 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
47 #include <basegfx/polygon/b2dpolygonclipper.hxx>
48 #include <basegfx/polygon/b2dpolypolygon.hxx>
49 #include <basegfx/numeric/ftools.hxx>
50 
51 #include <boost/bind.hpp>
52 
53 using namespace ::basegfx;
54 
55 
56 namespace basegfx2d
57 {
58 
59 class genericclipper : public CppUnit::TestFixture
60 {
61 private:
62     B2DPolygon aSelfIntersecting;
63     B2DPolygon aShiftedRectangle;
64 
65 public:
66     // initialise your test code values here.
67     void setUp()
68     {
69         aSelfIntersecting.append(B2DPoint(0,  0));
70         aSelfIntersecting.append(B2DPoint(0,  100));
71         aSelfIntersecting.append(B2DPoint(75, 100));
72         aSelfIntersecting.append(B2DPoint(75, 50));
73         aSelfIntersecting.append(B2DPoint(25, 50));
74         aSelfIntersecting.append(B2DPoint(25, 150));
75         aSelfIntersecting.append(B2DPoint(100,150));
76         aSelfIntersecting.append(B2DPoint(100,0));
77         aSelfIntersecting.setClosed(true);
78 
79         aShiftedRectangle = tools::createPolygonFromRect(
80             B2DRange(0,90,20,150));
81     }
82 
83     void tearDown()
84     {}
85 
86     void validate(const char* pName,
87                   const char* pValidSvgD,
88                   B2DPolyPolygon (*pFunc)(const B2DPolyPolygon&, const B2DPolyPolygon&))
89     {
90         const B2DPolyPolygon aSelfIntersect(
91             tools::prepareForPolygonOperation(aSelfIntersecting));
92         const B2DPolyPolygon aRect(
93             tools::prepareForPolygonOperation(aShiftedRectangle));
94 #if defined(VERBOSE)
95         fprintf(stderr, "%s input LHS - svg:d=\"%s\"\n",
96                 pName, rtl::OUStringToOString(
97                     basegfx::tools::exportToSvgD(
98                         aSelfIntersect),
99                     RTL_TEXTENCODING_UTF8).getStr() );
100         fprintf(stderr, "%s input RHS - svg:d=\"%s\"\n",
101                 pName, rtl::OUStringToOString(
102                     basegfx::tools::exportToSvgD(
103                         aRect),
104                     RTL_TEXTENCODING_UTF8).getStr() );
105 #endif
106 
107         const B2DPolyPolygon aRes=
108             pFunc(aSelfIntersect, aRect);
109 
110 #if defined(VERBOSE)
111         fprintf(stderr, "%s - svg:d=\"%s\"\n",
112                 pName, rtl::OUStringToOString(
113                     basegfx::tools::exportToSvgD(aRes),
114                     RTL_TEXTENCODING_UTF8).getStr() );
115 #endif
116 
117         rtl::OUString aValid=rtl::OUString::createFromAscii(pValidSvgD);
118 
119         CPPUNIT_ASSERT_MESSAGE(pName,
120                                basegfx::tools::exportToSvgD(aRes) == aValid);
121     }
122 
123     void validateOr()
124     {
125         const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm75 10v-50h-50v50z";
126         validate("validateOr", pValid, &tools::solvePolygonOperationOr);
127     }
128 
129     void validateXor()
130     {
131         const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm0 10h20v-10h-20zm75 10v-50h-50v50z";
132         validate("validateXor", pValid, &tools::solvePolygonOperationXor);
133     }
134 
135     void validateAnd()
136     {
137         const char* pValid="m0 100v-10h20v10z";
138         validate("validateAnd", pValid, &tools::solvePolygonOperationAnd);
139     }
140 
141     void validateDiff()
142     {
143         const char* pValid="m0 90v-90h100v150h-75v-50h-5v-10zm55 10v-50h-50v50z";
144         validate("validateDiff", pValid, &tools::solvePolygonOperationDiff);
145     }
146 
147     // Change the following lines only, if you add, remove or rename
148     // member functions of the current class,
149     // because these macros are need by auto register mechanism.
150 
151     CPPUNIT_TEST_SUITE(genericclipper);
152     CPPUNIT_TEST(validateOr);
153     CPPUNIT_TEST(validateXor);
154     CPPUNIT_TEST(validateAnd);
155     CPPUNIT_TEST(validateDiff);
156     CPPUNIT_TEST_SUITE_END();
157 };
158 
159 // -----------------------------------------------------------------------------
160 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::genericclipper);
161 } // namespace basegfx2d
162