Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sal/types.h>
30 : : #include "cppunit/TestAssert.h"
31 : : #include "cppunit/TestFixture.h"
32 : : #include "cppunit/extensions/HelperMacros.h"
33 : :
34 : : #include <basegfx/tools/b2dclipstate.hxx>
35 : : #include <basegfx/range/b2dpolyrange.hxx>
36 : : #include <basegfx/polygon/b2dpolygon.hxx>
37 : : #include <basegfx/polygon/b2dpolygontools.hxx>
38 : : #include <basegfx/polygon/b2dpolypolygontools.hxx>
39 : : #include <basegfx/polygon/b2dpolypolygon.hxx>
40 : : #include <basegfx/numeric/ftools.hxx>
41 : :
42 : : using namespace ::basegfx;
43 : :
44 : :
45 : : namespace basegfx2d
46 : : {
47 : :
48 [ + - ][ + - ]: 30 : class clipstate : public CppUnit::TestFixture
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
49 : : {
50 : : private:
51 : : tools::B2DClipState aUnion1;
52 : : tools::B2DClipState aUnion2;
53 : : tools::B2DClipState aIntersect;
54 : : tools::B2DClipState aXor;
55 : : tools::B2DClipState aSubtract;
56 : :
57 : : public:
58 : 10 : void setUp()
59 : : {
60 [ + - ]: 10 : B2DRange aCenter(100, 100, -100, -100);
61 [ + - ]: 10 : B2DRange aNorth(-10, -110, 10, -90);
62 [ + - ]: 10 : B2DRange aWest(-110, -10, -90, 10);
63 [ + - ]: 10 : B2DRange aSouth(-10, 110, 10, 90);
64 [ + - ]: 10 : B2DRange aEast(110, -10, 90, 10);
65 : :
66 [ + - ]: 10 : aUnion1.unionRange(aCenter);
67 [ + - ]: 10 : aUnion1.unionRange(aNorth);
68 [ + - ]: 10 : aUnion1.unionRange(aWest);
69 [ + - ]: 10 : aUnion1.unionRange(aSouth);
70 [ + - ]: 10 : aUnion1.unionRange(aEast);
71 : :
72 [ + - ]: 10 : aUnion2.makeNull();
73 [ + - ]: 10 : aUnion2.unionRange(aCenter);
74 [ + - ]: 10 : aUnion2.unionRange(aNorth);
75 [ + - ]: 10 : aUnion2.unionRange(aWest);
76 [ + - ]: 10 : aUnion2.unionRange(aSouth);
77 [ + - ]: 10 : aUnion2.unionRange(aEast);
78 : :
79 [ + - ]: 10 : aIntersect.intersectRange(aCenter);
80 [ + - ]: 10 : aIntersect.intersectRange(aNorth);
81 [ + - ]: 10 : aIntersect.intersectRange(aWest);
82 [ + - ]: 10 : aIntersect.intersectRange(aSouth);
83 [ + - ]: 10 : aIntersect.intersectRange(aEast);
84 : :
85 [ + - ]: 10 : aXor.makeNull();
86 [ + - ]: 10 : aXor.xorRange(aCenter);
87 [ + - ]: 10 : aXor.xorRange(aNorth);
88 [ + - ]: 10 : aXor.xorRange(aWest);
89 [ + - ]: 10 : aXor.xorRange(aSouth);
90 [ + - ]: 10 : aXor.xorRange(aEast);
91 : :
92 [ + - ]: 10 : aSubtract.intersectRange(aCenter);
93 [ + - ]: 10 : aSubtract.subtractRange(aNorth);
94 [ + - ]: 10 : aSubtract.subtractRange(aWest);
95 [ + - ]: 10 : aSubtract.subtractRange(aSouth);
96 [ + - ]: 10 : aSubtract.subtractRange(aEast);
97 : 10 : }
98 : :
99 : 10 : void tearDown()
100 : 10 : {}
101 : :
102 : 25 : void verifyPoly(const char* sName, const char* sSvg, const tools::B2DClipState& toTest)
103 : : {
104 : : #if OSL_DEBUG_LEVEL > 2
105 : : fprintf(stderr, "%s - svg:d=\"%s\"\n",
106 : : sName, rtl::OUStringToOString(
107 : : basegfx::tools::exportToSvgD(toTest.getClipPoly()),
108 : : RTL_TEXTENCODING_UTF8).getStr() );
109 : : #endif
110 : :
111 [ + - ]: 25 : B2DPolyPolygon aTmp1;
112 [ + - ][ + - ]: 50 : CPPUNIT_ASSERT_MESSAGE(sName,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
113 : : tools::importFromSvgD(
114 : : aTmp1,
115 [ + - ]: 25 : rtl::OUString::createFromAscii(sSvg)));
116 : :
117 : : const rtl::OUString aSvg=
118 [ + - ][ + - ]: 25 : tools::exportToSvgD(toTest.getClipPoly());
[ + - ]
119 [ + - ]: 25 : B2DPolyPolygon aTmp2;
120 [ + - ][ + - ]: 50 : CPPUNIT_ASSERT_MESSAGE(sName,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
121 : : tools::importFromSvgD(
122 : : aTmp2,
123 [ + - ]: 25 : aSvg));
124 : :
125 [ + - ][ + - ]: 50 : CPPUNIT_ASSERT_MESSAGE(
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
126 : : sName,
127 [ + - + - ]: 50 : aTmp2 == aTmp1);
[ + - ]
128 : 25 : }
129 : :
130 : 5 : void verifySimpleRange()
131 : : {
132 : 5 : const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
133 : 5 : const char* intersectSvg="m-100 10v-20h10v20zm90 90v-10h20v10zm0-190v-10h20v10zm100 100v-20h10v20z";
134 : : const char* xorSvg="m-100 10h10v-20h-10zm90 90h20v-10h-20zm0-190h20v-10h-20zm100 100h10v-20h-10z"
135 : 5 : "m10 0v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
136 : 5 : const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z";
137 : :
138 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("cleared clip stays empty under union operation",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
139 [ + - ]: 5 : aUnion1.isCleared());
140 : 5 : verifyPoly("union", unionSvg, aUnion2);
141 : 5 : verifyPoly("intersect", intersectSvg, aIntersect);
142 : 5 : verifyPoly("xor", xorSvg, aXor);
143 : 5 : verifyPoly("subtract", subtractSvg, aSubtract);
144 : 5 : }
145 : :
146 : 5 : void verifyMixedClips()
147 : : {
148 [ + - ]: 5 : tools::B2DClipState aMixedClip;
149 : :
150 : 5 : const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
151 : :
152 [ + - ]: 5 : B2DPolyPolygon aTmp1;
153 : : tools::importFromSvgD(
154 : : aTmp1,
155 [ + - ]: 5 : rtl::OUString::createFromAscii(unionSvg));
156 : :
157 [ + - ]: 5 : aMixedClip.intersectPolyPolygon(aTmp1);
158 [ + - ][ + - ]: 5 : aMixedClip.subtractRange(B2DRange(-20,-150,20,0));
159 [ + - ][ + - ]: 5 : aMixedClip.subtractRange(B2DRange(-150,-20,0,20));
160 [ + - ][ + - ]: 5 : aMixedClip.xorRange(B2DRange(-150,-150,150,150));
161 : :
162 : 5 : const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-20-20v-80h-80v80zm-130 170v-300h300v300z";
163 [ + - ][ + - ]: 5 : verifyPoly("mixed clip", mixedClipSvg, aMixedClip);
[ + - ]
164 : 5 : }
165 : :
166 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(clipstate);
[ + - ][ + - ]
[ # # ]
167 [ + - ][ + - ]: 5 : CPPUNIT_TEST(verifySimpleRange);
[ + - ][ + - ]
[ + - ][ + - ]
168 [ + - ][ + - ]: 5 : CPPUNIT_TEST(verifyMixedClips);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
169 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
170 : : };
171 : :
172 : : // -----------------------------------------------------------------------------
173 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::clipstate);
174 [ + - ][ + - ]: 15 : } // namespace basegfx2d
175 : :
176 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|