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