xref: /aoo42x/main/basegfx/test/clipstate.cxx (revision 131e08e2)
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/tools/b2dclipstate.hxx>
34cdf0e10cSrcweir #include <basegfx/range/b2dpolyrange.hxx>
35cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
37cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
38cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
39cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <boost/bind.hpp>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::basegfx;
44cdf0e10cSrcweir 
45*131e08e2SDamjan Jovanovic // FIXME:
46*131e08e2SDamjan Jovanovic #define RUN_OLD_FAILING_TESTS 0
47cdf0e10cSrcweir 
48cdf0e10cSrcweir namespace basegfx2d
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 
51*131e08e2SDamjan Jovanovic class clipstate : public ::testing::Test
52cdf0e10cSrcweir {
53*131e08e2SDamjan Jovanovic protected:
54cdf0e10cSrcweir     tools::B2DClipState aUnion1;
55cdf0e10cSrcweir     tools::B2DClipState aUnion2;
56cdf0e10cSrcweir     tools::B2DClipState aIntersect;
57cdf0e10cSrcweir     tools::B2DClipState aXor;
58cdf0e10cSrcweir     tools::B2DClipState aSubtract;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir public:
SetUp()61*131e08e2SDamjan Jovanovic     virtual 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 
TearDown()102*131e08e2SDamjan Jovanovic     virtual void TearDown()
103cdf0e10cSrcweir     {}
104cdf0e10cSrcweir 
verifyPoly(const char * sName,const char * sSvg,const tools::B2DClipState & toTest)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(
1101f882ec4SArmin Le Grand                     basegfx::tools::exportToSvgD(toTest.getClipPoly(), true, true, false),
111cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8).getStr() );
112cdf0e10cSrcweir #endif
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         B2DPolyPolygon aTmp1;
115*131e08e2SDamjan Jovanovic         ASSERT_TRUE(tools::importFromSvgD(
116*131e08e2SDamjan Jovanovic                                aTmp1, rtl::OUString::createFromAscii(sSvg), false, 0)) << sName;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         const rtl::OUString aSvg=
1191f882ec4SArmin Le Grand             tools::exportToSvgD(toTest.getClipPoly(), true, true, false);
120cdf0e10cSrcweir         B2DPolyPolygon aTmp2;
121*131e08e2SDamjan Jovanovic         ASSERT_TRUE(tools::importFromSvgD(aTmp2, aSvg, false, 0)) << sName;
122cdf0e10cSrcweir 
123*131e08e2SDamjan Jovanovic         ASSERT_TRUE(aTmp2 == aTmp1) << sName;
124cdf0e10cSrcweir     }
125*131e08e2SDamjan Jovanovic };
126cdf0e10cSrcweir 
TEST_F(clipstate,verifySimpleRange)127*131e08e2SDamjan Jovanovic TEST_F(clipstate, verifySimpleRange)
128*131e08e2SDamjan Jovanovic {
129*131e08e2SDamjan Jovanovic     const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
130*131e08e2SDamjan Jovanovic     const char* intersectSvg="m-100 10v-20h10v20zm80 90v-10h20v10zm-20-190v-10h20v10zm80 100v-20h10v20z";
131*131e08e2SDamjan Jovanovic     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*131e08e2SDamjan Jovanovic     const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z";
133*131e08e2SDamjan Jovanovic 
134*131e08e2SDamjan Jovanovic     ASSERT_TRUE(aUnion1.isCleared()) << "cleared clip stays empty under union operation";
135*131e08e2SDamjan Jovanovic     verifyPoly("union", unionSvg, aUnion2);
136*131e08e2SDamjan Jovanovic #if RUN_OLD_FAILING_TESTS
137*131e08e2SDamjan Jovanovic     verifyPoly("intersect", intersectSvg, aIntersect);
138*131e08e2SDamjan Jovanovic     verifyPoly("xor", xorSvg, aXor);
139*131e08e2SDamjan Jovanovic #endif
140*131e08e2SDamjan Jovanovic     verifyPoly("subtract", subtractSvg, aSubtract);
141*131e08e2SDamjan Jovanovic }
142cdf0e10cSrcweir 
TEST_F(clipstate,verifyMixedClips)143*131e08e2SDamjan Jovanovic TEST_F(clipstate, verifyMixedClips)
144*131e08e2SDamjan Jovanovic {
145*131e08e2SDamjan Jovanovic     tools::B2DClipState aMixedClip;
146cdf0e10cSrcweir 
147*131e08e2SDamjan Jovanovic     const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
148cdf0e10cSrcweir 
149*131e08e2SDamjan Jovanovic     B2DPolyPolygon aTmp1;
150*131e08e2SDamjan Jovanovic     tools::importFromSvgD(
151*131e08e2SDamjan Jovanovic         aTmp1, rtl::OUString::createFromAscii(unionSvg), false, 0);
152cdf0e10cSrcweir 
153*131e08e2SDamjan Jovanovic     aMixedClip.intersectPolyPolygon(aTmp1);
154*131e08e2SDamjan Jovanovic     aMixedClip.subtractRange(B2DRange(-20,-150,20,0));
155*131e08e2SDamjan Jovanovic     aMixedClip.subtractRange(B2DRange(-150,-20,0,20));
156*131e08e2SDamjan Jovanovic     aMixedClip.xorRange(B2DRange(-150,-150,150,150));
157cdf0e10cSrcweir 
158*131e08e2SDamjan Jovanovic     const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-40-20v-80h-80v80zm-50 170v-300h300v300z";
159*131e08e2SDamjan Jovanovic #if RUN_OLD_FAILING_TESTS
160*131e08e2SDamjan Jovanovic     verifyPoly("mixed clip", mixedClipSvg, aMixedClip);
161*131e08e2SDamjan Jovanovic #endif
162*131e08e2SDamjan Jovanovic }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // -----------------------------------------------------------------------------
165*131e08e2SDamjan Jovanovic 
166cdf0e10cSrcweir } // namespace basegfx2d
167