1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "cppunit/TestAssert.h"
21 #include "cppunit/TestFixture.h"
22 #include "cppunit/extensions/HelperMacros.h"
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/range/b2irange.hxx>
34 #include <basegfx/range/b2ibox.hxx>
35 #include <basegfx/range/b1drange.hxx>
36 #include <basegfx/range/b1irange.hxx>
37 #include <basegfx/range/b1ibox.hxx>
38 #include <basegfx/range/b2drange.hxx>
39 #include <basegfx/range/b2dpolyrange.hxx>
40 #include <basegfx/numeric/ftools.hxx>
41 #include <basegfx/color/bcolor.hxx>
42 #include <basegfx/color/bcolortools.hxx>
44 #include <basegfx/tools/rectcliptools.hxx>
49 using namespace ::basegfx
;
55 class b2dsvgdimpex
: public CppUnit::TestFixture
64 // initialise your test code values here.
68 aPath0
= "M 10 10-10 10-10-10 10-10Z";
70 // simple bezier polygon
71 aPath1
= "m11430 0c-8890 3810 5715 6985 5715 6985 "
72 "0 0-17145-1905-17145-1905 0 0 22860-10160 "
73 "16510 6350-6350 16510-3810-11430-3810-11430z";
75 // '@' as a bezier polygon
76 aPath2
= "m1917 1114c-89-189-233-284-430-284-167 "
77 "0-306 91-419 273-113 182-170 370-170 564 "
78 "0 145 33 259 98 342 65 84 150 126 257 126 "
79 "77 0 154-19 231-57 77-38 147-97 210-176 63"
80 "-79 99-143 109-190 38-199 76-398 114-598z"
81 "m840 1646c-133 73-312 139-537 197-225 57"
82 "-440 86-644 87-483-1-866-132-1150-392-284"
83 "-261-426-619-426-1076 0-292 67-560 200-803 "
84 "133-243 321-433 562-569 241-136 514-204 821"
85 "-204 405 0 739 125 1003 374 264 250 396 550 "
86 "396 899 0 313-88 576-265 787-177 212-386 318"
87 "-627 318-191 0-308-94-352-281-133 187-315 281"
88 "-546 281-172 0-315-67-428-200-113-133-170-301"
89 "-170-505 0-277 90-527 271-751 181-223 394"
90 "-335 640-335 196 0 353 83 470 250 13-68 26"
91 "-136 41-204 96 0 192 0 288 0-74 376-148 752"
92 "-224 1128-21 101-31 183-31 245 0 39 9 70 26 "
93 "93 17 24 39 36 67 36 145 0 279-80 400-240 121"
94 "-160 182-365 182-615 0-288-107-533-322-734"
95 "-215-201-487-301-816-301-395 0-715 124-960 "
96 "373-245 249-368 569-368 958 0 385 119 685 "
97 "357 900 237 216 557 324 958 325 189-1 389-27 "
98 "600-77 211-52 378-110 503-174 27 70 54 140 81 210z";
100 // first part of 'Hello World' as a line polygon
101 aPath3
= "m1598 125h306v2334h-306v-1105h-1293v1105h-305v"
102 "-2334h305v973h1293zm2159 1015 78-44 85 235-91 "
103 "47-91 40-90 34-90 29-89 21-88 16-88 10-88 3-102"
104 "-4-97-12-91-19-85-26-40-16-39-18-38-20-36-22-34"
105 "-24-33-26-32-27-30-30-29-31-27-33-25-33-23-36-21"
106 "-36-19-38-18-40-16-40-26-86-18-91-11-97-4-103 3"
107 "-98 11-94 17-89 24-84 31-79 37-75 22-35 23-34 24"
108 "-33 27-32 28-30 29-28 31-27 31-24 33-22 34-21 35"
109 "-18 37-17 38-14 38-13 41-11 41-8 86-12 91-4 82 4 "
110 "78 10 37 9 37 9 36 12 35 14 33 15 33 17 32 19 31 "
111 "21 30 22 30 25 55 54 26 29 24 31 22 32 21 33 19 "
112 "34 18 36 30 74 23 80 17 84 10 89 3 94v78h-1277l6 "
113 "75 10 70 14 66 19 62 23 57 13 26 14 26 15 25 17 "
114 "23 17 22 19 21 19 20 21 18 21 18 23 16 23 14 24 "
115 "14 26 12 26 11 27 10 28 8 59 13 63 7 67 3 80-3 81"
116 "-9 79-14 80-21 78-26 79-32zm-1049-808-12 53h963l"
117 "-7-51-11-49-14-46-17-43-21-40-24-38-27-36-31-32"
118 "-33-29-35-25-37-22-38-17-40-14-41-9-42-6-44-2-48 "
119 "2-46 6-44 9-42 13-40 17-38 21-36 24-34 28-32 32"
120 "-29 34-26 38-23 41-20 44-17 47zm1648-1293h288v"
121 "2459h-288zm752-2459h288v2459h-288zm1286-1750 86-11 "
122 "91-4 91 4 85 12 42 8 39 11 39 13 38 14 36 17 35 18 "
123 "34 20 33 23 31 24 30 26 29 28 28 30 26 32 25 33 23 "
124 "34 21 35 37 75 31 80 24 84 16 90 11 94 3 100-3 100"
125 "-11 95-16 89-24 85-31 80-37 74-21 35-23 35-25 32-26 "
126 "32-28 30-29 28-30 26-31 24-33 22-34 21-35 18-36 17"
127 "-38 14-39 13-39 10-42 9-85 12-91 4-91-4-86-12-41-9"
128 "-40-10-39-13-37-14-36-17-35-18-34-21-33-22-31-24-30"
129 "-26-29-28-28-30-26-32-25-32-23-35-21-35-38-74-30-80"
130 "-24-85-17-89-11-95-3-100 3-101 11-95 17-90 24-85 30"
131 "-79 38-75 21-35 23-35 25-32 26-32 28-30 29-28 30-26 "
132 "31-24 33-22 34-20 35-18 36-16 37-15 39-12 40-11z";
141 B2DPolyPolygon aPoly
;
144 CPPUNIT_ASSERT_MESSAGE("importing simple rectangle from SVG-D",
145 tools::importFromSvgD( aPoly
,
147 aExport
= tools::exportToSvgD( aPoly
);
148 const char* sExportString
= "m10 10h-20v-20h20z";
149 CPPUNIT_ASSERT_MESSAGE("exporting rectangle to SVG-D",
150 !aExport
.compareToAscii(sExportString
) );
151 CPPUNIT_ASSERT_MESSAGE("importing simple rectangle from SVG-D (round-trip",
152 tools::importFromSvgD( aPoly
,
154 aExport
= tools::exportToSvgD( aPoly
);
155 CPPUNIT_ASSERT_MESSAGE("exporting rectangle to SVG-D (round-trip)",
156 !aExport
.compareToAscii(sExportString
));
158 CPPUNIT_ASSERT_MESSAGE("importing simple bezier polygon from SVG-D",
159 tools::importFromSvgD( aPoly
,
161 aExport
= tools::exportToSvgD( aPoly
);
163 // Adaptions for B2DPolygon bezier change (see #i77162#):
165 // The import/export of aPath1 does not reproduce aExport again. This is
166 // correct since aPath1 contains a segment with non-used control points
167 // which gets exported now correctly as 'l' and also a point (#4, index 3)
168 // with C2 continuity which produces a 's' staement now.
170 // The old SVGexport identified nun-used ControlVectors erraneously as bezier segments
171 // because the 2nd vector at the start point was used, even when added
172 // with start point was identical to end point. Exactly for that reason
173 // i reworked the B2DPolygon to use prev, next control points.
175 // so for correct unit test i add the new exported string here as sExportStringSimpleBezier
176 // and compare to it.
177 const char* sExportStringSimpleBezier
=
178 "m11430 0c-8890 3810 5715 6985 5715 6985"
179 "l-17145-1905c0 0 22860-10160 16510 6350"
180 "s-3810-11430-3810-11430z";
181 CPPUNIT_ASSERT_MESSAGE("exporting bezier polygon to SVG-D", !aExport
.compareToAscii(sExportStringSimpleBezier
));
183 // Adaptions for B2DPolygon bezier change (see #i77162#):
185 // a 2nd good test is that re-importing of aExport has to create the same
186 // B2DPolPolygon again:
187 B2DPolyPolygon aReImport
;
188 CPPUNIT_ASSERT_MESSAGE("importing simple bezier polygon from SVG-D", tools::importFromSvgD( aReImport
, aExport
));
189 CPPUNIT_ASSERT_MESSAGE("re-imported polygon needs to be identical", aReImport
== aPoly
);
191 CPPUNIT_ASSERT_MESSAGE("importing '@' from SVG-D", tools::importFromSvgD( aPoly
, aPath2
));
192 aExport
= tools::exportToSvgD( aPoly
);
194 // Adaptions for B2DPolygon bezier change (see #i77162#):
196 // same here, the corrected export with the corrected B2DPolygon is simply more efficient,
197 // so i needed to change the compare string. Also adding the re-import comparison below.
198 const char* sExportString1
=
199 "m1917 1114c-89-189-233-284-430-284-167 0-306 91-419 273s-170 370-17"
200 "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"
201 "-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-"
202 "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"
203 "-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"
204 "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"
205 "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"
206 "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"
207 "8 325 189-1 389-27 600-77 211-52 378-110 503-174q40.5 105 81 210z";
208 CPPUNIT_ASSERT_MESSAGE("re-importing '@' from SVG-D", tools::importFromSvgD( aReImport
, aExport
));
209 CPPUNIT_ASSERT_MESSAGE("re-imported '@' needs to be identical", aReImport
== aPoly
);
211 CPPUNIT_ASSERT_MESSAGE("exporting '@' to SVG-D", !aExport
.compareToAscii(sExportString1
));
212 CPPUNIT_ASSERT_MESSAGE("importing '@' from SVG-D (round-trip",
213 tools::importFromSvgD( aPoly
,
215 aExport
= tools::exportToSvgD( aPoly
);
216 CPPUNIT_ASSERT_MESSAGE("exporting '@' to SVG-D (round-trip)",
217 !aExport
.compareToAscii(sExportString1
));
220 CPPUNIT_ASSERT_MESSAGE("importing complex polygon from SVG-D",
221 tools::importFromSvgD( aPoly
,
223 aExport
= tools::exportToSvgD( aPoly
);
224 const char* sExportString2
=
225 "m1598 125h306v2334h-306v-1105h-1293v1105h-305v-2334h305v973h1293"
226 "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"
227 "-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"
228 "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"
229 "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-"
230 "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"
231 "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 "
232 "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"
233 "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"
234 " 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"
235 "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"
236 "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"
237 "-1293h288v2459h-288zm752-2459h288v2459h-288zm1286-1750 86-11 91-4 91 4 85 12 42 "
238 "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 "
239 "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"
240 " 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"
241 "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"
242 "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-"
243 "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"
244 "-28 30-26 31-24 33-22 34-20 35-18 36-16 37-15 39-12 40-11z";
245 CPPUNIT_ASSERT_MESSAGE("exporting complex polygon to SVG-D",
246 !aExport
.compareToAscii(sExportString2
));
247 CPPUNIT_ASSERT_MESSAGE("importing complex polygon from SVG-D (round-trip",
248 tools::importFromSvgD( aPoly
,
250 aExport
= tools::exportToSvgD( aPoly
);
251 CPPUNIT_ASSERT_MESSAGE("exporting complex polygon to SVG-D (round-trip)",
252 !aExport
.compareToAscii(sExportString2
));
254 const B2DPolygon
aRect(
255 tools::createPolygonFromRect( B2DRange(0.0,0.0,4000.0,4000.0) ));
256 aExport
= tools::exportToSvgD( B2DPolyPolygon(aRect
), false, false);
258 const char* sExportStringRect
= "M0 0H4000V4000H0Z";
259 CPPUNIT_ASSERT_MESSAGE("exporting to rectangle svg-d string",
260 !aExport
.compareToAscii(sExportStringRect
));
263 // Change the following lines only, if you add, remove or rename
264 // member functions of the current class,
265 // because these macros are need by auto register mechanism.
267 CPPUNIT_TEST_SUITE(b2dsvgdimpex
);
269 CPPUNIT_TEST_SUITE_END();
270 }; // class b2dsvgdimpex
272 class b2drange
: public CppUnit::TestFixture
278 CPPUNIT_ASSERT_MESSAGE("simple range rounding from double to integer",
279 fround(B2DRange(1.2, 2.3, 3.5, 4.8)) == B2IRange(1, 2, 4, 5));
282 // Change the following lines only, if you add, remove or rename
283 // member functions of the current class,
284 // because these macros are need by auto register mechanism.
286 CPPUNIT_TEST_SUITE(b2drange
);
288 CPPUNIT_TEST_SUITE_END();
291 class b2dpolyrange
: public CppUnit::TestFixture
298 aRange
.appendElement(B2DRange(0,0,1,1),ORIENTATION_POSITIVE
);
299 aRange
.appendElement(B2DRange(2,2,3,3),ORIENTATION_POSITIVE
);
301 CPPUNIT_ASSERT_MESSAGE("simple poly range - count",
302 aRange
.count() == 2);
303 CPPUNIT_ASSERT_MESSAGE("simple poly range - first element",
304 aRange
.getElement(0).head
== B2DRange(0,0,1,1));
305 CPPUNIT_ASSERT_MESSAGE("simple poly range - second element",
306 aRange
.getElement(1).head
== B2DRange(2,2,3,3));
308 // B2DPolyRange relies on correctly orientated rects
309 const B2DRange
aRect(0,0,1,1);
310 CPPUNIT_ASSERT_MESSAGE("createPolygonFromRect - correct orientation",
311 tools::getOrientation(
312 tools::createPolygonFromRect(aRect
)) == ORIENTATION_POSITIVE
);
315 // Change the following lines only, if you add, remove or rename
316 // member functions of the current class,
317 // because these macros are need by auto register mechanism.
319 CPPUNIT_TEST_SUITE(b2dpolyrange
);
321 CPPUNIT_TEST_SUITE_END();
324 class b2dhommatrix
: public CppUnit::TestFixture
327 B2DHomMatrix maIdentity
;
328 B2DHomMatrix maScale
;
329 B2DHomMatrix maTranslate
;
330 B2DHomMatrix maShear
;
331 B2DHomMatrix maAffine
;
332 B2DHomMatrix maPerspective
;
335 // initialise your test code values here.
338 // setup some test matrices
339 maIdentity
.identity(); // force compact layout
340 maIdentity
.set(0,0, 1.0);
341 maIdentity
.set(0,1, 0.0);
342 maIdentity
.set(0,2, 0.0);
343 maIdentity
.set(1,0, 0.0);
344 maIdentity
.set(1,1, 1.0);
345 maIdentity
.set(1,2, 0.0);
347 maScale
.identity(); // force compact layout
348 maScale
.set(0,0, 2.0);
349 maScale
.set(1,1, 20.0);
351 maTranslate
.identity(); // force compact layout
352 maTranslate
.set(0,2, 20.0);
353 maTranslate
.set(1,2, 2.0);
355 maShear
.identity(); // force compact layout
356 maShear
.set(0,1, 3.0);
357 maShear
.set(1,0, 7.0);
358 maShear
.set(1,1, 22.0);
360 maAffine
.identity(); // force compact layout
361 maAffine
.set(0,0, 1.0);
362 maAffine
.set(0,1, 2.0);
363 maAffine
.set(0,2, 3.0);
364 maAffine
.set(1,0, 4.0);
365 maAffine
.set(1,1, 5.0);
366 maAffine
.set(1,2, 6.0);
368 maPerspective
.set(0,0, 1.0);
369 maPerspective
.set(0,1, 2.0);
370 maPerspective
.set(0,2, 3.0);
371 maPerspective
.set(1,0, 4.0);
372 maPerspective
.set(1,1, 5.0);
373 maPerspective
.set(1,2, 6.0);
374 maPerspective
.set(2,0, 7.0);
375 maPerspective
.set(2,1, 8.0);
376 maPerspective
.set(2,2, 9.0);
385 B2DHomMatrix aIdentity
;
387 B2DHomMatrix aTranslate
;
389 B2DHomMatrix aAffine
;
390 B2DHomMatrix aPerspective
;
392 // setup some test matrices
393 aIdentity
.identity(); // force compact layout
394 aIdentity
.set(0,0, 1.0);
395 aIdentity
.set(0,1, 0.0);
396 aIdentity
.set(0,2, 0.0);
397 aIdentity
.set(1,0, 0.0);
398 aIdentity
.set(1,1, 1.0);
399 aIdentity
.set(1,2, 0.0);
401 aScale
.identity(); // force compact layout
402 aScale
.set(0,0, 2.0);
403 aScale
.set(1,1, 20.0);
405 aTranslate
.identity(); // force compact layout
406 aTranslate
.set(0,2, 20.0);
407 aTranslate
.set(1,2, 2.0);
409 aShear
.identity(); // force compact layout
410 aShear
.set(0,1, 3.0);
411 aShear
.set(1,0, 7.0);
412 aShear
.set(1,1, 22.0);
414 aAffine
.identity(); // force compact layout
415 aAffine
.set(0,0, 1.0);
416 aAffine
.set(0,1, 2.0);
417 aAffine
.set(0,2, 3.0);
418 aAffine
.set(1,0, 4.0);
419 aAffine
.set(1,1, 5.0);
420 aAffine
.set(1,2, 6.0);
422 aPerspective
.set(0,0, 1.0);
423 aPerspective
.set(0,1, 2.0);
424 aPerspective
.set(0,2, 3.0);
425 aPerspective
.set(1,0, 4.0);
426 aPerspective
.set(1,1, 5.0);
427 aPerspective
.set(1,2, 6.0);
428 aPerspective
.set(2,0, 7.0);
429 aPerspective
.set(2,1, 8.0);
430 aPerspective
.set(2,2, 9.0);
432 CPPUNIT_ASSERT_MESSAGE("operator==: identity matrix", aIdentity
== maIdentity
);
433 CPPUNIT_ASSERT_MESSAGE("operator==: scale matrix", aScale
== maScale
);
434 CPPUNIT_ASSERT_MESSAGE("operator==: translate matrix", aTranslate
== maTranslate
);
435 CPPUNIT_ASSERT_MESSAGE("operator==: shear matrix", aShear
== maShear
);
436 CPPUNIT_ASSERT_MESSAGE("operator==: affine matrix", aAffine
== maAffine
);
437 CPPUNIT_ASSERT_MESSAGE("operator==: perspective matrix", aPerspective
== maPerspective
);
444 CPPUNIT_ASSERT_MESSAGE("identity", maIdentity
== ident
);
451 CPPUNIT_ASSERT_MESSAGE("scale", maScale
== mat
);
457 mat
.rotate(90*F_PI180
);
458 CPPUNIT_ASSERT_MESSAGE("rotate pi/2 yields exact matrix",
459 mat
.get(0,0) == 0.0 &&
460 mat
.get(0,1) == -1.0 &&
461 mat
.get(0,2) == 0.0 &&
462 mat
.get(1,0) == 1.0 &&
463 mat
.get(1,1) == 0.0 &&
464 mat
.get(1,2) == 0.0);
465 mat
.rotate(90*F_PI180
);
466 CPPUNIT_ASSERT_MESSAGE("rotate pi yields exact matrix",
467 mat
.get(0,0) == -1.0 &&
468 mat
.get(0,1) == 0.0 &&
469 mat
.get(0,2) == 0.0 &&
470 mat
.get(1,0) == 0.0 &&
471 mat
.get(1,1) == -1.0 &&
472 mat
.get(1,2) == 0.0);
473 mat
.rotate(90*F_PI180
);
474 CPPUNIT_ASSERT_MESSAGE("rotate 3/2 pi yields exact matrix",
475 mat
.get(0,0) == 0.0 &&
476 mat
.get(0,1) == 1.0 &&
477 mat
.get(0,2) == 0.0 &&
478 mat
.get(1,0) == -1.0 &&
479 mat
.get(1,1) == 0.0 &&
480 mat
.get(1,2) == 0.0);
481 mat
.rotate(90*F_PI180
);
482 CPPUNIT_ASSERT_MESSAGE("rotate 2 pi yields exact matrix",
483 mat
.get(0,0) == 1.0 &&
484 mat
.get(0,1) == 0.0 &&
485 mat
.get(0,2) == 0.0 &&
486 mat
.get(1,0) == 0.0 &&
487 mat
.get(1,1) == 1.0 &&
488 mat
.get(1,2) == 0.0);
494 mat
.translate(20.0,2.0);
495 CPPUNIT_ASSERT_MESSAGE("translate", maTranslate
== mat
);
503 CPPUNIT_ASSERT_MESSAGE("translate", maShear
== mat
);
508 B2DHomMatrix affineAffineProd
;
510 affineAffineProd
.set(0,0, 9);
511 affineAffineProd
.set(0,1, 12);
512 affineAffineProd
.set(0,2, 18);
513 affineAffineProd
.set(1,0, 24);
514 affineAffineProd
.set(1,1, 33);
515 affineAffineProd
.set(1,2, 48);
517 B2DHomMatrix affinePerspectiveProd
;
519 affinePerspectiveProd
.set(0,0, 30);
520 affinePerspectiveProd
.set(0,1, 36);
521 affinePerspectiveProd
.set(0,2, 42);
522 affinePerspectiveProd
.set(1,0, 66);
523 affinePerspectiveProd
.set(1,1, 81);
524 affinePerspectiveProd
.set(1,2, 96);
525 affinePerspectiveProd
.set(2,0, 7);
526 affinePerspectiveProd
.set(2,1, 8);
527 affinePerspectiveProd
.set(2,2, 9);
529 B2DHomMatrix perspectiveAffineProd
;
531 perspectiveAffineProd
.set(0,0, 9);
532 perspectiveAffineProd
.set(0,1, 12);
533 perspectiveAffineProd
.set(0,2, 18);
534 perspectiveAffineProd
.set(1,0, 24);
535 perspectiveAffineProd
.set(1,1, 33);
536 perspectiveAffineProd
.set(1,2, 48);
537 perspectiveAffineProd
.set(2,0, 39);
538 perspectiveAffineProd
.set(2,1, 54);
539 perspectiveAffineProd
.set(2,2, 78);
541 B2DHomMatrix perspectivePerspectiveProd
;
543 perspectivePerspectiveProd
.set(0,0, 30);
544 perspectivePerspectiveProd
.set(0,1, 36);
545 perspectivePerspectiveProd
.set(0,2, 42);
546 perspectivePerspectiveProd
.set(1,0, 66);
547 perspectivePerspectiveProd
.set(1,1, 81);
548 perspectivePerspectiveProd
.set(1,2, 96);
549 perspectivePerspectiveProd
.set(2,0, 102);
550 perspectivePerspectiveProd
.set(2,1, 126);
551 perspectivePerspectiveProd
.set(2,2, 150);
557 CPPUNIT_ASSERT_MESSAGE("multiply: both compact", temp
== affineAffineProd
);
559 temp
= maPerspective
;
561 CPPUNIT_ASSERT_MESSAGE("multiply: first compact", temp
== affinePerspectiveProd
);
565 CPPUNIT_ASSERT_MESSAGE("multiply: second compact", temp
== perspectiveAffineProd
);
567 temp
= maPerspective
;
569 CPPUNIT_ASSERT_MESSAGE("multiply: none compact", temp
== perspectivePerspectiveProd
);
572 void impFillMatrix(B2DHomMatrix
& rSource
, double fScaleX
, double fScaleY
, double fShearX
, double fRotate
)
574 // fill rSource with a linear combination of scale, shear and rotate
576 rSource
.scale(fScaleX
, fScaleY
);
577 rSource
.shearX(fShearX
);
578 rSource
.rotate(fRotate
);
581 bool impDecomposeComposeTest(double fScaleX
, double fScaleY
, double fShearX
, double fRotate
)
583 // linear combine matrix with given values
584 B2DHomMatrix aSource
;
585 impFillMatrix(aSource
, fScaleX
, fScaleY
, fShearX
, fRotate
);
587 // decompose that matrix
592 bool bWorked
= aSource
.decompose(aDScale
, aDTrans
, fDRot
, fDShX
);
594 // linear combine another matrix with decomposition results
595 B2DHomMatrix aRecombined
;
596 impFillMatrix(aRecombined
, aDScale
.getX(), aDScale
.getY(), fDShX
, fDRot
);
598 // if decomposition worked, matrices need to be the same
599 return bWorked
&& aSource
== aRecombined
;
604 // test matrix decompositions. Each matrix decomposed and rebuilt
605 // using the decompose result should be the same as before. Test
606 // with all ranges of values. Translations are not tested since these
607 // are just the two rightmost values and uncritical
608 static double fSX(10.0);
609 static double fSY(12.0);
610 static double fR(45.0 * F_PI180
);
611 static double fS(15.0 * F_PI180
);
613 // check all possible scaling combinations
614 CPPUNIT_ASSERT_MESSAGE("decompose: error test A1", impDecomposeComposeTest(fSX
, fSY
, 0.0, 0.0));
615 CPPUNIT_ASSERT_MESSAGE("decompose: error test A2", impDecomposeComposeTest(-fSX
, fSY
, 0.0, 0.0));
616 CPPUNIT_ASSERT_MESSAGE("decompose: error test A3", impDecomposeComposeTest(fSX
, -fSY
, 0.0, 0.0));
617 CPPUNIT_ASSERT_MESSAGE("decompose: error test A4", impDecomposeComposeTest(-fSX
, -fSY
, 0.0, 0.0));
619 // check all possible scaling combinations with positive rotation
620 CPPUNIT_ASSERT_MESSAGE("decompose: error test B1", impDecomposeComposeTest(fSX
, fSY
, 0.0, fR
));
621 CPPUNIT_ASSERT_MESSAGE("decompose: error test B2", impDecomposeComposeTest(-fSX
, fSY
, 0.0, fR
));
622 CPPUNIT_ASSERT_MESSAGE("decompose: error test B3", impDecomposeComposeTest(fSX
, -fSY
, 0.0, fR
));
623 CPPUNIT_ASSERT_MESSAGE("decompose: error test B4", impDecomposeComposeTest(-fSX
, -fSY
, 0.0, fR
));
625 // check all possible scaling combinations with negative rotation
626 CPPUNIT_ASSERT_MESSAGE("decompose: error test C1", impDecomposeComposeTest(fSX
, fSY
, 0.0, -fR
));
627 CPPUNIT_ASSERT_MESSAGE("decompose: error test C2", impDecomposeComposeTest(-fSX
, fSY
, 0.0, -fR
));
628 CPPUNIT_ASSERT_MESSAGE("decompose: error test C3", impDecomposeComposeTest(fSX
, -fSY
, 0.0, -fR
));
629 CPPUNIT_ASSERT_MESSAGE("decompose: error test C4", impDecomposeComposeTest(-fSX
, -fSY
, 0.0, -fR
));
631 // check all possible scaling combinations with positive shear
632 CPPUNIT_ASSERT_MESSAGE("decompose: error test D1", impDecomposeComposeTest(fSX
, fSY
, tan(fS
), 0.0));
633 CPPUNIT_ASSERT_MESSAGE("decompose: error test D2", impDecomposeComposeTest(-fSX
, fSY
, tan(fS
), 0.0));
634 CPPUNIT_ASSERT_MESSAGE("decompose: error test D3", impDecomposeComposeTest(fSX
, -fSY
, tan(fS
), 0.0));
635 CPPUNIT_ASSERT_MESSAGE("decompose: error test D4", impDecomposeComposeTest(-fSX
, -fSY
, tan(fS
), 0.0));
637 // check all possible scaling combinations with negative shear
638 CPPUNIT_ASSERT_MESSAGE("decompose: error test E1", impDecomposeComposeTest(fSX
, fSY
, tan(-fS
), 0.0));
639 CPPUNIT_ASSERT_MESSAGE("decompose: error test E2", impDecomposeComposeTest(-fSX
, fSY
, tan(-fS
), 0.0));
640 CPPUNIT_ASSERT_MESSAGE("decompose: error test E3", impDecomposeComposeTest(fSX
, -fSY
, tan(-fS
), 0.0));
641 CPPUNIT_ASSERT_MESSAGE("decompose: error test E4", impDecomposeComposeTest(-fSX
, -fSY
, tan(-fS
), 0.0));
643 // check all possible scaling combinations with positive rotate and positive shear
644 CPPUNIT_ASSERT_MESSAGE("decompose: error test F1", impDecomposeComposeTest(fSX
, fSY
, tan(fS
), fR
));
645 CPPUNIT_ASSERT_MESSAGE("decompose: error test F2", impDecomposeComposeTest(-fSX
, fSY
, tan(fS
), fR
));
646 CPPUNIT_ASSERT_MESSAGE("decompose: error test F3", impDecomposeComposeTest(fSX
, -fSY
, tan(fS
), fR
));
647 CPPUNIT_ASSERT_MESSAGE("decompose: error test F4", impDecomposeComposeTest(-fSX
, -fSY
, tan(fS
), fR
));
649 // check all possible scaling combinations with negative rotate and positive shear
650 CPPUNIT_ASSERT_MESSAGE("decompose: error test G1", impDecomposeComposeTest(fSX
, fSY
, tan(fS
), -fR
));
651 CPPUNIT_ASSERT_MESSAGE("decompose: error test G2", impDecomposeComposeTest(-fSX
, fSY
, tan(fS
), -fR
));
652 CPPUNIT_ASSERT_MESSAGE("decompose: error test G3", impDecomposeComposeTest(fSX
, -fSY
, tan(fS
), -fR
));
653 CPPUNIT_ASSERT_MESSAGE("decompose: error test G4", impDecomposeComposeTest(-fSX
, -fSY
, tan(fS
), -fR
));
655 // check all possible scaling combinations with positive rotate and negative shear
656 CPPUNIT_ASSERT_MESSAGE("decompose: error test H1", impDecomposeComposeTest(fSX
, fSY
, tan(-fS
), fR
));
657 CPPUNIT_ASSERT_MESSAGE("decompose: error test H2", impDecomposeComposeTest(-fSX
, fSY
, tan(-fS
), fR
));
658 CPPUNIT_ASSERT_MESSAGE("decompose: error test H3", impDecomposeComposeTest(fSX
, -fSY
, tan(-fS
), fR
));
659 CPPUNIT_ASSERT_MESSAGE("decompose: error test H4", impDecomposeComposeTest(-fSX
, -fSY
, tan(-fS
), fR
));
661 // check all possible scaling combinations with negative rotate and negative shear
662 CPPUNIT_ASSERT_MESSAGE("decompose: error test I1", impDecomposeComposeTest(fSX
, fSY
, tan(-fS
), -fR
));
663 CPPUNIT_ASSERT_MESSAGE("decompose: error test I2", impDecomposeComposeTest(-fSX
, fSY
, tan(-fS
), -fR
));
664 CPPUNIT_ASSERT_MESSAGE("decompose: error test I3", impDecomposeComposeTest(fSX
, -fSY
, tan(-fS
), -fR
));
665 CPPUNIT_ASSERT_MESSAGE("decompose: error test I4", impDecomposeComposeTest(-fSX
, -fSY
, tan(-fS
), -fR
));
667 // cover special case of 180 degree rotation
668 B2DHomMatrix aTest
=tools::createScaleShearXRotateTranslateB2DHomMatrix(
673 // decompose that matrix
678 aTest
.decompose(aDScale
, aDTrans
, fDRot
, fDShX
);
679 CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDScale
.getX() == 6425 && aDScale
.getY() == 3938);
680 CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDTrans
.getX() == 10482 && aDTrans
.getY() == 4921);
681 CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", fDRot
== 180*F_PI180
);
684 // Change the following lines only, if you add, remove or rename
685 // member functions of the current class,
686 // because these macros are need by auto register mechanism.
688 CPPUNIT_TEST_SUITE(b2dhommatrix
);
690 CPPUNIT_TEST(identity
);
692 CPPUNIT_TEST(translate
);
693 CPPUNIT_TEST(rotate
);
695 CPPUNIT_TEST(multiply
);
696 CPPUNIT_TEST(decompose
);
697 CPPUNIT_TEST_SUITE_END();
699 }; // class b2dhommatrix
702 class b2dpoint
: public CppUnit::TestFixture
705 // insert your test code here.
706 // this is only demonstration code
709 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
712 // Change the following lines only, if you add, remove or rename
713 // member functions of the current class,
714 // because these macros are need by auto register mechanism.
716 CPPUNIT_TEST_SUITE(b2dpoint
);
717 CPPUNIT_TEST(EmptyMethod
);
718 CPPUNIT_TEST_SUITE_END();
722 class b2dpolygon
: public CppUnit::TestFixture
725 // insert your test code here.
730 aPoly
.appendBezierSegment(B2DPoint(1,1),B2DPoint(2,2),B2DPoint(3,3));
732 CPPUNIT_ASSERT_MESSAGE("#1 first polygon point wrong",
733 aPoly
.getB2DPoint(0) == B2DPoint(3,3));
734 CPPUNIT_ASSERT_MESSAGE("#1 first control point wrong",
735 aPoly
.getPrevControlPoint(0) == B2DPoint(2,2));
736 CPPUNIT_ASSERT_MESSAGE("#1 second control point wrong",
737 aPoly
.getNextControlPoint(0) == B2DPoint(3,3));
738 CPPUNIT_ASSERT_MESSAGE("next control point not used",
739 aPoly
.isNextControlPointUsed(0) == false);
741 aPoly
.setNextControlPoint(0,B2DPoint(4,4));
742 CPPUNIT_ASSERT_MESSAGE("#1.1 second control point wrong",
743 aPoly
.getNextControlPoint(0) == B2DPoint(4,4));
744 CPPUNIT_ASSERT_MESSAGE("next control point used",
745 aPoly
.isNextControlPointUsed(0) == true);
746 CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong",
747 aPoly
.areControlPointsUsed() == true);
748 CPPUNIT_ASSERT_MESSAGE("getContinuityInPoint() wrong",
749 aPoly
.getContinuityInPoint(0) == CONTINUITY_C2
);
751 aPoly
.resetControlPoints();
752 CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
753 aPoly
.getB2DPoint(0) == B2DPoint(3,3));
754 CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
755 aPoly
.getPrevControlPoint(0) == B2DPoint(3,3));
756 CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
757 aPoly
.getNextControlPoint(0) == B2DPoint(3,3));
758 CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong #2",
759 aPoly
.areControlPointsUsed() == false);
762 aPoly
.append(B2DPoint(0,0));
763 aPoly
.appendBezierSegment(B2DPoint(1,1),B2DPoint(2,2),B2DPoint(3,3));
765 CPPUNIT_ASSERT_MESSAGE("#2 first polygon point wrong",
766 aPoly
.getB2DPoint(0) == B2DPoint(0,0));
767 CPPUNIT_ASSERT_MESSAGE("#2 first control point wrong",
768 aPoly
.getPrevControlPoint(0) == B2DPoint(0,0));
769 CPPUNIT_ASSERT_MESSAGE("#2 second control point wrong",
770 aPoly
.getNextControlPoint(0) == B2DPoint(1,1));
771 CPPUNIT_ASSERT_MESSAGE("#2 third control point wrong",
772 aPoly
.getPrevControlPoint(1) == B2DPoint(2,2));
773 CPPUNIT_ASSERT_MESSAGE("#2 fourth control point wrong",
774 aPoly
.getNextControlPoint(1) == B2DPoint(3,3));
775 CPPUNIT_ASSERT_MESSAGE("#2 second polygon point wrong",
776 aPoly
.getB2DPoint(1) == B2DPoint(3,3));
778 // Change the following lines only, if you add, remove or rename
779 // member functions of the current class,
780 // because these macros are need by auto register mechanism.
782 CPPUNIT_TEST_SUITE(b2dpolygon
);
783 CPPUNIT_TEST(testBasics
);
784 CPPUNIT_TEST_SUITE_END();
785 }; // class b2dpolygon
788 class b2dpolygontools
: public CppUnit::TestFixture
791 // insert your test code here.
792 // this is only demonstration code
793 void testIsRectangle()
796 tools::createPolygonFromRect(
797 B2DRange(0,0,1,1) ) );
800 aRect2
.append( B2DPoint(0,0) );
801 aRect2
.append( B2DPoint(1,0) );
802 aRect2
.append( B2DPoint(1,.5));
803 aRect2
.append( B2DPoint(1,1) );
804 aRect2
.append( B2DPoint(0,1) );
805 aRect2
.setClosed(true);
807 B2DPolygon aNonRect1
;
808 aNonRect1
.append( B2DPoint(0,0) );
809 aNonRect1
.append( B2DPoint(1,0) );
810 aNonRect1
.append( B2DPoint(1,1) );
811 aNonRect1
.append( B2DPoint(0.5,1) );
812 aNonRect1
.append( B2DPoint(0.5,0) );
813 aNonRect1
.setClosed(true);
815 B2DPolygon aNonRect2
;
816 aNonRect2
.append( B2DPoint(0,0) );
817 aNonRect2
.append( B2DPoint(1,1) );
818 aNonRect2
.append( B2DPoint(1,0) );
819 aNonRect2
.append( B2DPoint(0,1) );
820 aNonRect2
.setClosed(true);
822 B2DPolygon aNonRect3
;
823 aNonRect3
.append( B2DPoint(0,0) );
824 aNonRect3
.append( B2DPoint(1,0) );
825 aNonRect3
.append( B2DPoint(1,1) );
826 aNonRect3
.setClosed(true);
828 B2DPolygon aNonRect4
;
829 aNonRect4
.append( B2DPoint(0,0) );
830 aNonRect4
.append( B2DPoint(1,0) );
831 aNonRect4
.append( B2DPoint(1,1) );
832 aNonRect4
.append( B2DPoint(0,1) );
834 B2DPolygon aNonRect5
;
835 aNonRect5
.append( B2DPoint(0,0) );
836 aNonRect5
.append( B2DPoint(1,0) );
837 aNonRect5
.append( B2DPoint(1,1) );
838 aNonRect5
.append( B2DPoint(0,1) );
839 aNonRect5
.setControlPoints(1,B2DPoint(1,0),B2DPoint(-11,0));
840 aNonRect5
.setClosed(true);
842 CPPUNIT_ASSERT_MESSAGE("checking rectangle-ness of rectangle 1",
843 tools::isRectangle( aRect1
));
844 CPPUNIT_ASSERT_MESSAGE("checking rectangle-ness of rectangle 2",
845 tools::isRectangle( aRect2
));
846 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 1",
847 !tools::isRectangle( aNonRect1
));
848 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 2",
849 !tools::isRectangle( aNonRect2
));
850 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 3",
851 !tools::isRectangle( aNonRect3
));
852 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 4",
853 !tools::isRectangle( aNonRect4
));
854 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 5",
855 !tools::isRectangle( aNonRect5
));
858 // Change the following lines only, if you add, remove or rename
859 // member functions of the current class,
860 // because these macros are need by auto register mechanism.
862 CPPUNIT_TEST_SUITE(b2dpolygontools
);
863 CPPUNIT_TEST(testIsRectangle
);
864 CPPUNIT_TEST_SUITE_END();
865 }; // class b2dpolygontools
868 class b2dpolypolygon
: public CppUnit::TestFixture
871 // insert your test code here.
876 // Change the following lines only, if you add, remove or rename
877 // member functions of the current class,
878 // because these macros are need by auto register mechanism.
880 CPPUNIT_TEST_SUITE(b2dpolypolygon
);
881 CPPUNIT_TEST(EmptyMethod
);
882 CPPUNIT_TEST_SUITE_END();
883 }; // class b2dpolypolygon
885 class b1Xrange
: public CppUnit::TestFixture
888 template<class Type
> void implCheck()
890 // test interval axioms
891 // (http://en.wikipedia.org/wiki/Interval_%28mathematics%29)
893 CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aRange
.isEmpty());
894 CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since range is empty", aRange
.getCenter()==0);
896 // degenerate interval
898 CPPUNIT_ASSERT_MESSAGE("degenerate range - still, not empty!", !aRange
.isEmpty());
899 CPPUNIT_ASSERT_MESSAGE("degenerate range - size of 0", aRange
.getRange() == 0);
900 CPPUNIT_ASSERT_MESSAGE("same value as degenerate range - is inside range", aRange
.isInside(1));
901 CPPUNIT_ASSERT_MESSAGE("center - must be the single range value", aRange
.getCenter()==1);
905 CPPUNIT_ASSERT_MESSAGE("proper range - size of 1", aRange
.getRange() == 1);
906 CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range", aRange
.isInside(1));
907 CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range", aRange
.isInside(2));
909 // center for proper interval that works for ints, too
911 CPPUNIT_ASSERT_MESSAGE("center - must be half of the range", aRange
.getCenter()==2);
915 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound", aRange
.overlaps(aRange2
));
916 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely", !aRange
.overlapsMore(aRange2
));
919 CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now", aRange
.overlapsMore(aRange3
));
923 aRange
.intersect(aRange4
);
924 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange
.isEmpty());
927 aRange
.intersect(aRange5
);
928 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange
.isEmpty());
930 // just so that this compiles -
931 Type
aRange6( aRange
);
937 implCheck
<B1DRange
>();
938 implCheck
<B1IRange
>();
941 // Change the following lines only, if you add, remove or rename
942 // member functions of the current class,
943 // because these macros are need by auto register mechanism.
945 CPPUNIT_TEST_SUITE(b1Xrange
);
947 CPPUNIT_TEST_SUITE_END();
951 class b1ibox
: public CppUnit::TestFixture
956 // test axioms - markedly different from proper mathematical
957 // intervals (behaviour modelled after how polygon fill
958 // algorithms fill pixels)
960 CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aBox
.isEmpty());
964 CPPUNIT_ASSERT_MESSAGE("degenerate box - still empty!", aBox
.isEmpty());
965 CPPUNIT_ASSERT_MESSAGE("degenerate box - size of 0", aBox
.getRange() == 0);
966 CPPUNIT_ASSERT_MESSAGE("same value as degenerate box - is outside (since empty)", !aBox
.isInside(1));
967 CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since box is empty", aBox
.getCenter()==0);
971 CPPUNIT_ASSERT_MESSAGE("proper box - size of 1", aBox
.getRange() == 1);
972 CPPUNIT_ASSERT_MESSAGE("smaller value of box", aBox
.isInside(1));
973 CPPUNIT_ASSERT_MESSAGE("larger value of box - must be outside", !aBox
.isInside(2));
975 // center for proper box that works for ints, too
977 CPPUNIT_ASSERT_MESSAGE("center - must be center pixel of the box", aBox
.getCenter()==2);
979 // check overlap, which is markedly different from Range
981 CPPUNIT_ASSERT_MESSAGE("box overlapping *excludes* upper bound", !aBox
.overlaps(aBox2
));
984 CPPUNIT_ASSERT_MESSAGE("box overlapping then includes upper bound-1", aBox
.overlaps(aBox3
));
988 aBox
.intersect(aBox4
);
989 CPPUNIT_ASSERT_MESSAGE("box intersection is yielding nonempty box!", aBox
.isEmpty());
992 aBox5
.intersect(aBox4
);
993 CPPUNIT_ASSERT_MESSAGE("box intersection is yielding empty box!", !aBox5
.isEmpty());
995 // just so that this compiles -
996 B1IBox
aBox6( aBox
);
1000 // Change the following lines only, if you add, remove or rename
1001 // member functions of the current class,
1002 // because these macros are need by auto register mechanism.
1004 CPPUNIT_TEST_SUITE(b1ibox
);
1005 CPPUNIT_TEST(TestBox
);
1006 CPPUNIT_TEST_SUITE_END();
1010 class b2Xrange
: public CppUnit::TestFixture
1013 template<class Type
> void implCheck()
1015 // cohen sutherland clipping
1016 Type
aRange(0,0,10,10);
1018 CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
1019 tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aRange
) == 0);
1020 CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
1021 tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aRange
) ==
1022 (tools::RectClipFlags::LEFT
|tools::RectClipFlags::TOP
));
1023 CPPUNIT_ASSERT_MESSAGE("(10,10) is outside range!",
1024 tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aRange
) == 0);
1025 CPPUNIT_ASSERT_MESSAGE("(11,11) is inside range!",
1026 tools::getCohenSutherlandClipFlags(B2IPoint(11,11),aRange
) ==
1027 (tools::RectClipFlags::RIGHT
|tools::RectClipFlags::BOTTOM
));
1029 // just so that this compiles -
1030 Type
aRange1( aRange
);
1036 implCheck
<B2DRange
>();
1037 implCheck
<B2IRange
>();
1040 // Change the following lines only, if you add, remove or rename
1041 // member functions of the current class,
1042 // because these macros are need by auto register mechanism.
1044 CPPUNIT_TEST_SUITE(b2Xrange
);
1045 CPPUNIT_TEST(check
);
1046 CPPUNIT_TEST_SUITE_END();
1047 }; // class b2Xrange
1050 class b2ibox
: public CppUnit::TestFixture
1055 // cohen sutherland clipping
1056 B2IBox
aBox(0,0,10,10);
1058 CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
1059 tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aBox
) == 0);
1060 CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
1061 tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aBox
) ==
1062 (tools::RectClipFlags::LEFT
|tools::RectClipFlags::TOP
));
1063 CPPUNIT_ASSERT_MESSAGE("(9,9) is outside range!",
1064 tools::getCohenSutherlandClipFlags(B2IPoint(9,9),aBox
) == 0);
1065 CPPUNIT_ASSERT_MESSAGE("(10,10) is inside range!",
1066 tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aBox
) ==
1067 (tools::RectClipFlags::RIGHT
|tools::RectClipFlags::BOTTOM
));
1069 // just so that this compiles -
1070 B2IBox
aBox1( aBox
);
1074 // Change the following lines only, if you add, remove or rename
1075 // member functions of the current class,
1076 // because these macros are need by auto register mechanism.
1077 CPPUNIT_TEST_SUITE(b2ibox
);
1078 CPPUNIT_TEST(TestBox
);
1079 CPPUNIT_TEST_SUITE_END();
1083 class b2dtuple
: public CppUnit::TestFixture
1086 // insert your test code here.
1087 // this is only demonstration code
1090 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
1093 // Change the following lines only, if you add, remove or rename
1094 // member functions of the current class,
1095 // because these macros are need by auto register mechanism.
1097 CPPUNIT_TEST_SUITE(b2dtuple
);
1098 CPPUNIT_TEST(EmptyMethod
);
1099 CPPUNIT_TEST_SUITE_END();
1100 }; // class b2dtuple
1102 class bcolor
: public CppUnit::TestFixture
1125 // insert your test code here.
1128 CPPUNIT_ASSERT_MESSAGE("white",
1129 tools::rgb2hsl(maWhite
) == BColor(0,0,1));
1130 CPPUNIT_ASSERT_MESSAGE("black",
1131 tools::rgb2hsl(maBlack
) == BColor(0,0,0));
1132 CPPUNIT_ASSERT_MESSAGE("red",
1133 tools::rgb2hsl(maRed
) == BColor(0,1,0.5));
1134 CPPUNIT_ASSERT_MESSAGE("green",
1135 tools::rgb2hsl(maGreen
) == BColor(120,1,0.5));
1136 CPPUNIT_ASSERT_MESSAGE("blue",
1137 tools::rgb2hsl(maBlue
) == BColor(240,1,0.5));
1138 CPPUNIT_ASSERT_MESSAGE("yellow",
1139 tools::rgb2hsl(maYellow
) == BColor(60,1,0.5));
1140 CPPUNIT_ASSERT_MESSAGE("magenta",
1141 tools::rgb2hsl(maMagenta
) == BColor(300,1,0.5));
1142 CPPUNIT_ASSERT_MESSAGE("cyan",
1143 tools::rgb2hsl(maCyan
) == BColor(180,1,0.5));
1144 CPPUNIT_ASSERT_MESSAGE("third hue case",
1145 tools::rgb2hsl(BColor(0,0.5,1)) == BColor(210,1,0.5));
1147 CPPUNIT_ASSERT_MESSAGE("roundtrip white",
1148 tools::hsl2rgb(tools::rgb2hsl(maWhite
)) == maWhite
);
1149 CPPUNIT_ASSERT_MESSAGE("roundtrip black",
1150 tools::hsl2rgb(tools::rgb2hsl(maBlack
)) == maBlack
);
1151 CPPUNIT_ASSERT_MESSAGE("roundtrip red",
1152 tools::hsl2rgb(tools::rgb2hsl(maRed
)) == maRed
);
1153 CPPUNIT_ASSERT_MESSAGE("roundtrip green",
1154 tools::hsl2rgb(tools::rgb2hsl(maGreen
)) == maGreen
);
1155 CPPUNIT_ASSERT_MESSAGE("roundtrip blue",
1156 tools::hsl2rgb(tools::rgb2hsl(maBlue
)) == maBlue
);
1157 CPPUNIT_ASSERT_MESSAGE("roundtrip yellow",
1158 tools::hsl2rgb(tools::rgb2hsl(maYellow
)) == maYellow
);
1159 CPPUNIT_ASSERT_MESSAGE("roundtrip magenta",
1160 tools::hsl2rgb(tools::rgb2hsl(maMagenta
)) == maMagenta
);
1161 CPPUNIT_ASSERT_MESSAGE("roundtrip cyan",
1162 tools::hsl2rgb(tools::rgb2hsl(maCyan
)) == maCyan
);
1164 CPPUNIT_ASSERT_MESSAGE("grey10",
1165 tools::rgb2hsl(maWhite
*.1) == BColor(0,0,.1));
1166 CPPUNIT_ASSERT_MESSAGE("grey90",
1167 tools::rgb2hsl(maWhite
*.9) == BColor(0,0,.9));
1168 CPPUNIT_ASSERT_MESSAGE("red/2",
1169 tools::rgb2hsl(maRed
*.5) == BColor(0,1,0.25));
1170 CPPUNIT_ASSERT_MESSAGE("green/2",
1171 tools::rgb2hsl(maGreen
*.5) == BColor(120,1,0.25));
1172 CPPUNIT_ASSERT_MESSAGE("blue/2",
1173 tools::rgb2hsl(maBlue
*.5) == BColor(240,1,0.25));
1174 CPPUNIT_ASSERT_MESSAGE("yellow/2",
1175 tools::rgb2hsl(maYellow
*.5) == BColor(60,1,0.25));
1176 CPPUNIT_ASSERT_MESSAGE("magenta/2",
1177 tools::rgb2hsl(maMagenta
*.5) == BColor(300,1,0.25));
1178 CPPUNIT_ASSERT_MESSAGE("cyan/2",
1179 tools::rgb2hsl(maCyan
*.5) == BColor(180,1,0.25));
1181 CPPUNIT_ASSERT_MESSAGE("pastel",
1182 tools::rgb2hsl(BColor(.75,.25,.25)) == BColor(0,.5,.5));
1185 // insert your test code here.
1188 CPPUNIT_ASSERT_MESSAGE("white",
1189 tools::rgb2hsv(maWhite
) == BColor(0,0,1));
1190 CPPUNIT_ASSERT_MESSAGE("black",
1191 tools::rgb2hsv(maBlack
) == BColor(0,0,0));
1192 CPPUNIT_ASSERT_MESSAGE("red",
1193 tools::rgb2hsv(maRed
) == BColor(0,1,1));
1194 CPPUNIT_ASSERT_MESSAGE("green",
1195 tools::rgb2hsv(maGreen
) == BColor(120,1,1));
1196 CPPUNIT_ASSERT_MESSAGE("blue",
1197 tools::rgb2hsv(maBlue
) == BColor(240,1,1));
1198 CPPUNIT_ASSERT_MESSAGE("yellow",
1199 tools::rgb2hsv(maYellow
) == BColor(60,1,1));
1200 CPPUNIT_ASSERT_MESSAGE("magenta",
1201 tools::rgb2hsv(maMagenta
) == BColor(300,1,1));
1202 CPPUNIT_ASSERT_MESSAGE("cyan",
1203 tools::rgb2hsv(maCyan
) == BColor(180,1,1));
1205 CPPUNIT_ASSERT_MESSAGE("roundtrip white",
1206 tools::hsv2rgb(tools::rgb2hsv(maWhite
)) == maWhite
);
1207 CPPUNIT_ASSERT_MESSAGE("roundtrip black",
1208 tools::hsv2rgb(tools::rgb2hsv(maBlack
)) == maBlack
);
1209 CPPUNIT_ASSERT_MESSAGE("roundtrip red",
1210 tools::hsv2rgb(tools::rgb2hsv(maRed
)) == maRed
);
1211 CPPUNIT_ASSERT_MESSAGE("roundtrip green",
1212 tools::hsv2rgb(tools::rgb2hsv(maGreen
)) == maGreen
);
1213 CPPUNIT_ASSERT_MESSAGE("roundtrip blue",
1214 tools::hsv2rgb(tools::rgb2hsv(maBlue
)) == maBlue
);
1215 CPPUNIT_ASSERT_MESSAGE("roundtrip yellow",
1216 tools::hsv2rgb(tools::rgb2hsv(maYellow
)) == maYellow
);
1217 CPPUNIT_ASSERT_MESSAGE("roundtrip magenta",
1218 tools::hsv2rgb(tools::rgb2hsv(maMagenta
)) == maMagenta
);
1219 CPPUNIT_ASSERT_MESSAGE("roundtrip cyan",
1220 tools::hsv2rgb(tools::rgb2hsv(maCyan
)) == maCyan
);
1222 CPPUNIT_ASSERT_MESSAGE("grey10",
1223 tools::rgb2hsv(maWhite
*.1) == BColor(0,0,.1));
1224 CPPUNIT_ASSERT_MESSAGE("grey90",
1225 tools::rgb2hsv(maWhite
*.9) == BColor(0,0,.9));
1226 CPPUNIT_ASSERT_MESSAGE("red/2",
1227 tools::rgb2hsv(maRed
*.5) == BColor(0,1,0.5));
1228 CPPUNIT_ASSERT_MESSAGE("green/2",
1229 tools::rgb2hsv(maGreen
*.5) == BColor(120,1,0.5));
1230 CPPUNIT_ASSERT_MESSAGE("blue/2",
1231 tools::rgb2hsv(maBlue
*.5) == BColor(240,1,0.5));
1232 CPPUNIT_ASSERT_MESSAGE("yellow/2",
1233 tools::rgb2hsv(maYellow
*.5) == BColor(60,1,0.5));
1234 CPPUNIT_ASSERT_MESSAGE("magenta/2",
1235 tools::rgb2hsv(maMagenta
*.5) == BColor(300,1,0.5));
1236 CPPUNIT_ASSERT_MESSAGE("cyan/2",
1237 tools::rgb2hsv(maCyan
*.5) == BColor(180,1,0.5));
1239 CPPUNIT_ASSERT_MESSAGE("pastel",
1240 tools::rgb2hsv(BColor(.5,.25,.25)) == BColor(0,.5,.5));
1245 tools::rgb2ciexyz(maWhite
);
1246 tools::rgb2ciexyz(maBlack
);
1247 tools::rgb2ciexyz(maRed
);
1248 tools::rgb2ciexyz(maGreen
);
1249 tools::rgb2ciexyz(maBlue
);
1250 tools::rgb2ciexyz(maYellow
);
1251 tools::rgb2ciexyz(maMagenta
);
1252 tools::rgb2ciexyz(maCyan
);
1255 // Change the following lines only, if you add, remove or rename
1256 // member functions of the current class,
1257 // because these macros are need by auto register mechanism.
1259 CPPUNIT_TEST_SUITE(bcolor
);
1260 CPPUNIT_TEST(hslTest
);
1261 CPPUNIT_TEST(hsvTest
);
1262 CPPUNIT_TEST(ciexyzTest
);
1263 CPPUNIT_TEST_SUITE_END();
1264 }; // class b2dvector
1266 // -----------------------------------------------------------------------------
1268 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dsvgdimpex
);
1269 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2drange
);
1270 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolyrange
);
1271 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dhommatrix
);
1272 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpoint
);
1273 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygon
);
1274 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygontools
);
1275 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolypolygon
);
1276 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1Xrange
);
1277 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1ibox
);
1278 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2Xrange
);
1279 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2ibox
);
1280 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dtuple
);
1281 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::bcolor
);
1282 } // namespace basegfx2d
1285 // -----------------------------------------------------------------------------
1287 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1288 // to let the user the possibility to also register some functions by hand.
1291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */