1*09dbbe93SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*09dbbe93SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*09dbbe93SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*09dbbe93SAndrew Rist * distributed with this work for additional information 6*09dbbe93SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*09dbbe93SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*09dbbe93SAndrew Rist * "License"); you may not use this file except in compliance 9*09dbbe93SAndrew Rist * with the License. You may obtain a copy of the License at 10*09dbbe93SAndrew Rist * 11*09dbbe93SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*09dbbe93SAndrew Rist * 13*09dbbe93SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*09dbbe93SAndrew Rist * software distributed under the License is distributed on an 15*09dbbe93SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*09dbbe93SAndrew Rist * KIND, either express or implied. See the License for the 17*09dbbe93SAndrew Rist * specific language governing permissions and limitations 18*09dbbe93SAndrew Rist * under the License. 19*09dbbe93SAndrew Rist * 20*09dbbe93SAndrew Rist *************************************************************/ 21*09dbbe93SAndrew Rist 22*09dbbe93SAndrew 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" 30cdf0e10cSrcweir #include "cppunit/TestAssert.h" 31cdf0e10cSrcweir #include "cppunit/TestFixture.h" 32cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 33cdf0e10cSrcweir #include "postextstl.h" 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <basegfx/tools/b2dclipstate.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/b2dpolypolygon.hxx> 41cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include <boost/bind.hpp> 44cdf0e10cSrcweir 45cdf0e10cSrcweir using namespace ::basegfx; 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir namespace basegfx2d 49cdf0e10cSrcweir { 50cdf0e10cSrcweir 51cdf0e10cSrcweir class clipstate : public CppUnit::TestFixture 52cdf0e10cSrcweir { 53cdf0e10cSrcweir private: 54cdf0e10cSrcweir tools::B2DClipState aUnion1; 55cdf0e10cSrcweir tools::B2DClipState aUnion2; 56cdf0e10cSrcweir tools::B2DClipState aIntersect; 57cdf0e10cSrcweir tools::B2DClipState aXor; 58cdf0e10cSrcweir tools::B2DClipState aSubtract; 59cdf0e10cSrcweir 60cdf0e10cSrcweir public: 61cdf0e10cSrcweir void setUp() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir B2DRange aCenter(100, 100, -100, -100); 64cdf0e10cSrcweir B2DRange aNorth(-10, -110, 10, -90); 65cdf0e10cSrcweir B2DRange aWest(-110, -10, -90, 10); 66cdf0e10cSrcweir B2DRange aSouth(-10, 110, 10, 90); 67cdf0e10cSrcweir B2DRange aEast(110, -10, 90, 10); 68cdf0e10cSrcweir 69cdf0e10cSrcweir aUnion1.unionRange(aCenter); 70cdf0e10cSrcweir aUnion1.unionRange(aNorth); 71cdf0e10cSrcweir aUnion1.unionRange(aWest); 72cdf0e10cSrcweir aUnion1.unionRange(aSouth); 73cdf0e10cSrcweir aUnion1.unionRange(aEast); 74cdf0e10cSrcweir 75cdf0e10cSrcweir aUnion2.makeNull(); 76cdf0e10cSrcweir aUnion2.unionRange(aCenter); 77cdf0e10cSrcweir aUnion2.unionRange(aNorth); 78cdf0e10cSrcweir aUnion2.unionRange(aWest); 79cdf0e10cSrcweir aUnion2.unionRange(aSouth); 80cdf0e10cSrcweir aUnion2.unionRange(aEast); 81cdf0e10cSrcweir 82cdf0e10cSrcweir aIntersect.intersectRange(aCenter); 83cdf0e10cSrcweir aIntersect.intersectRange(aNorth); 84cdf0e10cSrcweir aIntersect.intersectRange(aWest); 85cdf0e10cSrcweir aIntersect.intersectRange(aSouth); 86cdf0e10cSrcweir aIntersect.intersectRange(aEast); 87cdf0e10cSrcweir 88cdf0e10cSrcweir aXor.makeNull(); 89cdf0e10cSrcweir aXor.xorRange(aCenter); 90cdf0e10cSrcweir aXor.xorRange(aNorth); 91cdf0e10cSrcweir aXor.xorRange(aWest); 92cdf0e10cSrcweir aXor.xorRange(aSouth); 93cdf0e10cSrcweir aXor.xorRange(aEast); 94cdf0e10cSrcweir 95cdf0e10cSrcweir aSubtract.intersectRange(aCenter); 96cdf0e10cSrcweir aSubtract.subtractRange(aNorth); 97cdf0e10cSrcweir aSubtract.subtractRange(aWest); 98cdf0e10cSrcweir aSubtract.subtractRange(aSouth); 99cdf0e10cSrcweir aSubtract.subtractRange(aEast); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir void tearDown() 103cdf0e10cSrcweir {} 104cdf0e10cSrcweir 105cdf0e10cSrcweir void verifyPoly(const char* sName, const char* sSvg, const tools::B2DClipState& toTest) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir #if defined(VERBOSE) 108cdf0e10cSrcweir fprintf(stderr, "%s - svg:d=\"%s\"\n", 109cdf0e10cSrcweir sName, rtl::OUStringToOString( 110cdf0e10cSrcweir basegfx::tools::exportToSvgD(toTest.getClipPoly()), 111cdf0e10cSrcweir RTL_TEXTENCODING_UTF8).getStr() ); 112cdf0e10cSrcweir #endif 113cdf0e10cSrcweir 114cdf0e10cSrcweir B2DPolyPolygon aTmp1; 115cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE(sName, 116cdf0e10cSrcweir tools::importFromSvgD( 117cdf0e10cSrcweir aTmp1, 118cdf0e10cSrcweir rtl::OUString::createFromAscii(sSvg))); 119cdf0e10cSrcweir 120cdf0e10cSrcweir const rtl::OUString aSvg= 121cdf0e10cSrcweir tools::exportToSvgD(toTest.getClipPoly()); 122cdf0e10cSrcweir B2DPolyPolygon aTmp2; 123cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE(sName, 124cdf0e10cSrcweir tools::importFromSvgD( 125cdf0e10cSrcweir aTmp2, 126cdf0e10cSrcweir aSvg)); 127cdf0e10cSrcweir 128cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( 129cdf0e10cSrcweir sName, 130cdf0e10cSrcweir aTmp2 == aTmp1); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir void verifySimpleRange() 134cdf0e10cSrcweir { 135cdf0e10cSrcweir const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 136cdf0e10cSrcweir const char* intersectSvg="m-100 10v-20h10v20zm80 90v-10h20v10zm-20-190v-10h20v10zm80 100v-20h10v20z"; 137cdf0e10cSrcweir 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"; 138cdf0e10cSrcweir const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z"; 139cdf0e10cSrcweir 140cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("cleared clip stays empty under union operation", 141cdf0e10cSrcweir aUnion1.isCleared()); 142cdf0e10cSrcweir verifyPoly("union", unionSvg, aUnion2); 143cdf0e10cSrcweir verifyPoly("intersect", intersectSvg, aIntersect); 144cdf0e10cSrcweir verifyPoly("xor", xorSvg, aXor); 145cdf0e10cSrcweir verifyPoly("subtract", subtractSvg, aSubtract); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir void verifyMixedClips() 149cdf0e10cSrcweir { 150cdf0e10cSrcweir tools::B2DClipState aMixedClip; 151cdf0e10cSrcweir 152cdf0e10cSrcweir const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 153cdf0e10cSrcweir 154cdf0e10cSrcweir B2DPolyPolygon aTmp1; 155cdf0e10cSrcweir tools::importFromSvgD( 156cdf0e10cSrcweir aTmp1, 157cdf0e10cSrcweir rtl::OUString::createFromAscii(unionSvg)); 158cdf0e10cSrcweir 159cdf0e10cSrcweir aMixedClip.intersectPolyPolygon(aTmp1); 160cdf0e10cSrcweir aMixedClip.subtractRange(B2DRange(-20,-150,20,0)); 161cdf0e10cSrcweir aMixedClip.subtractRange(B2DRange(-150,-20,0,20)); 162cdf0e10cSrcweir aMixedClip.xorRange(B2DRange(-150,-150,150,150)); 163cdf0e10cSrcweir 164cdf0e10cSrcweir const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-40-20v-80h-80v80zm-50 170v-300h300v300z"; 165cdf0e10cSrcweir verifyPoly("mixed clip", mixedClipSvg, aMixedClip); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir CPPUNIT_TEST_SUITE(clipstate); 169cdf0e10cSrcweir CPPUNIT_TEST(verifySimpleRange); 170cdf0e10cSrcweir CPPUNIT_TEST(verifyMixedClips); 171cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 172cdf0e10cSrcweir }; 173cdf0e10cSrcweir 174cdf0e10cSrcweir // ----------------------------------------------------------------------------- 175cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::clipstate); 176cdf0e10cSrcweir } // namespace basegfx2d 177