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/tools/b2dclipstate.hxx> 34 #include <basegfx/range/b2dpolyrange.hxx> 35 #include <basegfx/polygon/b2dpolygon.hxx> 36 #include <basegfx/polygon/b2dpolygontools.hxx> 37 #include <basegfx/polygon/b2dpolypolygontools.hxx> 38 #include <basegfx/polygon/b2dpolypolygon.hxx> 39 #include <basegfx/numeric/ftools.hxx> 40 41 #include <boost/bind.hpp> 42 43 using namespace ::basegfx; 44 45 // FIXME: 46 #define RUN_OLD_FAILING_TESTS 0 47 48 namespace basegfx2d 49 { 50 51 class clipstate : public ::testing::Test 52 { 53 protected: 54 tools::B2DClipState aUnion1; 55 tools::B2DClipState aUnion2; 56 tools::B2DClipState aIntersect; 57 tools::B2DClipState aXor; 58 tools::B2DClipState aSubtract; 59 60 public: 61 virtual void SetUp() 62 { 63 B2DRange aCenter(100, 100, -100, -100); 64 B2DRange aNorth(-10, -110, 10, -90); 65 B2DRange aWest(-110, -10, -90, 10); 66 B2DRange aSouth(-10, 110, 10, 90); 67 B2DRange aEast(110, -10, 90, 10); 68 69 aUnion1.unionRange(aCenter); 70 aUnion1.unionRange(aNorth); 71 aUnion1.unionRange(aWest); 72 aUnion1.unionRange(aSouth); 73 aUnion1.unionRange(aEast); 74 75 aUnion2.makeNull(); 76 aUnion2.unionRange(aCenter); 77 aUnion2.unionRange(aNorth); 78 aUnion2.unionRange(aWest); 79 aUnion2.unionRange(aSouth); 80 aUnion2.unionRange(aEast); 81 82 aIntersect.intersectRange(aCenter); 83 aIntersect.intersectRange(aNorth); 84 aIntersect.intersectRange(aWest); 85 aIntersect.intersectRange(aSouth); 86 aIntersect.intersectRange(aEast); 87 88 aXor.makeNull(); 89 aXor.xorRange(aCenter); 90 aXor.xorRange(aNorth); 91 aXor.xorRange(aWest); 92 aXor.xorRange(aSouth); 93 aXor.xorRange(aEast); 94 95 aSubtract.intersectRange(aCenter); 96 aSubtract.subtractRange(aNorth); 97 aSubtract.subtractRange(aWest); 98 aSubtract.subtractRange(aSouth); 99 aSubtract.subtractRange(aEast); 100 } 101 102 virtual void TearDown() 103 {} 104 105 void verifyPoly(const char* sName, const char* sSvg, const tools::B2DClipState& toTest) 106 { 107 #if defined(VERBOSE) 108 fprintf(stderr, "%s - svg:d=\"%s\"\n", 109 sName, rtl::OUStringToOString( 110 basegfx::tools::exportToSvgD(toTest.getClipPoly(), true, true, false), 111 RTL_TEXTENCODING_UTF8).getStr() ); 112 #endif 113 114 B2DPolyPolygon aTmp1; 115 ASSERT_TRUE(tools::importFromSvgD( 116 aTmp1, rtl::OUString::createFromAscii(sSvg), false, 0)) << sName; 117 118 const rtl::OUString aSvg= 119 tools::exportToSvgD(toTest.getClipPoly(), true, true, false); 120 B2DPolyPolygon aTmp2; 121 ASSERT_TRUE(tools::importFromSvgD(aTmp2, aSvg, false, 0)) << sName; 122 123 ASSERT_TRUE(aTmp2 == aTmp1) << sName; 124 } 125 }; 126 127 TEST_F(clipstate, verifySimpleRange) 128 { 129 const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 130 const char* intersectSvg="m-100 10v-20h10v20zm80 90v-10h20v10zm-20-190v-10h20v10zm80 100v-20h10v20z"; 131 const char* xorSvg="m-100 10h10v-20h-10zm90 110h20v-10h-20zm0-180h20v-10h-20zm100 110h10v-20h-10zm10 20v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 132 const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z"; 133 134 ASSERT_TRUE(aUnion1.isCleared()) << "cleared clip stays empty under union operation"; 135 verifyPoly("union", unionSvg, aUnion2); 136 #if RUN_OLD_FAILING_TESTS 137 verifyPoly("intersect", intersectSvg, aIntersect); 138 verifyPoly("xor", xorSvg, aXor); 139 #endif 140 verifyPoly("subtract", subtractSvg, aSubtract); 141 } 142 143 TEST_F(clipstate, verifyMixedClips) 144 { 145 tools::B2DClipState aMixedClip; 146 147 const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 148 149 B2DPolyPolygon aTmp1; 150 tools::importFromSvgD( 151 aTmp1, rtl::OUString::createFromAscii(unionSvg), false, 0); 152 153 aMixedClip.intersectPolyPolygon(aTmp1); 154 aMixedClip.subtractRange(B2DRange(-20,-150,20,0)); 155 aMixedClip.subtractRange(B2DRange(-150,-20,0,20)); 156 aMixedClip.xorRange(B2DRange(-150,-150,150,150)); 157 158 const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-40-20v-80h-80v80zm-50 170v-300h300v300z"; 159 #if RUN_OLD_FAILING_TESTS 160 verifyPoly("mixed clip", mixedClipSvg, aMixedClip); 161 #endif 162 } 163 164 // ----------------------------------------------------------------------------- 165 166 } // namespace basegfx2d 167