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 "gtest/gtest.h" 31 #include "postextstl.h" 32 33 #include <basegfx/matrix/b2dhommatrix.hxx> 34 #include <basegfx/curve/b2dcubicbezier.hxx> 35 #include <basegfx/curve/b2dbeziertools.hxx> 36 #include <basegfx/range/b2dpolyrange.hxx> 37 #include <basegfx/polygon/b2dpolygon.hxx> 38 #include <basegfx/polygon/b2dpolygontools.hxx> 39 #include <basegfx/polygon/b2dpolypolygontools.hxx> 40 #include <basegfx/polygon/b2dpolypolygoncutter.hxx> 41 #include <basegfx/polygon/b2dpolygonclipper.hxx> 42 #include <basegfx/polygon/b2dpolypolygon.hxx> 43 #include <basegfx/numeric/ftools.hxx> 44 45 #include <boost/bind.hpp> 46 47 using namespace ::basegfx; 48 49 // FIXME: 50 #define RUN_OLD_FAILING_TESTS 0 51 52 namespace basegfx2d 53 { 54 55 class genericclipper : public ::testing::Test 56 { 57 protected: 58 B2DPolygon aSelfIntersecting; 59 B2DPolygon aShiftedRectangle; 60 61 public: 62 // initialise your test code values here. 63 virtual 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 79 virtual void TearDown() 80 {} 81 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 ASSERT_TRUE(basegfx::tools::exportToSvgD(aRes, true, true, false) == aValid) << pName; 116 } 117 }; 118 119 TEST_F(genericclipper, validateOr) 120 { 121 #if RUN_OLD_FAILING_TESTS 122 const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm75 10v-50h-50v50z"; 123 validate("validateOr", pValid, &tools::solvePolygonOperationOr); 124 #endif 125 } 126 127 TEST_F(genericclipper, validateXor) 128 { 129 #if RUN_OLD_FAILING_TESTS 130 const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm0 10h20v-10h-20zm75 10v-50h-50v50z"; 131 validate("validateXor", pValid, &tools::solvePolygonOperationXor); 132 #endif 133 } 134 135 TEST_F(genericclipper, validateAnd) 136 { 137 const char* pValid="m0 100v-10h20v10z"; 138 validate("validateAnd", pValid, &tools::solvePolygonOperationAnd); 139 } 140 141 TEST_F(genericclipper, validateDiff) 142 { 143 #if RUN_OLD_FAILING_TESTS 144 const char* pValid="m0 90v-90h100v150h-75v-50h-5v-10zm55 10v-50h-50v50z"; 145 validate("validateDiff", pValid, &tools::solvePolygonOperationDiff); 146 #endif 147 } 148 149 // ----------------------------------------------------------------------------- 150 151 } // namespace basegfx2d 152