Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <cppunit/TestAssert.h>
21 : #include <cppunit/TestFixture.h>
22 : #include <cppunit/extensions/HelperMacros.h>
23 :
24 : #include <basegfx/matrix/b2dhommatrix.hxx>
25 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
26 : #include <basegfx/polygon/b2dpolygon.hxx>
27 : #include <basegfx/polygon/b2dpolygontools.hxx>
28 : #include <basegfx/curve/b2dcubicbezier.hxx>
29 : #include <basegfx/curve/b2dbeziertools.hxx>
30 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
31 : #include <basegfx/polygon/b2dpolygonclipper.hxx>
32 : #include <basegfx/polygon/b2dpolypolygon.hxx>
33 : #include <basegfx/polygon/b2dtrapezoid.hxx>
34 : #include <basegfx/range/b2irange.hxx>
35 : #include <basegfx/range/b2ibox.hxx>
36 : #include <basegfx/range/b1drange.hxx>
37 : #include <basegfx/range/b1irange.hxx>
38 : #include <basegfx/range/b1ibox.hxx>
39 : #include <basegfx/range/b2drange.hxx>
40 : #include <basegfx/range/b2dpolyrange.hxx>
41 : #include <basegfx/numeric/ftools.hxx>
42 : #include <basegfx/color/bcolor.hxx>
43 : #include <basegfx/color/bcolortools.hxx>
44 :
45 : #include <basegfx/tools/rectcliptools.hxx>
46 :
47 : #include <iostream>
48 : #include <fstream>
49 :
50 : #include <boxclipper.hxx>
51 :
52 : using namespace ::basegfx;
53 :
54 : namespace basegfx2d
55 : {
56 6 : class b2dsvgdimpex : public CppUnit::TestFixture
57 : {
58 : private:
59 : OUString aPath0;
60 : OUString aPath1;
61 : OUString aPath2;
62 : OUString aPath3;
63 :
64 : public:
65 : // initialise your test code values here.
66 2 : void setUp() SAL_OVERRIDE
67 : {
68 : // simple rectangle
69 2 : aPath0 = "M 10 10-10 10-10-10 10-10Z";
70 :
71 : // simple bezier polygon
72 2 : aPath1 = "m11430 0c-8890 3810 5715 6985 5715 6985 "
73 : "0 0-17145-1905-17145-1905 0 0 22860-10160 "
74 2 : "16510 6350-6350 16510-3810-11430-3810-11430z";
75 :
76 : // '@' as a bezier polygon
77 2 : aPath2 = "m1917 1114c-89-189-233-284-430-284-167 "
78 : "0-306 91-419 273-113 182-170 370-170 564 "
79 : "0 145 33 259 98 342 65 84 150 126 257 126 "
80 : "77 0 154-19 231-57 77-38 147-97 210-176 63"
81 : "-79 99-143 109-190 38-199 76-398 114-598z"
82 : "m840 1646c-133 73-312 139-537 197-225 57"
83 : "-440 86-644 87-483-1-866-132-1150-392-284"
84 : "-261-426-619-426-1076 0-292 67-560 200-803 "
85 : "133-243 321-433 562-569 241-136 514-204 821"
86 : "-204 405 0 739 125 1003 374 264 250 396 550 "
87 : "396 899 0 313-88 576-265 787-177 212-386 318"
88 : "-627 318-191 0-308-94-352-281-133 187-315 281"
89 : "-546 281-172 0-315-67-428-200-113-133-170-301"
90 : "-170-505 0-277 90-527 271-751 181-223 394"
91 : "-335 640-335 196 0 353 83 470 250 13-68 26"
92 : "-136 41-204 96 0 192 0 288 0-74 376-148 752"
93 : "-224 1128-21 101-31 183-31 245 0 39 9 70 26 "
94 : "93 17 24 39 36 67 36 145 0 279-80 400-240 121"
95 : "-160 182-365 182-615 0-288-107-533-322-734"
96 : "-215-201-487-301-816-301-395 0-715 124-960 "
97 : "373-245 249-368 569-368 958 0 385 119 685 "
98 : "357 900 237 216 557 324 958 325 189-1 389-27 "
99 2 : "600-77 211-52 378-110 503-174 27 70 54 140 81 210z";
100 :
101 : // first part of 'Hello World' as a line polygon
102 2 : aPath3 = "m1598 125h306v2334h-306v-1105h-1293v1105h-305v"
103 : "-2334h305v973h1293zm2159 1015 78-44 85 235-91 "
104 : "47-91 40-90 34-90 29-89 21-88 16-88 10-88 3-102"
105 : "-4-97-12-91-19-85-26-40-16-39-18-38-20-36-22-34"
106 : "-24-33-26-32-27-30-30-29-31-27-33-25-33-23-36-21"
107 : "-36-19-38-18-40-16-40-26-86-18-91-11-97-4-103 3"
108 : "-98 11-94 17-89 24-84 31-79 37-75 22-35 23-34 24"
109 : "-33 27-32 28-30 29-28 31-27 31-24 33-22 34-21 35"
110 : "-18 37-17 38-14 38-13 41-11 41-8 86-12 91-4 82 4 "
111 : "78 10 37 9 37 9 36 12 35 14 33 15 33 17 32 19 31 "
112 : "21 30 22 30 25 55 54 26 29 24 31 22 32 21 33 19 "
113 : "34 18 36 30 74 23 80 17 84 10 89 3 94v78h-1277l6 "
114 : "75 10 70 14 66 19 62 23 57 13 26 14 26 15 25 17 "
115 : "23 17 22 19 21 19 20 21 18 21 18 23 16 23 14 24 "
116 : "14 26 12 26 11 27 10 28 8 59 13 63 7 67 3 80-3 81"
117 : "-9 79-14 80-21 78-26 79-32zm-1049-808-12 53h963l"
118 : "-7-51-11-49-14-46-17-43-21-40-24-38-27-36-31-32"
119 : "-33-29-35-25-37-22-38-17-40-14-41-9-42-6-44-2-48 "
120 : "2-46 6-44 9-42 13-40 17-38 21-36 24-34 28-32 32"
121 : "-29 34-26 38-23 41-20 44-17 47zm1648-1293h288v"
122 : "2459h-288zm752-2459h288v2459h-288zm1286-1750 86-11 "
123 : "91-4 91 4 85 12 42 8 39 11 39 13 38 14 36 17 35 18 "
124 : "34 20 33 23 31 24 30 26 29 28 28 30 26 32 25 33 23 "
125 : "34 21 35 37 75 31 80 24 84 16 90 11 94 3 100-3 100"
126 : "-11 95-16 89-24 85-31 80-37 74-21 35-23 35-25 32-26 "
127 : "32-28 30-29 28-30 26-31 24-33 22-34 21-35 18-36 17"
128 : "-38 14-39 13-39 10-42 9-85 12-91 4-91-4-86-12-41-9"
129 : "-40-10-39-13-37-14-36-17-35-18-34-21-33-22-31-24-30"
130 : "-26-29-28-28-30-26-32-25-32-23-35-21-35-38-74-30-80"
131 : "-24-85-17-89-11-95-3-100 3-101 11-95 17-90 24-85 30"
132 : "-79 38-75 21-35 23-35 25-32 26-32 28-30 29-28 30-26 "
133 2 : "31-24 33-22 34-20 35-18 36-16 37-15 39-12 40-11z";
134 2 : }
135 :
136 2 : void tearDown() SAL_OVERRIDE
137 : {
138 2 : }
139 :
140 2 : void impex()
141 : {
142 2 : B2DPolyPolygon aPoly;
143 4 : OUString aExport;
144 :
145 4 : CPPUNIT_ASSERT_MESSAGE("importing simple rectangle from SVG-D",
146 2 : tools::importFromSvgD( aPoly, aPath0, false, 0 ));
147 2 : aExport = tools::exportToSvgD( aPoly, true, true, false );
148 2 : const char* sExportString = "m10 10h-20v-20h20z";
149 4 : CPPUNIT_ASSERT_MESSAGE("exporting rectangle to SVG-D",
150 2 : aExport.equalsAscii(sExportString) );
151 4 : CPPUNIT_ASSERT_MESSAGE("importing simple rectangle from SVG-D (round-trip",
152 2 : tools::importFromSvgD( aPoly, aExport, false, 0 ));
153 2 : aExport = tools::exportToSvgD( aPoly, true, true, false );
154 4 : CPPUNIT_ASSERT_MESSAGE("exporting rectangle to SVG-D (round-trip)",
155 2 : aExport.equalsAscii(sExportString));
156 :
157 4 : CPPUNIT_ASSERT_MESSAGE("importing simple bezier polygon from SVG-D",
158 2 : tools::importFromSvgD( aPoly, aPath1, false, 0 ));
159 2 : aExport = tools::exportToSvgD( aPoly, true, true, false );
160 :
161 : // Adaptions for B2DPolygon bezier change (see #i77162#):
162 :
163 : // The import/export of aPath1 does not reproduce aExport again. This is
164 : // correct since aPath1 contains a segment with non-used control points
165 : // which gets exported now correctly as 'l' and also a point (#4, index 3)
166 : // with C2 continuity which produces a 's' staement now.
167 :
168 : // The old SVGexport identified nun-used ControlVectors erraneously as bezier segments
169 : // because the 2nd vector at the start point was used, even when added
170 : // with start point was identical to end point. Exactly for that reason
171 : // i reworked the B2DPolygon to use prev, next control points.
172 :
173 : // so for correct unit test i add the new exported string here as sExportStringSimpleBezier
174 : // and compare to it.
175 : const char* sExportStringSimpleBezier =
176 : "m11430 0c-8890 3810 5715 6985 5715 6985"
177 : "l-17145-1905c0 0 22860-10160 16510 6350"
178 2 : "s-3810-11430-3810-11430z";
179 2 : CPPUNIT_ASSERT_MESSAGE("exporting bezier polygon to SVG-D", aExport.equalsAscii(sExportStringSimpleBezier));
180 :
181 : // Adaptions for B2DPolygon bezier change (see #i77162#):
182 :
183 : // a 2nd good test is that re-importing of aExport has to create the same
184 : // B2DPolPolygon again:
185 4 : B2DPolyPolygon aReImport;
186 2 : CPPUNIT_ASSERT_MESSAGE("importing simple bezier polygon from SVG-D", tools::importFromSvgD( aReImport, aExport, false, 0));
187 2 : CPPUNIT_ASSERT_MESSAGE("re-imported polygon needs to be identical", aReImport == aPoly);
188 :
189 2 : CPPUNIT_ASSERT_MESSAGE("importing '@' from SVG-D", tools::importFromSvgD( aPoly, aPath2, false, NULL));
190 2 : aExport = tools::exportToSvgD( aPoly, true, true, false );
191 :
192 : // Adaptions for B2DPolygon bezier change (see #i77162#):
193 :
194 : // same here, the corrected export with the corrected B2DPolygon is simply more efficient,
195 : // so i needed to change the compare string. Also adding the re-import comparison below.
196 : const char* sExportString1 =
197 : "m1917 1114c-89-189-233-284-430-284-167 0-306 91-419 273s-170 370-17"
198 : "0 564c0 145 33 259 98 342 65 84 150 126 257 126q115.5 0 231-57s147-97 210-176 99-143 109-190c38-199 76-398 114"
199 : "-598zm840 1646c-133 73-312 139-537 197-225 57-440 86-644 87-483-1-866-132-1150-392-284-261-426-619-426-1076 0-"
200 : "292 67-560 200-803s321-433 562-569 514-204 821-204c405 0 739 125 1003 374 264 250 396 550 396 899 0 313-88 576"
201 : "-265 787q-265.5 318-627 318c-191 0-308-94-352-281-133 187-315 281-546 281-172 0-315-67-428-200s-170-301-170-50"
202 : "5c0-277 90-527 271-751 181-223 394-335 640-335 196 0 353 83 470 250 13-68 26-136 41-204q144 0 288 0c-74 376-14"
203 : "8 752-224 1128-21 101-31 183-31 245 0 39 9 70 26 93 17 24 39 36 67 36 145 0 279-80 400-240s182-365 182-615c0-2"
204 : "88-107-533-322-734s-487-301-816-301c-395 0-715 124-960 373s-368 569-368 958q0 577.5 357 900c237 216 557 324 95"
205 2 : "8 325 189-1 389-27 600-77 211-52 378-110 503-174q40.5 105 81 210z";
206 2 : CPPUNIT_ASSERT_MESSAGE("re-importing '@' from SVG-D", tools::importFromSvgD( aReImport, aExport, false, 0));
207 2 : CPPUNIT_ASSERT_MESSAGE("re-imported '@' needs to be identical", aReImport == aPoly);
208 :
209 2 : CPPUNIT_ASSERT_MESSAGE("exporting '@' to SVG-D", aExport.equalsAscii(sExportString1));
210 4 : CPPUNIT_ASSERT_MESSAGE("importing '@' from SVG-D (round-trip",
211 2 : tools::importFromSvgD( aPoly, aExport, false, 0 ));
212 2 : aExport = tools::exportToSvgD( aPoly, true, true, false );
213 4 : CPPUNIT_ASSERT_MESSAGE("exporting '@' to SVG-D (round-trip)",
214 2 : aExport.equalsAscii(sExportString1));
215 :
216 4 : CPPUNIT_ASSERT_MESSAGE("importing complex polygon from SVG-D",
217 2 : tools::importFromSvgD( aPoly, aPath3, false, 0 ));
218 2 : aExport = tools::exportToSvgD( aPoly, true, true, false );
219 : const char* sExportString2 =
220 : "m1598 125h306v2334h-306v-1105h-1293v1105h-305v-2334h305v973h1293"
221 : "zm2159 1015 78-44 85 235-91 47-91 40-90 34-90 29-89 21-88 16-88 10-88 3-102-4-97"
222 : "-12-91-19-85-26-40-16-39-18-38-20-36-22-34-24-33-26-32-27-30-30-29-31-27-33-25-3"
223 : "3-23-36-21-36-19-38-18-40-16-40-26-86-18-91-11-97-4-103 3-98 11-94 17-89 24-84 3"
224 : "1-79 37-75 22-35 23-34 24-33 27-32 28-30 29-28 31-27 31-24 33-22 34-21 35-18 37-"
225 : "17 38-14 38-13 41-11 41-8 86-12 91-4 82 4 78 10 37 9 37 9 36 12 35 14 33 15 33 1"
226 : "7 32 19 31 21 30 22 30 25 55 54 26 29 24 31 22 32 21 33 19 34 18 36 30 74 23 80 "
227 : "17 84 10 89 3 94v78h-1277l6 75 10 70 14 66 19 62 23 57 13 26 14 26 15 25 17 23 1"
228 : "7 22 19 21 19 20 21 18 21 18 23 16 23 14 24 14 26 12 26 11 27 10 28 8 59 13 63 7"
229 : " 67 3 80-3 81-9 79-14 80-21 78-26 79-32zm-1049-808-12 53h963l-7-51-11-49-14-46-1"
230 : "7-43-21-40-24-38-27-36-31-32-33-29-35-25-37-22-38-17-40-14-41-9-42-6-44-2-48 2-4"
231 : "6 6-44 9-42 13-40 17-38 21-36 24-34 28-32 32-29 34-26 38-23 41-20 44-17 47zm1648"
232 : "-1293h288v2459h-288zm752-2459h288v2459h-288zm1286-1750 86-11 91-4 91 4 85 12 42 "
233 : "8 39 11 39 13 38 14 36 17 35 18 34 20 33 23 31 24 30 26 29 28 28 30 26 32 25 33 "
234 : "23 34 21 35 37 75 31 80 24 84 16 90 11 94 3 100-3 100-11 95-16 89-24 85-31 80-37"
235 : " 74-21 35-23 35-25 32-26 32-28 30-29 28-30 26-31 24-33 22-34 21-35 18-36 17-38 1"
236 : "4-39 13-39 10-42 9-85 12-91 4-91-4-86-12-41-9-40-10-39-13-37-14-36-17-35-18-34-2"
237 : "1-33-22-31-24-30-26-29-28-28-30-26-32-25-32-23-35-21-35-38-74-30-80-24-85-17-89-"
238 : "11-95-3-100 3-101 11-95 17-90 24-85 30-79 38-75 21-35 23-35 25-32 26-32 28-30 29"
239 2 : "-28 30-26 31-24 33-22 34-20 35-18 36-16 37-15 39-12 40-11z";
240 4 : CPPUNIT_ASSERT_MESSAGE("exporting complex polygon to SVG-D",
241 2 : aExport.equalsAscii(sExportString2));
242 4 : CPPUNIT_ASSERT_MESSAGE("importing complex polygon from SVG-D (round-trip",
243 2 : tools::importFromSvgD( aPoly, aExport, false, 0 ));
244 2 : aExport = tools::exportToSvgD( aPoly, true, true, false );
245 4 : CPPUNIT_ASSERT_MESSAGE("exporting complex polygon to SVG-D (round-trip)",
246 2 : aExport.equalsAscii(sExportString2));
247 :
248 : const B2DPolygon aRect(
249 4 : tools::createPolygonFromRect( B2DRange(0.0,0.0,4000.0,4000.0) ));
250 2 : aExport = tools::exportToSvgD( B2DPolyPolygon(aRect), false, false, false );
251 :
252 2 : const char* sExportStringRect = "M0 0H4000V4000H0Z";
253 4 : CPPUNIT_ASSERT_MESSAGE("exporting to rectangle svg-d string",
254 4 : aExport.equalsAscii(sExportStringRect));
255 2 : }
256 :
257 : // Change the following lines only, if you add, remove or rename
258 : // member functions of the current class,
259 : // because these macros are need by auto register mechanism.
260 :
261 4 : CPPUNIT_TEST_SUITE(b2dsvgdimpex);
262 2 : CPPUNIT_TEST(impex);
263 4 : CPPUNIT_TEST_SUITE_END();
264 : }; // class b2dsvgdimpex
265 :
266 6 : class b2drange : public CppUnit::TestFixture
267 : {
268 : private:
269 : public:
270 2 : void check()
271 : {
272 4 : CPPUNIT_ASSERT_MESSAGE("simple range rounding from double to integer",
273 2 : fround(B2DRange(1.2, 2.3, 3.5, 4.8)) == B2IRange(1, 2, 4, 5));
274 2 : }
275 :
276 : // Change the following lines only, if you add, remove or rename
277 : // member functions of the current class,
278 : // because these macros are need by auto register mechanism.
279 :
280 4 : CPPUNIT_TEST_SUITE(b2drange);
281 2 : CPPUNIT_TEST(check);
282 4 : CPPUNIT_TEST_SUITE_END();
283 : };
284 :
285 6 : class b2dpolyrange : public CppUnit::TestFixture
286 : {
287 : private:
288 : public:
289 2 : void check()
290 : {
291 2 : B2DPolyRange aRange;
292 2 : aRange.appendElement(B2DRange(0,0,1,1),ORIENTATION_POSITIVE);
293 2 : aRange.appendElement(B2DRange(2,2,3,3),ORIENTATION_POSITIVE);
294 :
295 4 : CPPUNIT_ASSERT_MESSAGE("simple poly range - count",
296 2 : aRange.count() == 2);
297 4 : CPPUNIT_ASSERT_MESSAGE("simple poly range - first element",
298 2 : aRange.getElement(0).head == B2DRange(0,0,1,1));
299 4 : CPPUNIT_ASSERT_MESSAGE("simple poly range - second element",
300 2 : aRange.getElement(1).head == B2DRange(2,2,3,3));
301 :
302 : // B2DPolyRange relies on correctly orientated rects
303 2 : const B2DRange aRect(0,0,1,1);
304 4 : CPPUNIT_ASSERT_MESSAGE("createPolygonFromRect - correct orientation",
305 : tools::getOrientation(
306 4 : tools::createPolygonFromRect(aRect)) == ORIENTATION_POSITIVE );
307 2 : }
308 :
309 : // Change the following lines only, if you add, remove or rename
310 : // member functions of the current class,
311 : // because these macros are need by auto register mechanism.
312 :
313 4 : CPPUNIT_TEST_SUITE(b2dpolyrange);
314 2 : CPPUNIT_TEST(check);
315 4 : CPPUNIT_TEST_SUITE_END();
316 : };
317 :
318 48 : class b2dhommatrix : public CppUnit::TestFixture
319 : {
320 : private:
321 : B2DHomMatrix maIdentity;
322 : B2DHomMatrix maScale;
323 : B2DHomMatrix maTranslate;
324 : B2DHomMatrix maShear;
325 : B2DHomMatrix maAffine;
326 : B2DHomMatrix maPerspective;
327 :
328 : public:
329 : // initialise your test code values here.
330 16 : void setUp() SAL_OVERRIDE
331 : {
332 : // setup some test matrices
333 16 : maIdentity.identity(); // force compact layout
334 16 : maIdentity.set(0,0, 1.0);
335 16 : maIdentity.set(0,1, 0.0);
336 16 : maIdentity.set(0,2, 0.0);
337 16 : maIdentity.set(1,0, 0.0);
338 16 : maIdentity.set(1,1, 1.0);
339 16 : maIdentity.set(1,2, 0.0);
340 :
341 16 : maScale.identity(); // force compact layout
342 16 : maScale.set(0,0, 2.0);
343 16 : maScale.set(1,1, 20.0);
344 :
345 16 : maTranslate.identity(); // force compact layout
346 16 : maTranslate.set(0,2, 20.0);
347 16 : maTranslate.set(1,2, 2.0);
348 :
349 16 : maShear.identity(); // force compact layout
350 16 : maShear.set(0,1, 3.0);
351 16 : maShear.set(1,0, 7.0);
352 16 : maShear.set(1,1, 22.0);
353 :
354 16 : maAffine.identity(); // force compact layout
355 16 : maAffine.set(0,0, 1.0);
356 16 : maAffine.set(0,1, 2.0);
357 16 : maAffine.set(0,2, 3.0);
358 16 : maAffine.set(1,0, 4.0);
359 16 : maAffine.set(1,1, 5.0);
360 16 : maAffine.set(1,2, 6.0);
361 :
362 16 : maPerspective.set(0,0, 1.0);
363 16 : maPerspective.set(0,1, 2.0);
364 16 : maPerspective.set(0,2, 3.0);
365 16 : maPerspective.set(1,0, 4.0);
366 16 : maPerspective.set(1,1, 5.0);
367 16 : maPerspective.set(1,2, 6.0);
368 16 : maPerspective.set(2,0, 7.0);
369 16 : maPerspective.set(2,1, 8.0);
370 16 : maPerspective.set(2,2, 9.0);
371 16 : }
372 :
373 16 : void tearDown() SAL_OVERRIDE
374 : {
375 16 : }
376 :
377 2 : void equal()
378 : {
379 2 : B2DHomMatrix aIdentity;
380 4 : B2DHomMatrix aScale;
381 4 : B2DHomMatrix aTranslate;
382 4 : B2DHomMatrix aShear;
383 4 : B2DHomMatrix aAffine;
384 4 : B2DHomMatrix aPerspective;
385 :
386 : // setup some test matrices
387 2 : aIdentity.identity(); // force compact layout
388 2 : aIdentity.set(0,0, 1.0);
389 2 : aIdentity.set(0,1, 0.0);
390 2 : aIdentity.set(0,2, 0.0);
391 2 : aIdentity.set(1,0, 0.0);
392 2 : aIdentity.set(1,1, 1.0);
393 2 : aIdentity.set(1,2, 0.0);
394 :
395 2 : aScale.identity(); // force compact layout
396 2 : aScale.set(0,0, 2.0);
397 2 : aScale.set(1,1, 20.0);
398 :
399 2 : aTranslate.identity(); // force compact layout
400 2 : aTranslate.set(0,2, 20.0);
401 2 : aTranslate.set(1,2, 2.0);
402 :
403 2 : aShear.identity(); // force compact layout
404 2 : aShear.set(0,1, 3.0);
405 2 : aShear.set(1,0, 7.0);
406 2 : aShear.set(1,1, 22.0);
407 :
408 2 : aAffine.identity(); // force compact layout
409 2 : aAffine.set(0,0, 1.0);
410 2 : aAffine.set(0,1, 2.0);
411 2 : aAffine.set(0,2, 3.0);
412 2 : aAffine.set(1,0, 4.0);
413 2 : aAffine.set(1,1, 5.0);
414 2 : aAffine.set(1,2, 6.0);
415 :
416 2 : aPerspective.set(0,0, 1.0);
417 2 : aPerspective.set(0,1, 2.0);
418 2 : aPerspective.set(0,2, 3.0);
419 2 : aPerspective.set(1,0, 4.0);
420 2 : aPerspective.set(1,1, 5.0);
421 2 : aPerspective.set(1,2, 6.0);
422 2 : aPerspective.set(2,0, 7.0);
423 2 : aPerspective.set(2,1, 8.0);
424 2 : aPerspective.set(2,2, 9.0);
425 :
426 2 : CPPUNIT_ASSERT_MESSAGE("operator==: identity matrix", aIdentity == maIdentity);
427 2 : CPPUNIT_ASSERT_MESSAGE("operator==: scale matrix", aScale == maScale);
428 2 : CPPUNIT_ASSERT_MESSAGE("operator==: translate matrix", aTranslate == maTranslate);
429 2 : CPPUNIT_ASSERT_MESSAGE("operator==: shear matrix", aShear == maShear);
430 2 : CPPUNIT_ASSERT_MESSAGE("operator==: affine matrix", aAffine == maAffine);
431 4 : CPPUNIT_ASSERT_MESSAGE("operator==: perspective matrix", aPerspective == maPerspective);
432 2 : }
433 :
434 2 : void identity()
435 : {
436 2 : B2DHomMatrix ident;
437 :
438 2 : CPPUNIT_ASSERT_MESSAGE("identity", maIdentity == ident);
439 2 : }
440 :
441 2 : void scale()
442 : {
443 2 : B2DHomMatrix mat;
444 2 : mat.scale(2.0,20.0);
445 2 : CPPUNIT_ASSERT_MESSAGE("scale", maScale == mat);
446 2 : }
447 :
448 2 : void rotate()
449 : {
450 2 : B2DHomMatrix mat;
451 2 : mat.rotate(90*F_PI180);
452 4 : CPPUNIT_ASSERT_MESSAGE("rotate pi/2 yields exact matrix",
453 : mat.get(0,0) == 0.0 &&
454 : mat.get(0,1) == -1.0 &&
455 : mat.get(0,2) == 0.0 &&
456 : mat.get(1,0) == 1.0 &&
457 : mat.get(1,1) == 0.0 &&
458 2 : mat.get(1,2) == 0.0);
459 2 : mat.rotate(90*F_PI180);
460 4 : CPPUNIT_ASSERT_MESSAGE("rotate pi yields exact matrix",
461 : mat.get(0,0) == -1.0 &&
462 : mat.get(0,1) == 0.0 &&
463 : mat.get(0,2) == 0.0 &&
464 : mat.get(1,0) == 0.0 &&
465 : mat.get(1,1) == -1.0 &&
466 2 : mat.get(1,2) == 0.0);
467 2 : mat.rotate(90*F_PI180);
468 4 : CPPUNIT_ASSERT_MESSAGE("rotate 3/2 pi yields exact matrix",
469 : mat.get(0,0) == 0.0 &&
470 : mat.get(0,1) == 1.0 &&
471 : mat.get(0,2) == 0.0 &&
472 : mat.get(1,0) == -1.0 &&
473 : mat.get(1,1) == 0.0 &&
474 2 : mat.get(1,2) == 0.0);
475 2 : mat.rotate(90*F_PI180);
476 4 : CPPUNIT_ASSERT_MESSAGE("rotate 2 pi yields exact matrix",
477 : mat.get(0,0) == 1.0 &&
478 : mat.get(0,1) == 0.0 &&
479 : mat.get(0,2) == 0.0 &&
480 : mat.get(1,0) == 0.0 &&
481 : mat.get(1,1) == 1.0 &&
482 4 : mat.get(1,2) == 0.0);
483 2 : }
484 :
485 2 : void translate()
486 : {
487 2 : B2DHomMatrix mat;
488 2 : mat.translate(20.0,2.0);
489 2 : CPPUNIT_ASSERT_MESSAGE("translate", maTranslate == mat);
490 2 : }
491 :
492 2 : void shear()
493 : {
494 2 : B2DHomMatrix mat;
495 2 : mat.shearX(3.0);
496 2 : mat.shearY(7.0);
497 2 : CPPUNIT_ASSERT_MESSAGE("translate", maShear == mat);
498 2 : }
499 :
500 2 : void multiply()
501 : {
502 2 : B2DHomMatrix affineAffineProd;
503 :
504 2 : affineAffineProd.set(0,0, 9);
505 2 : affineAffineProd.set(0,1, 12);
506 2 : affineAffineProd.set(0,2, 18);
507 2 : affineAffineProd.set(1,0, 24);
508 2 : affineAffineProd.set(1,1, 33);
509 2 : affineAffineProd.set(1,2, 48);
510 :
511 4 : B2DHomMatrix affinePerspectiveProd;
512 :
513 2 : affinePerspectiveProd.set(0,0, 30);
514 2 : affinePerspectiveProd.set(0,1, 36);
515 2 : affinePerspectiveProd.set(0,2, 42);
516 2 : affinePerspectiveProd.set(1,0, 66);
517 2 : affinePerspectiveProd.set(1,1, 81);
518 2 : affinePerspectiveProd.set(1,2, 96);
519 2 : affinePerspectiveProd.set(2,0, 7);
520 2 : affinePerspectiveProd.set(2,1, 8);
521 2 : affinePerspectiveProd.set(2,2, 9);
522 :
523 4 : B2DHomMatrix perspectiveAffineProd;
524 :
525 2 : perspectiveAffineProd.set(0,0, 9);
526 2 : perspectiveAffineProd.set(0,1, 12);
527 2 : perspectiveAffineProd.set(0,2, 18);
528 2 : perspectiveAffineProd.set(1,0, 24);
529 2 : perspectiveAffineProd.set(1,1, 33);
530 2 : perspectiveAffineProd.set(1,2, 48);
531 2 : perspectiveAffineProd.set(2,0, 39);
532 2 : perspectiveAffineProd.set(2,1, 54);
533 2 : perspectiveAffineProd.set(2,2, 78);
534 :
535 4 : B2DHomMatrix perspectivePerspectiveProd;
536 :
537 2 : perspectivePerspectiveProd.set(0,0, 30);
538 2 : perspectivePerspectiveProd.set(0,1, 36);
539 2 : perspectivePerspectiveProd.set(0,2, 42);
540 2 : perspectivePerspectiveProd.set(1,0, 66);
541 2 : perspectivePerspectiveProd.set(1,1, 81);
542 2 : perspectivePerspectiveProd.set(1,2, 96);
543 2 : perspectivePerspectiveProd.set(2,0, 102);
544 2 : perspectivePerspectiveProd.set(2,1, 126);
545 2 : perspectivePerspectiveProd.set(2,2, 150);
546 :
547 4 : B2DHomMatrix temp;
548 :
549 2 : temp = maAffine;
550 2 : temp*=maAffine;
551 2 : CPPUNIT_ASSERT_MESSAGE("multiply: both compact", temp == affineAffineProd);
552 :
553 2 : temp = maPerspective;
554 2 : temp*=maAffine;
555 2 : CPPUNIT_ASSERT_MESSAGE("multiply: first compact", temp == affinePerspectiveProd);
556 :
557 2 : temp = maAffine;
558 2 : temp*=maPerspective;
559 2 : CPPUNIT_ASSERT_MESSAGE("multiply: second compact", temp == perspectiveAffineProd);
560 :
561 2 : temp = maPerspective;
562 2 : temp*=maPerspective;
563 4 : CPPUNIT_ASSERT_MESSAGE("multiply: none compact", temp == perspectivePerspectiveProd);
564 2 : }
565 :
566 144 : void impFillMatrix(B2DHomMatrix& rSource, double fScaleX, double fScaleY, double fShearX, double fRotate)
567 : {
568 : // fill rSource with a linear combination of scale, shear and rotate
569 144 : rSource.identity();
570 144 : rSource.scale(fScaleX, fScaleY);
571 144 : rSource.shearX(fShearX);
572 144 : rSource.rotate(fRotate);
573 144 : }
574 :
575 72 : bool impDecomposeComposeTest(double fScaleX, double fScaleY, double fShearX, double fRotate)
576 : {
577 : // linear combine matrix with given values
578 72 : B2DHomMatrix aSource;
579 72 : impFillMatrix(aSource, fScaleX, fScaleY, fShearX, fRotate);
580 :
581 : // decompose that matrix
582 144 : B2DTuple aDScale;
583 144 : B2DTuple aDTrans;
584 : double fDRot;
585 : double fDShX;
586 72 : bool bWorked = aSource.decompose(aDScale, aDTrans, fDRot, fDShX);
587 :
588 : // linear combine another matrix with decomposition results
589 144 : B2DHomMatrix aRecombined;
590 72 : impFillMatrix(aRecombined, aDScale.getX(), aDScale.getY(), fDShX, fDRot);
591 :
592 : // if decomposition worked, matrices need to be the same
593 144 : return bWorked && aSource == aRecombined;
594 : }
595 :
596 2 : void decompose()
597 : {
598 : // test matrix decompositions. Each matrix decomposed and rebuilt
599 : // using the decompose result should be the same as before. Test
600 : // with all ranges of values. Translations are not tested since these
601 : // are just the two rightmost values and uncritical
602 : static double fSX(10.0);
603 : static double fSY(12.0);
604 : static double fR(45.0 * F_PI180);
605 : static double fS(15.0 * F_PI180);
606 :
607 : // check all possible scaling combinations
608 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test A1", impDecomposeComposeTest(fSX, fSY, 0.0, 0.0));
609 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test A2", impDecomposeComposeTest(-fSX, fSY, 0.0, 0.0));
610 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test A3", impDecomposeComposeTest(fSX, -fSY, 0.0, 0.0));
611 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test A4", impDecomposeComposeTest(-fSX, -fSY, 0.0, 0.0));
612 :
613 : // check all possible scaling combinations with positive rotation
614 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test B1", impDecomposeComposeTest(fSX, fSY, 0.0, fR));
615 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test B2", impDecomposeComposeTest(-fSX, fSY, 0.0, fR));
616 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test B3", impDecomposeComposeTest(fSX, -fSY, 0.0, fR));
617 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test B4", impDecomposeComposeTest(-fSX, -fSY, 0.0, fR));
618 :
619 : // check all possible scaling combinations with negative rotation
620 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test C1", impDecomposeComposeTest(fSX, fSY, 0.0, -fR));
621 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test C2", impDecomposeComposeTest(-fSX, fSY, 0.0, -fR));
622 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test C3", impDecomposeComposeTest(fSX, -fSY, 0.0, -fR));
623 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test C4", impDecomposeComposeTest(-fSX, -fSY, 0.0, -fR));
624 :
625 : // check all possible scaling combinations with positive shear
626 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test D1", impDecomposeComposeTest(fSX, fSY, tan(fS), 0.0));
627 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test D2", impDecomposeComposeTest(-fSX, fSY, tan(fS), 0.0));
628 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test D3", impDecomposeComposeTest(fSX, -fSY, tan(fS), 0.0));
629 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test D4", impDecomposeComposeTest(-fSX, -fSY, tan(fS), 0.0));
630 :
631 : // check all possible scaling combinations with negative shear
632 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test E1", impDecomposeComposeTest(fSX, fSY, tan(-fS), 0.0));
633 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test E2", impDecomposeComposeTest(-fSX, fSY, tan(-fS), 0.0));
634 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test E3", impDecomposeComposeTest(fSX, -fSY, tan(-fS), 0.0));
635 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test E4", impDecomposeComposeTest(-fSX, -fSY, tan(-fS), 0.0));
636 :
637 : // check all possible scaling combinations with positive rotate and positive shear
638 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test F1", impDecomposeComposeTest(fSX, fSY, tan(fS), fR));
639 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test F2", impDecomposeComposeTest(-fSX, fSY, tan(fS), fR));
640 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test F3", impDecomposeComposeTest(fSX, -fSY, tan(fS), fR));
641 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test F4", impDecomposeComposeTest(-fSX, -fSY, tan(fS), fR));
642 :
643 : // check all possible scaling combinations with negative rotate and positive shear
644 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test G1", impDecomposeComposeTest(fSX, fSY, tan(fS), -fR));
645 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test G2", impDecomposeComposeTest(-fSX, fSY, tan(fS), -fR));
646 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test G3", impDecomposeComposeTest(fSX, -fSY, tan(fS), -fR));
647 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test G4", impDecomposeComposeTest(-fSX, -fSY, tan(fS), -fR));
648 :
649 : // check all possible scaling combinations with positive rotate and negative shear
650 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test H1", impDecomposeComposeTest(fSX, fSY, tan(-fS), fR));
651 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test H2", impDecomposeComposeTest(-fSX, fSY, tan(-fS), fR));
652 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test H3", impDecomposeComposeTest(fSX, -fSY, tan(-fS), fR));
653 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test H4", impDecomposeComposeTest(-fSX, -fSY, tan(-fS), fR));
654 :
655 : // check all possible scaling combinations with negative rotate and negative shear
656 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test I1", impDecomposeComposeTest(fSX, fSY, tan(-fS), -fR));
657 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test I2", impDecomposeComposeTest(-fSX, fSY, tan(-fS), -fR));
658 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test I3", impDecomposeComposeTest(fSX, -fSY, tan(-fS), -fR));
659 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test I4", impDecomposeComposeTest(-fSX, -fSY, tan(-fS), -fR));
660 :
661 : // cover special case of 180 degree rotation
662 : B2DHomMatrix aTest=tools::createScaleShearXRotateTranslateB2DHomMatrix(
663 : 6425,3938,
664 : 0,
665 : 180*F_PI180,
666 2 : 10482,4921);
667 : // decompose that matrix
668 4 : B2DTuple aDScale;
669 4 : B2DTuple aDTrans;
670 : double fDRot;
671 : double fDShX;
672 2 : aTest.decompose(aDScale, aDTrans, fDRot, fDShX);
673 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDScale.getX() == 6425 && aDScale.getY() == 3938);
674 2 : CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDTrans.getX() == 10482 && aDTrans.getY() == 4921);
675 4 : CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", fDRot == 180*F_PI180);
676 2 : }
677 :
678 : // Change the following lines only, if you add, remove or rename
679 : // member functions of the current class,
680 : // because these macros are need by auto register mechanism.
681 :
682 4 : CPPUNIT_TEST_SUITE(b2dhommatrix);
683 2 : CPPUNIT_TEST(equal);
684 2 : CPPUNIT_TEST(identity);
685 2 : CPPUNIT_TEST(scale);
686 2 : CPPUNIT_TEST(translate);
687 2 : CPPUNIT_TEST(rotate);
688 2 : CPPUNIT_TEST(shear);
689 2 : CPPUNIT_TEST(multiply);
690 2 : CPPUNIT_TEST(decompose);
691 4 : CPPUNIT_TEST_SUITE_END();
692 :
693 : }; // class b2dhommatrix
694 :
695 6 : class b2dpoint : public CppUnit::TestFixture
696 : {
697 : public:
698 : // insert your test code here.
699 : // this is only demonstration code
700 2 : void EmptyMethod()
701 : {
702 : // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
703 2 : }
704 :
705 : // Change the following lines only, if you add, remove or rename
706 : // member functions of the current class,
707 : // because these macros are need by auto register mechanism.
708 :
709 4 : CPPUNIT_TEST_SUITE(b2dpoint);
710 2 : CPPUNIT_TEST(EmptyMethod);
711 4 : CPPUNIT_TEST_SUITE_END();
712 : }; // class b2dpoint
713 :
714 6 : class b2dpolygon : public CppUnit::TestFixture
715 : {
716 : public:
717 : // insert your test code here.
718 2 : void testBasics()
719 : {
720 2 : B2DPolygon aPoly;
721 :
722 2 : aPoly.appendBezierSegment(B2DPoint(1,1),B2DPoint(2,2),B2DPoint(3,3));
723 :
724 4 : CPPUNIT_ASSERT_MESSAGE("#1 first polygon point wrong",
725 2 : aPoly.getB2DPoint(0) == B2DPoint(3,3));
726 4 : CPPUNIT_ASSERT_MESSAGE("#1 first control point wrong",
727 2 : aPoly.getPrevControlPoint(0) == B2DPoint(2,2));
728 4 : CPPUNIT_ASSERT_MESSAGE("#1 second control point wrong",
729 2 : aPoly.getNextControlPoint(0) == B2DPoint(3,3));
730 4 : CPPUNIT_ASSERT_MESSAGE("next control point not used",
731 2 : aPoly.isNextControlPointUsed(0) == false);
732 :
733 2 : aPoly.setNextControlPoint(0,B2DPoint(4,4));
734 4 : CPPUNIT_ASSERT_MESSAGE("#1.1 second control point wrong",
735 2 : aPoly.getNextControlPoint(0) == B2DPoint(4,4));
736 4 : CPPUNIT_ASSERT_MESSAGE("next control point used",
737 2 : aPoly.isNextControlPointUsed(0) == true);
738 4 : CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong",
739 2 : aPoly.areControlPointsUsed() == true);
740 4 : CPPUNIT_ASSERT_MESSAGE("getContinuityInPoint() wrong",
741 2 : aPoly.getContinuityInPoint(0) == CONTINUITY_C2);
742 :
743 2 : aPoly.resetControlPoints();
744 4 : CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
745 2 : aPoly.getB2DPoint(0) == B2DPoint(3,3));
746 4 : CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
747 2 : aPoly.getPrevControlPoint(0) == B2DPoint(3,3));
748 4 : CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
749 2 : aPoly.getNextControlPoint(0) == B2DPoint(3,3));
750 4 : CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong #2",
751 2 : aPoly.areControlPointsUsed() == false);
752 :
753 2 : aPoly.clear();
754 2 : aPoly.append(B2DPoint(0,0));
755 2 : aPoly.appendBezierSegment(B2DPoint(1,1),B2DPoint(2,2),B2DPoint(3,3));
756 :
757 4 : CPPUNIT_ASSERT_MESSAGE("#2 first polygon point wrong",
758 2 : aPoly.getB2DPoint(0) == B2DPoint(0,0));
759 4 : CPPUNIT_ASSERT_MESSAGE("#2 first control point wrong",
760 2 : aPoly.getPrevControlPoint(0) == B2DPoint(0,0));
761 4 : CPPUNIT_ASSERT_MESSAGE("#2 second control point wrong",
762 2 : aPoly.getNextControlPoint(0) == B2DPoint(1,1));
763 4 : CPPUNIT_ASSERT_MESSAGE("#2 third control point wrong",
764 2 : aPoly.getPrevControlPoint(1) == B2DPoint(2,2));
765 4 : CPPUNIT_ASSERT_MESSAGE("#2 fourth control point wrong",
766 2 : aPoly.getNextControlPoint(1) == B2DPoint(3,3));
767 4 : CPPUNIT_ASSERT_MESSAGE("#2 second polygon point wrong",
768 4 : aPoly.getB2DPoint(1) == B2DPoint(3,3));
769 2 : }
770 : // Change the following lines only, if you add, remove or rename
771 : // member functions of the current class,
772 : // because these macros are need by auto register mechanism.
773 :
774 4 : CPPUNIT_TEST_SUITE(b2dpolygon);
775 2 : CPPUNIT_TEST(testBasics);
776 4 : CPPUNIT_TEST_SUITE_END();
777 : }; // class b2dpolygon
778 :
779 6 : class b2dpolygontools : public CppUnit::TestFixture
780 : {
781 : public:
782 : // insert your test code here.
783 : // this is only demonstration code
784 2 : void testIsRectangle()
785 : {
786 : B2DPolygon aRect1(
787 : tools::createPolygonFromRect(
788 2 : B2DRange(0,0,1,1) ) );
789 :
790 4 : B2DPolygon aRect2;
791 2 : aRect2.append( B2DPoint(0,0) );
792 2 : aRect2.append( B2DPoint(1,0) );
793 2 : aRect2.append( B2DPoint(1,.5));
794 2 : aRect2.append( B2DPoint(1,1) );
795 2 : aRect2.append( B2DPoint(0,1) );
796 2 : aRect2.setClosed(true);
797 :
798 4 : B2DPolygon aNonRect1;
799 2 : aNonRect1.append( B2DPoint(0,0) );
800 2 : aNonRect1.append( B2DPoint(1,0) );
801 2 : aNonRect1.append( B2DPoint(1,1) );
802 2 : aNonRect1.append( B2DPoint(0.5,1) );
803 2 : aNonRect1.append( B2DPoint(0.5,0) );
804 2 : aNonRect1.setClosed(true);
805 :
806 4 : B2DPolygon aNonRect2;
807 2 : aNonRect2.append( B2DPoint(0,0) );
808 2 : aNonRect2.append( B2DPoint(1,1) );
809 2 : aNonRect2.append( B2DPoint(1,0) );
810 2 : aNonRect2.append( B2DPoint(0,1) );
811 2 : aNonRect2.setClosed(true);
812 :
813 4 : B2DPolygon aNonRect3;
814 2 : aNonRect3.append( B2DPoint(0,0) );
815 2 : aNonRect3.append( B2DPoint(1,0) );
816 2 : aNonRect3.append( B2DPoint(1,1) );
817 2 : aNonRect3.setClosed(true);
818 :
819 4 : B2DPolygon aNonRect4;
820 2 : aNonRect4.append( B2DPoint(0,0) );
821 2 : aNonRect4.append( B2DPoint(1,0) );
822 2 : aNonRect4.append( B2DPoint(1,1) );
823 2 : aNonRect4.append( B2DPoint(0,1) );
824 :
825 4 : B2DPolygon aNonRect5;
826 2 : aNonRect5.append( B2DPoint(0,0) );
827 2 : aNonRect5.append( B2DPoint(1,0) );
828 2 : aNonRect5.append( B2DPoint(1,1) );
829 2 : aNonRect5.append( B2DPoint(0,1) );
830 2 : aNonRect5.setControlPoints(1,B2DPoint(1,0),B2DPoint(-11,0));
831 2 : aNonRect5.setClosed(true);
832 :
833 4 : CPPUNIT_ASSERT_MESSAGE("checking rectangle-ness of rectangle 1",
834 2 : tools::isRectangle( aRect1 ));
835 4 : CPPUNIT_ASSERT_MESSAGE("checking rectangle-ness of rectangle 2",
836 2 : tools::isRectangle( aRect2 ));
837 4 : CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 1",
838 2 : !tools::isRectangle( aNonRect1 ));
839 4 : CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 2",
840 2 : !tools::isRectangle( aNonRect2 ));
841 4 : CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 3",
842 2 : !tools::isRectangle( aNonRect3 ));
843 4 : CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 4",
844 2 : !tools::isRectangle( aNonRect4 ));
845 4 : CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 5",
846 4 : !tools::isRectangle( aNonRect5 ));
847 2 : }
848 :
849 : // Change the following lines only, if you add, remove or rename
850 : // member functions of the current class,
851 : // because these macros are need by auto register mechanism.
852 :
853 4 : CPPUNIT_TEST_SUITE(b2dpolygontools);
854 2 : CPPUNIT_TEST(testIsRectangle);
855 4 : CPPUNIT_TEST_SUITE_END();
856 : }; // class b2dpolygontools
857 :
858 6 : class b2dpolypolygon : public CppUnit::TestFixture
859 : {
860 : public:
861 : // insert your test code here.
862 2 : void testTrapezoidHelper()
863 : {
864 2 : B2DPolygon aPolygon;
865 : // provoke the PointBlockAllocator to exercise the freeIfLast path
866 322 : for(int i = 0; i < 16 * 10; i++)
867 : {
868 320 : B2DPoint aPoint(getRandomOrdinal(1000), getRandomOrdinal(1000));
869 320 : aPolygon.append(aPoint);
870 320 : }
871 : // scatter some duplicate points in to stress things more.
872 322 : for(int i = 0; i < 16 * 10; i++)
873 : {
874 320 : aPolygon.insert(getRandomOrdinal(aPolygon.count() - 1),
875 640 : aPolygon.getB2DPoint(getRandomOrdinal(aPolygon.count() - 1)));
876 : }
877 4 : B2DPolygon aPolygonOffset;
878 : // duplicate the polygon and offset it slightly.
879 642 : for(size_t i = 0; i < aPolygon.count(); i++)
880 : {
881 640 : B2DPoint aPoint(aPolygon.getB2DPoint(i));
882 640 : aPoint += B2DPoint(0.5-getRandomOrdinal(1),0.5-getRandomOrdinal(1));
883 640 : }
884 4 : B2DPolyPolygon aPolyPolygon;
885 2 : aPolyPolygon.append(aPolygon);
886 2 : aPolyPolygon.append(aPolygonOffset);
887 4 : B2DTrapezoidVector aVector;
888 2 : basegfx::tools::trapezoidSubdivide(aVector, aPolyPolygon);
889 4 : CPPUNIT_ASSERT_MESSAGE("more than zero sub-divided trapezoids",
890 4 : aVector.size() > 0);
891 2 : }
892 :
893 : // Change the following lines only, if you add, remove or rename
894 : // member functions of the current class,
895 : // because these macros are need by auto register mechanism.
896 :
897 4 : CPPUNIT_TEST_SUITE(b2dpolypolygon);
898 2 : CPPUNIT_TEST(testTrapezoidHelper);
899 4 : CPPUNIT_TEST_SUITE_END();
900 : }; // class b2dpolypolygon
901 :
902 6 : class b1Xrange : public CppUnit::TestFixture
903 : {
904 : public:
905 4 : template<class Type> void implCheck()
906 : {
907 : // test interval axioms
908 : // (http://en.wikipedia.org/wiki/Interval_%28mathematics%29)
909 4 : Type aRange;
910 4 : CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aRange.isEmpty());
911 4 : CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since range is empty", aRange.getCenter()==0);
912 :
913 : // degenerate interval
914 4 : aRange.expand(1);
915 4 : CPPUNIT_ASSERT_MESSAGE("degenerate range - still, not empty!", !aRange.isEmpty());
916 4 : CPPUNIT_ASSERT_MESSAGE("degenerate range - size of 0", aRange.getRange() == 0);
917 4 : CPPUNIT_ASSERT_MESSAGE("same value as degenerate range - is inside range", aRange.isInside(1));
918 4 : CPPUNIT_ASSERT_MESSAGE("center - must be the single range value", aRange.getCenter()==1);
919 :
920 : // proper interval
921 4 : aRange.expand(2);
922 4 : CPPUNIT_ASSERT_MESSAGE("proper range - size of 1", aRange.getRange() == 1);
923 4 : CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range", aRange.isInside(1));
924 4 : CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range", aRange.isInside(2));
925 :
926 : // center for proper interval that works for ints, too
927 4 : aRange.expand(3);
928 4 : CPPUNIT_ASSERT_MESSAGE("center - must be half of the range", aRange.getCenter()==2);
929 :
930 : // check overlap
931 4 : Type aRange2(0,1);
932 4 : CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound", aRange.overlaps(aRange2));
933 4 : CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely", !aRange.overlapsMore(aRange2));
934 :
935 4 : Type aRange3(0,2);
936 4 : CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now", aRange.overlapsMore(aRange3));
937 :
938 : // check intersect
939 4 : Type aRange4(3,4);
940 4 : aRange.intersect(aRange4);
941 4 : CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange.isEmpty());
942 :
943 4 : Type aRange5(5,6);
944 4 : aRange.intersect(aRange5);
945 4 : CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange.isEmpty());
946 :
947 : // just so that this compiles -
948 4 : Type aRange6( aRange );
949 : (void)aRange6;
950 4 : }
951 :
952 2 : void check()
953 : {
954 2 : implCheck<B1DRange>();
955 2 : implCheck<B1IRange>();
956 2 : }
957 :
958 : // Change the following lines only, if you add, remove or rename
959 : // member functions of the current class,
960 : // because these macros are need by auto register mechanism.
961 :
962 4 : CPPUNIT_TEST_SUITE(b1Xrange);
963 2 : CPPUNIT_TEST(check);
964 4 : CPPUNIT_TEST_SUITE_END();
965 : }; // class b1Xrange
966 :
967 6 : class b1ibox : public CppUnit::TestFixture
968 : {
969 : public:
970 2 : void TestBox()
971 : {
972 : // test axioms - markedly different from proper mathematical
973 : // intervals (behaviour modelled after how polygon fill
974 : // algorithms fill pixels)
975 2 : B1IBox aBox;
976 2 : CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aBox.isEmpty());
977 :
978 : // degenerate box
979 2 : aBox.expand(1);
980 2 : CPPUNIT_ASSERT_MESSAGE("degenerate box - still empty!", aBox.isEmpty());
981 2 : CPPUNIT_ASSERT_MESSAGE("degenerate box - size of 0", aBox.getRange() == 0);
982 2 : CPPUNIT_ASSERT_MESSAGE("same value as degenerate box - is outside (since empty)", !aBox.isInside(1));
983 2 : CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since box is empty", aBox.getCenter()==0);
984 :
985 : // proper box
986 2 : aBox.expand(2);
987 2 : CPPUNIT_ASSERT_MESSAGE("proper box - size of 1", aBox.getRange() == 1);
988 2 : CPPUNIT_ASSERT_MESSAGE("smaller value of box", aBox.isInside(1));
989 2 : CPPUNIT_ASSERT_MESSAGE("larger value of box - must be outside", !aBox.isInside(2));
990 :
991 : // center for proper box that works for ints, too
992 2 : aBox.expand(4);
993 2 : CPPUNIT_ASSERT_MESSAGE("center - must be center pixel of the box", aBox.getCenter()==2);
994 :
995 : // check overlap, which is markedly different from Range
996 2 : B1IBox aBox2(0,1);
997 2 : CPPUNIT_ASSERT_MESSAGE("box overlapping *excludes* upper bound", !aBox.overlaps(aBox2));
998 :
999 2 : B1IBox aBox3(0,2);
1000 2 : CPPUNIT_ASSERT_MESSAGE("box overlapping then includes upper bound-1", aBox.overlaps(aBox3));
1001 :
1002 : // check intersect
1003 2 : B1IBox aBox4(4,5);
1004 2 : aBox.intersect(aBox4);
1005 2 : CPPUNIT_ASSERT_MESSAGE("box intersection is yielding nonempty box!", aBox.isEmpty());
1006 :
1007 2 : B1IBox aBox5(2,5);
1008 2 : aBox5.intersect(aBox4);
1009 2 : CPPUNIT_ASSERT_MESSAGE("box intersection is yielding empty box!", !aBox5.isEmpty());
1010 :
1011 : // just so that this compiles -
1012 2 : B1IBox aBox6( aBox );
1013 : (void)aBox6;
1014 2 : }
1015 :
1016 : // Change the following lines only, if you add, remove or rename
1017 : // member functions of the current class,
1018 : // because these macros are need by auto register mechanism.
1019 :
1020 4 : CPPUNIT_TEST_SUITE(b1ibox);
1021 2 : CPPUNIT_TEST(TestBox);
1022 4 : CPPUNIT_TEST_SUITE_END();
1023 : }; // class b1ibox
1024 :
1025 6 : class b2Xrange : public CppUnit::TestFixture
1026 : {
1027 : public:
1028 4 : template<class Type> void implCheck()
1029 : {
1030 : // cohen sutherland clipping
1031 4 : Type aRange(0,0,10,10);
1032 :
1033 4 : CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
1034 : tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aRange) == 0);
1035 4 : CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
1036 : tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aRange) ==
1037 : (tools::RectClipFlags::LEFT|tools::RectClipFlags::TOP));
1038 4 : CPPUNIT_ASSERT_MESSAGE("(10,10) is outside range!",
1039 : tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aRange) == 0);
1040 4 : CPPUNIT_ASSERT_MESSAGE("(11,11) is inside range!",
1041 : tools::getCohenSutherlandClipFlags(B2IPoint(11,11),aRange) ==
1042 : (tools::RectClipFlags::RIGHT|tools::RectClipFlags::BOTTOM));
1043 :
1044 : // just so that this compiles -
1045 4 : Type aRange1( aRange );
1046 : (void)aRange1;
1047 4 : }
1048 :
1049 2 : void check()
1050 : {
1051 2 : implCheck<B2DRange>();
1052 2 : implCheck<B2IRange>();
1053 2 : }
1054 :
1055 : // Change the following lines only, if you add, remove or rename
1056 : // member functions of the current class,
1057 : // because these macros are need by auto register mechanism.
1058 :
1059 4 : CPPUNIT_TEST_SUITE(b2Xrange);
1060 2 : CPPUNIT_TEST(check);
1061 4 : CPPUNIT_TEST_SUITE_END();
1062 : }; // class b2Xrange
1063 :
1064 6 : class b2ibox : public CppUnit::TestFixture
1065 : {
1066 : public:
1067 2 : void TestBox()
1068 : {
1069 : // cohen sutherland clipping
1070 2 : B2IBox aBox(0,0,10,10);
1071 :
1072 4 : CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
1073 2 : tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aBox) == 0);
1074 4 : CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
1075 : tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aBox) ==
1076 2 : (tools::RectClipFlags::LEFT|tools::RectClipFlags::TOP));
1077 4 : CPPUNIT_ASSERT_MESSAGE("(9,9) is outside range!",
1078 2 : tools::getCohenSutherlandClipFlags(B2IPoint(9,9),aBox) == 0);
1079 4 : CPPUNIT_ASSERT_MESSAGE("(10,10) is inside range!",
1080 : tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aBox) ==
1081 2 : (tools::RectClipFlags::RIGHT|tools::RectClipFlags::BOTTOM));
1082 :
1083 : // just so that this compiles -
1084 2 : B2IBox aBox1( aBox );
1085 : (void)aBox1;
1086 2 : }
1087 :
1088 : // Change the following lines only, if you add, remove or rename
1089 : // member functions of the current class,
1090 : // because these macros are need by auto register mechanism.
1091 4 : CPPUNIT_TEST_SUITE(b2ibox);
1092 2 : CPPUNIT_TEST(TestBox);
1093 4 : CPPUNIT_TEST_SUITE_END();
1094 : }; // class b2ibox
1095 :
1096 6 : class b2dtuple : public CppUnit::TestFixture
1097 : {
1098 : public:
1099 : // insert your test code here.
1100 : // this is only demonstration code
1101 2 : void EmptyMethod()
1102 : {
1103 : // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
1104 2 : }
1105 :
1106 : // Change the following lines only, if you add, remove or rename
1107 : // member functions of the current class,
1108 : // because these macros are need by auto register mechanism.
1109 :
1110 4 : CPPUNIT_TEST_SUITE(b2dtuple);
1111 2 : CPPUNIT_TEST(EmptyMethod);
1112 4 : CPPUNIT_TEST_SUITE_END();
1113 : }; // class b2dtuple
1114 :
1115 12 : class bcolor : public CppUnit::TestFixture
1116 : {
1117 : BColor maWhite;
1118 : BColor maBlack;
1119 : BColor maRed;
1120 : BColor maGreen;
1121 : BColor maBlue;
1122 : BColor maYellow;
1123 : BColor maMagenta;
1124 : BColor maCyan;
1125 :
1126 : public:
1127 6 : bcolor() :
1128 : maWhite(1,1,1),
1129 : maBlack(0,0,0),
1130 : maRed(1,0,0),
1131 : maGreen(0,1,0),
1132 : maBlue(0,0,1),
1133 : maYellow(1,1,0),
1134 : maMagenta(1,0,1),
1135 6 : maCyan(0,1,1)
1136 6 : {}
1137 :
1138 : // insert your test code here.
1139 2 : void hslTest()
1140 : {
1141 4 : CPPUNIT_ASSERT_MESSAGE("white",
1142 2 : tools::rgb2hsl(maWhite) == BColor(0,0,1));
1143 4 : CPPUNIT_ASSERT_MESSAGE("black",
1144 2 : tools::rgb2hsl(maBlack) == BColor(0,0,0));
1145 4 : CPPUNIT_ASSERT_MESSAGE("red",
1146 2 : tools::rgb2hsl(maRed) == BColor(0,1,0.5));
1147 4 : CPPUNIT_ASSERT_MESSAGE("green",
1148 2 : tools::rgb2hsl(maGreen) == BColor(120,1,0.5));
1149 4 : CPPUNIT_ASSERT_MESSAGE("blue",
1150 2 : tools::rgb2hsl(maBlue) == BColor(240,1,0.5));
1151 4 : CPPUNIT_ASSERT_MESSAGE("yellow",
1152 2 : tools::rgb2hsl(maYellow) == BColor(60,1,0.5));
1153 4 : CPPUNIT_ASSERT_MESSAGE("magenta",
1154 2 : tools::rgb2hsl(maMagenta) == BColor(300,1,0.5));
1155 4 : CPPUNIT_ASSERT_MESSAGE("cyan",
1156 2 : tools::rgb2hsl(maCyan) == BColor(180,1,0.5));
1157 4 : CPPUNIT_ASSERT_MESSAGE("third hue case",
1158 2 : tools::rgb2hsl(BColor(0,0.5,1)) == BColor(210,1,0.5));
1159 :
1160 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip white",
1161 2 : tools::hsl2rgb(tools::rgb2hsl(maWhite)) == maWhite);
1162 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip black",
1163 2 : tools::hsl2rgb(tools::rgb2hsl(maBlack)) == maBlack);
1164 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip red",
1165 2 : tools::hsl2rgb(tools::rgb2hsl(maRed)) == maRed);
1166 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip green",
1167 2 : tools::hsl2rgb(tools::rgb2hsl(maGreen)) == maGreen);
1168 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip blue",
1169 2 : tools::hsl2rgb(tools::rgb2hsl(maBlue)) == maBlue);
1170 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip yellow",
1171 2 : tools::hsl2rgb(tools::rgb2hsl(maYellow)) == maYellow);
1172 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip magenta",
1173 2 : tools::hsl2rgb(tools::rgb2hsl(maMagenta)) == maMagenta);
1174 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip cyan",
1175 2 : tools::hsl2rgb(tools::rgb2hsl(maCyan)) == maCyan);
1176 :
1177 4 : CPPUNIT_ASSERT_MESSAGE("grey10",
1178 2 : tools::rgb2hsl(maWhite*.1) == BColor(0,0,.1));
1179 4 : CPPUNIT_ASSERT_MESSAGE("grey90",
1180 2 : tools::rgb2hsl(maWhite*.9) == BColor(0,0,.9));
1181 4 : CPPUNIT_ASSERT_MESSAGE("red/2",
1182 2 : tools::rgb2hsl(maRed*.5) == BColor(0,1,0.25));
1183 4 : CPPUNIT_ASSERT_MESSAGE("green/2",
1184 2 : tools::rgb2hsl(maGreen*.5) == BColor(120,1,0.25));
1185 4 : CPPUNIT_ASSERT_MESSAGE("blue/2",
1186 2 : tools::rgb2hsl(maBlue*.5) == BColor(240,1,0.25));
1187 4 : CPPUNIT_ASSERT_MESSAGE("yellow/2",
1188 2 : tools::rgb2hsl(maYellow*.5) == BColor(60,1,0.25));
1189 4 : CPPUNIT_ASSERT_MESSAGE("magenta/2",
1190 2 : tools::rgb2hsl(maMagenta*.5) == BColor(300,1,0.25));
1191 4 : CPPUNIT_ASSERT_MESSAGE("cyan/2",
1192 2 : tools::rgb2hsl(maCyan*.5) == BColor(180,1,0.25));
1193 :
1194 4 : CPPUNIT_ASSERT_MESSAGE("pastel",
1195 2 : tools::rgb2hsl(BColor(.75,.25,.25)) == BColor(0,.5,.5));
1196 2 : }
1197 :
1198 : // insert your test code here.
1199 2 : void hsvTest()
1200 : {
1201 4 : CPPUNIT_ASSERT_MESSAGE("white",
1202 2 : tools::rgb2hsv(maWhite) == BColor(0,0,1));
1203 4 : CPPUNIT_ASSERT_MESSAGE("black",
1204 2 : tools::rgb2hsv(maBlack) == BColor(0,0,0));
1205 4 : CPPUNIT_ASSERT_MESSAGE("red",
1206 2 : tools::rgb2hsv(maRed) == BColor(0,1,1));
1207 4 : CPPUNIT_ASSERT_MESSAGE("green",
1208 2 : tools::rgb2hsv(maGreen) == BColor(120,1,1));
1209 4 : CPPUNIT_ASSERT_MESSAGE("blue",
1210 2 : tools::rgb2hsv(maBlue) == BColor(240,1,1));
1211 4 : CPPUNIT_ASSERT_MESSAGE("yellow",
1212 2 : tools::rgb2hsv(maYellow) == BColor(60,1,1));
1213 4 : CPPUNIT_ASSERT_MESSAGE("magenta",
1214 2 : tools::rgb2hsv(maMagenta) == BColor(300,1,1));
1215 4 : CPPUNIT_ASSERT_MESSAGE("cyan",
1216 2 : tools::rgb2hsv(maCyan) == BColor(180,1,1));
1217 :
1218 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip white",
1219 2 : tools::hsv2rgb(tools::rgb2hsv(maWhite)) == maWhite);
1220 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip black",
1221 2 : tools::hsv2rgb(tools::rgb2hsv(maBlack)) == maBlack);
1222 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip red",
1223 2 : tools::hsv2rgb(tools::rgb2hsv(maRed)) == maRed);
1224 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip green",
1225 2 : tools::hsv2rgb(tools::rgb2hsv(maGreen)) == maGreen);
1226 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip blue",
1227 2 : tools::hsv2rgb(tools::rgb2hsv(maBlue)) == maBlue);
1228 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip yellow",
1229 2 : tools::hsv2rgb(tools::rgb2hsv(maYellow)) == maYellow);
1230 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip magenta",
1231 2 : tools::hsv2rgb(tools::rgb2hsv(maMagenta)) == maMagenta);
1232 4 : CPPUNIT_ASSERT_MESSAGE("roundtrip cyan",
1233 2 : tools::hsv2rgb(tools::rgb2hsv(maCyan)) == maCyan);
1234 :
1235 4 : CPPUNIT_ASSERT_MESSAGE("grey10",
1236 2 : tools::rgb2hsv(maWhite*.1) == BColor(0,0,.1));
1237 4 : CPPUNIT_ASSERT_MESSAGE("grey90",
1238 2 : tools::rgb2hsv(maWhite*.9) == BColor(0,0,.9));
1239 4 : CPPUNIT_ASSERT_MESSAGE("red/2",
1240 2 : tools::rgb2hsv(maRed*.5) == BColor(0,1,0.5));
1241 4 : CPPUNIT_ASSERT_MESSAGE("green/2",
1242 2 : tools::rgb2hsv(maGreen*.5) == BColor(120,1,0.5));
1243 4 : CPPUNIT_ASSERT_MESSAGE("blue/2",
1244 2 : tools::rgb2hsv(maBlue*.5) == BColor(240,1,0.5));
1245 4 : CPPUNIT_ASSERT_MESSAGE("yellow/2",
1246 2 : tools::rgb2hsv(maYellow*.5) == BColor(60,1,0.5));
1247 4 : CPPUNIT_ASSERT_MESSAGE("magenta/2",
1248 2 : tools::rgb2hsv(maMagenta*.5) == BColor(300,1,0.5));
1249 4 : CPPUNIT_ASSERT_MESSAGE("cyan/2",
1250 2 : tools::rgb2hsv(maCyan*.5) == BColor(180,1,0.5));
1251 :
1252 4 : CPPUNIT_ASSERT_MESSAGE("pastel",
1253 2 : tools::rgb2hsv(BColor(.5,.25,.25)) == BColor(0,.5,.5));
1254 2 : }
1255 :
1256 2 : void ciexyzTest()
1257 : {
1258 2 : tools::rgb2ciexyz(maWhite);
1259 2 : tools::rgb2ciexyz(maBlack);
1260 2 : tools::rgb2ciexyz(maRed);
1261 2 : tools::rgb2ciexyz(maGreen);
1262 2 : tools::rgb2ciexyz(maBlue);
1263 2 : tools::rgb2ciexyz(maYellow);
1264 2 : tools::rgb2ciexyz(maMagenta);
1265 2 : tools::rgb2ciexyz(maCyan);
1266 2 : }
1267 :
1268 : // Change the following lines only, if you add, remove or rename
1269 : // member functions of the current class,
1270 : // because these macros are need by auto register mechanism.
1271 :
1272 4 : CPPUNIT_TEST_SUITE(bcolor);
1273 2 : CPPUNIT_TEST(hslTest);
1274 2 : CPPUNIT_TEST(hsvTest);
1275 2 : CPPUNIT_TEST(ciexyzTest);
1276 4 : CPPUNIT_TEST_SUITE_END();
1277 : }; // class b2dvector
1278 :
1279 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dsvgdimpex);
1280 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2drange);
1281 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolyrange);
1282 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dhommatrix);
1283 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpoint);
1284 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygon);
1285 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygontools);
1286 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolypolygon);
1287 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1Xrange);
1288 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1ibox);
1289 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2Xrange);
1290 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2ibox);
1291 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dtuple);
1292 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::bcolor);
1293 6 : } // namespace basegfx2d
1294 :
1295 : // this macro creates an empty function, which will called by the RegisterAllFunctions()
1296 : // to let the user the possibility to also register some functions by hand.
1297 : // NOADDITIONAL;
1298 :
1299 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|