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