109dbbe93SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
309dbbe93SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
409dbbe93SAndrew Rist * or more contributor license agreements. See the NOTICE file
509dbbe93SAndrew Rist * distributed with this work for additional information
609dbbe93SAndrew Rist * regarding copyright ownership. The ASF licenses this file
709dbbe93SAndrew Rist * to you under the Apache License, Version 2.0 (the
809dbbe93SAndrew Rist * "License"); you may not use this file except in compliance
909dbbe93SAndrew Rist * with the License. You may obtain a copy of the License at
1009dbbe93SAndrew Rist *
1109dbbe93SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1209dbbe93SAndrew Rist *
1309dbbe93SAndrew Rist * Unless required by applicable law or agreed to in writing,
1409dbbe93SAndrew Rist * software distributed under the License is distributed on an
1509dbbe93SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1609dbbe93SAndrew Rist * KIND, either express or implied. See the License for the
1709dbbe93SAndrew Rist * specific language governing permissions and limitations
1809dbbe93SAndrew Rist * under the License.
1909dbbe93SAndrew Rist *
2009dbbe93SAndrew Rist *************************************************************/
2109dbbe93SAndrew Rist
2209dbbe93SAndrew 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"
30*131e08e2SDamjan Jovanovic #include "gtest/gtest.h"
31cdf0e10cSrcweir #include "postextstl.h"
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
34cdf0e10cSrcweir #include <basegfx/curve/b2dcubicbezier.hxx>
35cdf0e10cSrcweir #include <basegfx/curve/b2dbeziertools.hxx>
36cdf0e10cSrcweir #include <basegfx/range/b2dpolyrange.hxx>
37cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
38cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
39cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
40cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
41cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygonclipper.hxx>
42cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
43cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include <boost/bind.hpp>
46cdf0e10cSrcweir
47cdf0e10cSrcweir using namespace ::basegfx;
48cdf0e10cSrcweir
49*131e08e2SDamjan Jovanovic // FIXME:
50*131e08e2SDamjan Jovanovic #define RUN_OLD_FAILING_TESTS 0
51cdf0e10cSrcweir
52cdf0e10cSrcweir namespace basegfx2d
53cdf0e10cSrcweir {
54cdf0e10cSrcweir
55*131e08e2SDamjan Jovanovic class genericclipper : public ::testing::Test
56cdf0e10cSrcweir {
57*131e08e2SDamjan Jovanovic protected:
58cdf0e10cSrcweir B2DPolygon aSelfIntersecting;
59cdf0e10cSrcweir B2DPolygon aShiftedRectangle;
60cdf0e10cSrcweir
61cdf0e10cSrcweir public:
62cdf0e10cSrcweir // initialise your test code values here.
SetUp()63*131e08e2SDamjan Jovanovic virtual 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
TearDown()79*131e08e2SDamjan Jovanovic virtual void TearDown()
80cdf0e10cSrcweir {}
81cdf0e10cSrcweir
validate(const char * pName,const char * pValidSvgD,B2DPolyPolygon (* pFunc)(const B2DPolyPolygon &,const B2DPolyPolygon &))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(
941f882ec4SArmin Le Grand aSelfIntersect, true, true, false),
95cdf0e10cSrcweir RTL_TEXTENCODING_UTF8).getStr() );
96cdf0e10cSrcweir fprintf(stderr, "%s input RHS - svg:d=\"%s\"\n",
97cdf0e10cSrcweir pName, rtl::OUStringToOString(
98cdf0e10cSrcweir basegfx::tools::exportToSvgD(
991f882ec4SArmin Le Grand aRect, true, true, false),
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(
1091f882ec4SArmin Le Grand basegfx::tools::exportToSvgD(aRes, true, true, false),
110cdf0e10cSrcweir RTL_TEXTENCODING_UTF8).getStr() );
111cdf0e10cSrcweir #endif
112cdf0e10cSrcweir
113cdf0e10cSrcweir rtl::OUString aValid=rtl::OUString::createFromAscii(pValidSvgD);
114cdf0e10cSrcweir
115*131e08e2SDamjan Jovanovic ASSERT_TRUE(basegfx::tools::exportToSvgD(aRes, true, true, false) == aValid) << pName;
116cdf0e10cSrcweir }
117*131e08e2SDamjan Jovanovic };
118cdf0e10cSrcweir
TEST_F(genericclipper,validateOr)119*131e08e2SDamjan Jovanovic TEST_F(genericclipper, validateOr)
120*131e08e2SDamjan Jovanovic {
121*131e08e2SDamjan Jovanovic #if RUN_OLD_FAILING_TESTS
122*131e08e2SDamjan Jovanovic const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm75 10v-50h-50v50z";
123*131e08e2SDamjan Jovanovic validate("validateOr", pValid, &tools::solvePolygonOperationOr);
124*131e08e2SDamjan Jovanovic #endif
125*131e08e2SDamjan Jovanovic }
126cdf0e10cSrcweir
TEST_F(genericclipper,validateXor)127*131e08e2SDamjan Jovanovic TEST_F(genericclipper, validateXor)
128*131e08e2SDamjan Jovanovic {
129*131e08e2SDamjan Jovanovic #if RUN_OLD_FAILING_TESTS
130*131e08e2SDamjan Jovanovic const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm0 10h20v-10h-20zm75 10v-50h-50v50z";
131*131e08e2SDamjan Jovanovic validate("validateXor", pValid, &tools::solvePolygonOperationXor);
132*131e08e2SDamjan Jovanovic #endif
133*131e08e2SDamjan Jovanovic }
134cdf0e10cSrcweir
TEST_F(genericclipper,validateAnd)135*131e08e2SDamjan Jovanovic TEST_F(genericclipper, validateAnd)
136*131e08e2SDamjan Jovanovic {
137*131e08e2SDamjan Jovanovic const char* pValid="m0 100v-10h20v10z";
138*131e08e2SDamjan Jovanovic validate("validateAnd", pValid, &tools::solvePolygonOperationAnd);
139*131e08e2SDamjan Jovanovic }
140cdf0e10cSrcweir
TEST_F(genericclipper,validateDiff)141*131e08e2SDamjan Jovanovic TEST_F(genericclipper, validateDiff)
142*131e08e2SDamjan Jovanovic {
143*131e08e2SDamjan Jovanovic #if RUN_OLD_FAILING_TESTS
144*131e08e2SDamjan Jovanovic const char* pValid="m0 90v-90h100v150h-75v-50h-5v-10zm55 10v-50h-50v50z";
145*131e08e2SDamjan Jovanovic validate("validateDiff", pValid, &tools::solvePolygonOperationDiff);
146*131e08e2SDamjan Jovanovic #endif
147*131e08e2SDamjan Jovanovic }
148cdf0e10cSrcweir
149cdf0e10cSrcweir // -----------------------------------------------------------------------------
150*131e08e2SDamjan Jovanovic
151cdf0e10cSrcweir } // namespace basegfx2d
152