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
, aPath0
, false, 0 ));
146 aExport
= tools::exportToSvgD( aPoly
, true, true, false );
147 const char* sExportString
= "m10 10h-20v-20h20z";
148 CPPUNIT_ASSERT_MESSAGE("exporting rectangle to SVG-D",
149 aExport
.equalsAscii(sExportString
) );
150 CPPUNIT_ASSERT_MESSAGE("importing simple rectangle from SVG-D (round-trip",
151 tools::importFromSvgD( aPoly
, aExport
, false, 0 ));
152 aExport
= tools::exportToSvgD( aPoly
, true, true, false );
153 CPPUNIT_ASSERT_MESSAGE("exporting rectangle to SVG-D (round-trip)",
154 aExport
.equalsAscii(sExportString
));
156 CPPUNIT_ASSERT_MESSAGE("importing simple bezier polygon from SVG-D",
157 tools::importFromSvgD( aPoly
, aPath1
, false, 0 ));
158 aExport
= tools::exportToSvgD( aPoly
, true, true, false );
160 // Adaptions for B2DPolygon bezier change (see #i77162#):
162 // The import/export of aPath1 does not reproduce aExport again. This is
163 // correct since aPath1 contains a segment with non-used control points
164 // which gets exported now correctly as 'l' and also a point (#4, index 3)
165 // with C2 continuity which produces a 's' staement now.
167 // The old SVGexport identified nun-used ControlVectors erraneously as bezier segments
168 // because the 2nd vector at the start point was used, even when added
169 // with start point was identical to end point. Exactly for that reason
170 // i reworked the B2DPolygon to use prev, next control points.
172 // so for correct unit test i add the new exported string here as sExportStringSimpleBezier
173 // and compare to it.
174 const char* sExportStringSimpleBezier
=
175 "m11430 0c-8890 3810 5715 6985 5715 6985"
176 "l-17145-1905c0 0 22860-10160 16510 6350"
177 "s-3810-11430-3810-11430z";
178 CPPUNIT_ASSERT_MESSAGE("exporting bezier polygon to SVG-D", aExport
.equalsAscii(sExportStringSimpleBezier
));
180 // Adaptions for B2DPolygon bezier change (see #i77162#):
182 // a 2nd good test is that re-importing of aExport has to create the same
183 // B2DPolPolygon again:
184 B2DPolyPolygon aReImport
;
185 CPPUNIT_ASSERT_MESSAGE("importing simple bezier polygon from SVG-D", tools::importFromSvgD( aReImport
, aExport
, false, 0));
186 CPPUNIT_ASSERT_MESSAGE("re-imported polygon needs to be identical", aReImport
== aPoly
);
188 CPPUNIT_ASSERT_MESSAGE("importing '@' from SVG-D", tools::importFromSvgD( aPoly
, aPath2
, false, NULL
));
189 aExport
= tools::exportToSvgD( aPoly
, true, true, false );
191 // Adaptions for B2DPolygon bezier change (see #i77162#):
193 // same here, the corrected export with the corrected B2DPolygon is simply more efficient,
194 // so i needed to change the compare string. Also adding the re-import comparison below.
195 const char* sExportString1
=
196 "m1917 1114c-89-189-233-284-430-284-167 0-306 91-419 273s-170 370-17"
197 "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"
198 "-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-"
199 "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"
200 "-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"
201 "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"
202 "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"
203 "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"
204 "8 325 189-1 389-27 600-77 211-52 378-110 503-174q40.5 105 81 210z";
205 CPPUNIT_ASSERT_MESSAGE("re-importing '@' from SVG-D", tools::importFromSvgD( aReImport
, aExport
, false, 0));
206 CPPUNIT_ASSERT_MESSAGE("re-imported '@' needs to be identical", aReImport
== aPoly
);
208 CPPUNIT_ASSERT_MESSAGE("exporting '@' to SVG-D", aExport
.equalsAscii(sExportString1
));
209 CPPUNIT_ASSERT_MESSAGE("importing '@' from SVG-D (round-trip",
210 tools::importFromSvgD( aPoly
, aExport
, false, 0 ));
211 aExport
= tools::exportToSvgD( aPoly
, true, true, false );
212 CPPUNIT_ASSERT_MESSAGE("exporting '@' to SVG-D (round-trip)",
213 aExport
.equalsAscii(sExportString1
));
216 CPPUNIT_ASSERT_MESSAGE("importing complex polygon from SVG-D",
217 tools::importFromSvgD( aPoly
, aPath3
, false, 0 ));
218 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 "-28 30-26 31-24 33-22 34-20 35-18 36-16 37-15 39-12 40-11z";
240 CPPUNIT_ASSERT_MESSAGE("exporting complex polygon to SVG-D",
241 aExport
.equalsAscii(sExportString2
));
242 CPPUNIT_ASSERT_MESSAGE("importing complex polygon from SVG-D (round-trip",
243 tools::importFromSvgD( aPoly
, aExport
, false, 0 ));
244 aExport
= tools::exportToSvgD( aPoly
, true, true, false );
245 CPPUNIT_ASSERT_MESSAGE("exporting complex polygon to SVG-D (round-trip)",
246 aExport
.equalsAscii(sExportString2
));
248 const B2DPolygon
aRect(
249 tools::createPolygonFromRect( B2DRange(0.0,0.0,4000.0,4000.0) ));
250 aExport
= tools::exportToSvgD( B2DPolyPolygon(aRect
), false, false, false );
252 const char* sExportStringRect
= "M0 0H4000V4000H0Z";
253 CPPUNIT_ASSERT_MESSAGE("exporting to rectangle svg-d string",
254 aExport
.equalsAscii(sExportStringRect
));
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.
261 CPPUNIT_TEST_SUITE(b2dsvgdimpex
);
263 CPPUNIT_TEST_SUITE_END();
264 }; // class b2dsvgdimpex
266 class b2drange
: public CppUnit::TestFixture
272 CPPUNIT_ASSERT_MESSAGE("simple range rounding from double to integer",
273 fround(B2DRange(1.2, 2.3, 3.5, 4.8)) == B2IRange(1, 2, 4, 5));
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.
280 CPPUNIT_TEST_SUITE(b2drange
);
282 CPPUNIT_TEST_SUITE_END();
285 class b2dpolyrange
: public CppUnit::TestFixture
292 aRange
.appendElement(B2DRange(0,0,1,1),ORIENTATION_POSITIVE
);
293 aRange
.appendElement(B2DRange(2,2,3,3),ORIENTATION_POSITIVE
);
295 CPPUNIT_ASSERT_MESSAGE("simple poly range - count",
296 aRange
.count() == 2);
297 CPPUNIT_ASSERT_MESSAGE("simple poly range - first element",
298 aRange
.getElement(0).head
== B2DRange(0,0,1,1));
299 CPPUNIT_ASSERT_MESSAGE("simple poly range - second element",
300 aRange
.getElement(1).head
== B2DRange(2,2,3,3));
302 // B2DPolyRange relies on correctly orientated rects
303 const B2DRange
aRect(0,0,1,1);
304 CPPUNIT_ASSERT_MESSAGE("createPolygonFromRect - correct orientation",
305 tools::getOrientation(
306 tools::createPolygonFromRect(aRect
)) == ORIENTATION_POSITIVE
);
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.
313 CPPUNIT_TEST_SUITE(b2dpolyrange
);
315 CPPUNIT_TEST_SUITE_END();
318 class b2dhommatrix
: public CppUnit::TestFixture
321 B2DHomMatrix maIdentity
;
322 B2DHomMatrix maScale
;
323 B2DHomMatrix maTranslate
;
324 B2DHomMatrix maShear
;
325 B2DHomMatrix maAffine
;
326 B2DHomMatrix maPerspective
;
329 // initialise your test code values here.
332 // setup some test matrices
333 maIdentity
.identity(); // force compact layout
334 maIdentity
.set(0,0, 1.0);
335 maIdentity
.set(0,1, 0.0);
336 maIdentity
.set(0,2, 0.0);
337 maIdentity
.set(1,0, 0.0);
338 maIdentity
.set(1,1, 1.0);
339 maIdentity
.set(1,2, 0.0);
341 maScale
.identity(); // force compact layout
342 maScale
.set(0,0, 2.0);
343 maScale
.set(1,1, 20.0);
345 maTranslate
.identity(); // force compact layout
346 maTranslate
.set(0,2, 20.0);
347 maTranslate
.set(1,2, 2.0);
349 maShear
.identity(); // force compact layout
350 maShear
.set(0,1, 3.0);
351 maShear
.set(1,0, 7.0);
352 maShear
.set(1,1, 22.0);
354 maAffine
.identity(); // force compact layout
355 maAffine
.set(0,0, 1.0);
356 maAffine
.set(0,1, 2.0);
357 maAffine
.set(0,2, 3.0);
358 maAffine
.set(1,0, 4.0);
359 maAffine
.set(1,1, 5.0);
360 maAffine
.set(1,2, 6.0);
362 maPerspective
.set(0,0, 1.0);
363 maPerspective
.set(0,1, 2.0);
364 maPerspective
.set(0,2, 3.0);
365 maPerspective
.set(1,0, 4.0);
366 maPerspective
.set(1,1, 5.0);
367 maPerspective
.set(1,2, 6.0);
368 maPerspective
.set(2,0, 7.0);
369 maPerspective
.set(2,1, 8.0);
370 maPerspective
.set(2,2, 9.0);
379 B2DHomMatrix aIdentity
;
381 B2DHomMatrix aTranslate
;
383 B2DHomMatrix aAffine
;
384 B2DHomMatrix aPerspective
;
386 // setup some test matrices
387 aIdentity
.identity(); // force compact layout
388 aIdentity
.set(0,0, 1.0);
389 aIdentity
.set(0,1, 0.0);
390 aIdentity
.set(0,2, 0.0);
391 aIdentity
.set(1,0, 0.0);
392 aIdentity
.set(1,1, 1.0);
393 aIdentity
.set(1,2, 0.0);
395 aScale
.identity(); // force compact layout
396 aScale
.set(0,0, 2.0);
397 aScale
.set(1,1, 20.0);
399 aTranslate
.identity(); // force compact layout
400 aTranslate
.set(0,2, 20.0);
401 aTranslate
.set(1,2, 2.0);
403 aShear
.identity(); // force compact layout
404 aShear
.set(0,1, 3.0);
405 aShear
.set(1,0, 7.0);
406 aShear
.set(1,1, 22.0);
408 aAffine
.identity(); // force compact layout
409 aAffine
.set(0,0, 1.0);
410 aAffine
.set(0,1, 2.0);
411 aAffine
.set(0,2, 3.0);
412 aAffine
.set(1,0, 4.0);
413 aAffine
.set(1,1, 5.0);
414 aAffine
.set(1,2, 6.0);
416 aPerspective
.set(0,0, 1.0);
417 aPerspective
.set(0,1, 2.0);
418 aPerspective
.set(0,2, 3.0);
419 aPerspective
.set(1,0, 4.0);
420 aPerspective
.set(1,1, 5.0);
421 aPerspective
.set(1,2, 6.0);
422 aPerspective
.set(2,0, 7.0);
423 aPerspective
.set(2,1, 8.0);
424 aPerspective
.set(2,2, 9.0);
426 CPPUNIT_ASSERT_MESSAGE("operator==: identity matrix", aIdentity
== maIdentity
);
427 CPPUNIT_ASSERT_MESSAGE("operator==: scale matrix", aScale
== maScale
);
428 CPPUNIT_ASSERT_MESSAGE("operator==: translate matrix", aTranslate
== maTranslate
);
429 CPPUNIT_ASSERT_MESSAGE("operator==: shear matrix", aShear
== maShear
);
430 CPPUNIT_ASSERT_MESSAGE("operator==: affine matrix", aAffine
== maAffine
);
431 CPPUNIT_ASSERT_MESSAGE("operator==: perspective matrix", aPerspective
== maPerspective
);
438 CPPUNIT_ASSERT_MESSAGE("identity", maIdentity
== ident
);
445 CPPUNIT_ASSERT_MESSAGE("scale", maScale
== mat
);
451 mat
.rotate(90*F_PI180
);
452 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 mat
.get(1,2) == 0.0);
459 mat
.rotate(90*F_PI180
);
460 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 mat
.get(1,2) == 0.0);
467 mat
.rotate(90*F_PI180
);
468 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 mat
.get(1,2) == 0.0);
475 mat
.rotate(90*F_PI180
);
476 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 mat
.get(1,2) == 0.0);
488 mat
.translate(20.0,2.0);
489 CPPUNIT_ASSERT_MESSAGE("translate", maTranslate
== mat
);
497 CPPUNIT_ASSERT_MESSAGE("translate", maShear
== mat
);
502 B2DHomMatrix affineAffineProd
;
504 affineAffineProd
.set(0,0, 9);
505 affineAffineProd
.set(0,1, 12);
506 affineAffineProd
.set(0,2, 18);
507 affineAffineProd
.set(1,0, 24);
508 affineAffineProd
.set(1,1, 33);
509 affineAffineProd
.set(1,2, 48);
511 B2DHomMatrix affinePerspectiveProd
;
513 affinePerspectiveProd
.set(0,0, 30);
514 affinePerspectiveProd
.set(0,1, 36);
515 affinePerspectiveProd
.set(0,2, 42);
516 affinePerspectiveProd
.set(1,0, 66);
517 affinePerspectiveProd
.set(1,1, 81);
518 affinePerspectiveProd
.set(1,2, 96);
519 affinePerspectiveProd
.set(2,0, 7);
520 affinePerspectiveProd
.set(2,1, 8);
521 affinePerspectiveProd
.set(2,2, 9);
523 B2DHomMatrix perspectiveAffineProd
;
525 perspectiveAffineProd
.set(0,0, 9);
526 perspectiveAffineProd
.set(0,1, 12);
527 perspectiveAffineProd
.set(0,2, 18);
528 perspectiveAffineProd
.set(1,0, 24);
529 perspectiveAffineProd
.set(1,1, 33);
530 perspectiveAffineProd
.set(1,2, 48);
531 perspectiveAffineProd
.set(2,0, 39);
532 perspectiveAffineProd
.set(2,1, 54);
533 perspectiveAffineProd
.set(2,2, 78);
535 B2DHomMatrix perspectivePerspectiveProd
;
537 perspectivePerspectiveProd
.set(0,0, 30);
538 perspectivePerspectiveProd
.set(0,1, 36);
539 perspectivePerspectiveProd
.set(0,2, 42);
540 perspectivePerspectiveProd
.set(1,0, 66);
541 perspectivePerspectiveProd
.set(1,1, 81);
542 perspectivePerspectiveProd
.set(1,2, 96);
543 perspectivePerspectiveProd
.set(2,0, 102);
544 perspectivePerspectiveProd
.set(2,1, 126);
545 perspectivePerspectiveProd
.set(2,2, 150);
551 CPPUNIT_ASSERT_MESSAGE("multiply: both compact", temp
== affineAffineProd
);
553 temp
= maPerspective
;
555 CPPUNIT_ASSERT_MESSAGE("multiply: first compact", temp
== affinePerspectiveProd
);
559 CPPUNIT_ASSERT_MESSAGE("multiply: second compact", temp
== perspectiveAffineProd
);
561 temp
= maPerspective
;
563 CPPUNIT_ASSERT_MESSAGE("multiply: none compact", temp
== perspectivePerspectiveProd
);
566 void impFillMatrix(B2DHomMatrix
& rSource
, double fScaleX
, double fScaleY
, double fShearX
, double fRotate
)
568 // fill rSource with a linear combination of scale, shear and rotate
570 rSource
.scale(fScaleX
, fScaleY
);
571 rSource
.shearX(fShearX
);
572 rSource
.rotate(fRotate
);
575 bool impDecomposeComposeTest(double fScaleX
, double fScaleY
, double fShearX
, double fRotate
)
577 // linear combine matrix with given values
578 B2DHomMatrix aSource
;
579 impFillMatrix(aSource
, fScaleX
, fScaleY
, fShearX
, fRotate
);
581 // decompose that matrix
586 bool bWorked
= aSource
.decompose(aDScale
, aDTrans
, fDRot
, fDShX
);
588 // linear combine another matrix with decomposition results
589 B2DHomMatrix aRecombined
;
590 impFillMatrix(aRecombined
, aDScale
.getX(), aDScale
.getY(), fDShX
, fDRot
);
592 // if decomposition worked, matrices need to be the same
593 return bWorked
&& aSource
== aRecombined
;
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
);
607 // check all possible scaling combinations
608 CPPUNIT_ASSERT_MESSAGE("decompose: error test A1", impDecomposeComposeTest(fSX
, fSY
, 0.0, 0.0));
609 CPPUNIT_ASSERT_MESSAGE("decompose: error test A2", impDecomposeComposeTest(-fSX
, fSY
, 0.0, 0.0));
610 CPPUNIT_ASSERT_MESSAGE("decompose: error test A3", impDecomposeComposeTest(fSX
, -fSY
, 0.0, 0.0));
611 CPPUNIT_ASSERT_MESSAGE("decompose: error test A4", impDecomposeComposeTest(-fSX
, -fSY
, 0.0, 0.0));
613 // check all possible scaling combinations with positive rotation
614 CPPUNIT_ASSERT_MESSAGE("decompose: error test B1", impDecomposeComposeTest(fSX
, fSY
, 0.0, fR
));
615 CPPUNIT_ASSERT_MESSAGE("decompose: error test B2", impDecomposeComposeTest(-fSX
, fSY
, 0.0, fR
));
616 CPPUNIT_ASSERT_MESSAGE("decompose: error test B3", impDecomposeComposeTest(fSX
, -fSY
, 0.0, fR
));
617 CPPUNIT_ASSERT_MESSAGE("decompose: error test B4", impDecomposeComposeTest(-fSX
, -fSY
, 0.0, fR
));
619 // check all possible scaling combinations with negative rotation
620 CPPUNIT_ASSERT_MESSAGE("decompose: error test C1", impDecomposeComposeTest(fSX
, fSY
, 0.0, -fR
));
621 CPPUNIT_ASSERT_MESSAGE("decompose: error test C2", impDecomposeComposeTest(-fSX
, fSY
, 0.0, -fR
));
622 CPPUNIT_ASSERT_MESSAGE("decompose: error test C3", impDecomposeComposeTest(fSX
, -fSY
, 0.0, -fR
));
623 CPPUNIT_ASSERT_MESSAGE("decompose: error test C4", impDecomposeComposeTest(-fSX
, -fSY
, 0.0, -fR
));
625 // check all possible scaling combinations with positive shear
626 CPPUNIT_ASSERT_MESSAGE("decompose: error test D1", impDecomposeComposeTest(fSX
, fSY
, tan(fS
), 0.0));
627 CPPUNIT_ASSERT_MESSAGE("decompose: error test D2", impDecomposeComposeTest(-fSX
, fSY
, tan(fS
), 0.0));
628 CPPUNIT_ASSERT_MESSAGE("decompose: error test D3", impDecomposeComposeTest(fSX
, -fSY
, tan(fS
), 0.0));
629 CPPUNIT_ASSERT_MESSAGE("decompose: error test D4", impDecomposeComposeTest(-fSX
, -fSY
, tan(fS
), 0.0));
631 // check all possible scaling combinations with negative shear
632 CPPUNIT_ASSERT_MESSAGE("decompose: error test E1", impDecomposeComposeTest(fSX
, fSY
, tan(-fS
), 0.0));
633 CPPUNIT_ASSERT_MESSAGE("decompose: error test E2", impDecomposeComposeTest(-fSX
, fSY
, tan(-fS
), 0.0));
634 CPPUNIT_ASSERT_MESSAGE("decompose: error test E3", impDecomposeComposeTest(fSX
, -fSY
, tan(-fS
), 0.0));
635 CPPUNIT_ASSERT_MESSAGE("decompose: error test E4", impDecomposeComposeTest(-fSX
, -fSY
, tan(-fS
), 0.0));
637 // check all possible scaling combinations with positive rotate and positive shear
638 CPPUNIT_ASSERT_MESSAGE("decompose: error test F1", impDecomposeComposeTest(fSX
, fSY
, tan(fS
), fR
));
639 CPPUNIT_ASSERT_MESSAGE("decompose: error test F2", impDecomposeComposeTest(-fSX
, fSY
, tan(fS
), fR
));
640 CPPUNIT_ASSERT_MESSAGE("decompose: error test F3", impDecomposeComposeTest(fSX
, -fSY
, tan(fS
), fR
));
641 CPPUNIT_ASSERT_MESSAGE("decompose: error test F4", impDecomposeComposeTest(-fSX
, -fSY
, tan(fS
), fR
));
643 // check all possible scaling combinations with negative rotate and positive shear
644 CPPUNIT_ASSERT_MESSAGE("decompose: error test G1", impDecomposeComposeTest(fSX
, fSY
, tan(fS
), -fR
));
645 CPPUNIT_ASSERT_MESSAGE("decompose: error test G2", impDecomposeComposeTest(-fSX
, fSY
, tan(fS
), -fR
));
646 CPPUNIT_ASSERT_MESSAGE("decompose: error test G3", impDecomposeComposeTest(fSX
, -fSY
, tan(fS
), -fR
));
647 CPPUNIT_ASSERT_MESSAGE("decompose: error test G4", impDecomposeComposeTest(-fSX
, -fSY
, tan(fS
), -fR
));
649 // check all possible scaling combinations with positive rotate and negative shear
650 CPPUNIT_ASSERT_MESSAGE("decompose: error test H1", impDecomposeComposeTest(fSX
, fSY
, tan(-fS
), fR
));
651 CPPUNIT_ASSERT_MESSAGE("decompose: error test H2", impDecomposeComposeTest(-fSX
, fSY
, tan(-fS
), fR
));
652 CPPUNIT_ASSERT_MESSAGE("decompose: error test H3", impDecomposeComposeTest(fSX
, -fSY
, tan(-fS
), fR
));
653 CPPUNIT_ASSERT_MESSAGE("decompose: error test H4", impDecomposeComposeTest(-fSX
, -fSY
, tan(-fS
), fR
));
655 // check all possible scaling combinations with negative rotate and negative shear
656 CPPUNIT_ASSERT_MESSAGE("decompose: error test I1", impDecomposeComposeTest(fSX
, fSY
, tan(-fS
), -fR
));
657 CPPUNIT_ASSERT_MESSAGE("decompose: error test I2", impDecomposeComposeTest(-fSX
, fSY
, tan(-fS
), -fR
));
658 CPPUNIT_ASSERT_MESSAGE("decompose: error test I3", impDecomposeComposeTest(fSX
, -fSY
, tan(-fS
), -fR
));
659 CPPUNIT_ASSERT_MESSAGE("decompose: error test I4", impDecomposeComposeTest(-fSX
, -fSY
, tan(-fS
), -fR
));
661 // cover special case of 180 degree rotation
662 B2DHomMatrix aTest
=tools::createScaleShearXRotateTranslateB2DHomMatrix(
667 // decompose that matrix
672 aTest
.decompose(aDScale
, aDTrans
, fDRot
, fDShX
);
673 CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDScale
.getX() == 6425 && aDScale
.getY() == 3938);
674 CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDTrans
.getX() == 10482 && aDTrans
.getY() == 4921);
675 CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", fDRot
== 180*F_PI180
);
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.
682 CPPUNIT_TEST_SUITE(b2dhommatrix
);
684 CPPUNIT_TEST(identity
);
686 CPPUNIT_TEST(translate
);
687 CPPUNIT_TEST(rotate
);
689 CPPUNIT_TEST(multiply
);
690 CPPUNIT_TEST(decompose
);
691 CPPUNIT_TEST_SUITE_END();
693 }; // class b2dhommatrix
696 class b2dpoint
: public CppUnit::TestFixture
699 // insert your test code here.
700 // this is only demonstration code
703 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
706 // Change the following lines only, if you add, remove or rename
707 // member functions of the current class,
708 // because these macros are need by auto register mechanism.
710 CPPUNIT_TEST_SUITE(b2dpoint
);
711 CPPUNIT_TEST(EmptyMethod
);
712 CPPUNIT_TEST_SUITE_END();
716 class b2dpolygon
: public CppUnit::TestFixture
719 // insert your test code here.
724 aPoly
.appendBezierSegment(B2DPoint(1,1),B2DPoint(2,2),B2DPoint(3,3));
726 CPPUNIT_ASSERT_MESSAGE("#1 first polygon point wrong",
727 aPoly
.getB2DPoint(0) == B2DPoint(3,3));
728 CPPUNIT_ASSERT_MESSAGE("#1 first control point wrong",
729 aPoly
.getPrevControlPoint(0) == B2DPoint(2,2));
730 CPPUNIT_ASSERT_MESSAGE("#1 second control point wrong",
731 aPoly
.getNextControlPoint(0) == B2DPoint(3,3));
732 CPPUNIT_ASSERT_MESSAGE("next control point not used",
733 aPoly
.isNextControlPointUsed(0) == false);
735 aPoly
.setNextControlPoint(0,B2DPoint(4,4));
736 CPPUNIT_ASSERT_MESSAGE("#1.1 second control point wrong",
737 aPoly
.getNextControlPoint(0) == B2DPoint(4,4));
738 CPPUNIT_ASSERT_MESSAGE("next control point used",
739 aPoly
.isNextControlPointUsed(0) == true);
740 CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong",
741 aPoly
.areControlPointsUsed() == true);
742 CPPUNIT_ASSERT_MESSAGE("getContinuityInPoint() wrong",
743 aPoly
.getContinuityInPoint(0) == CONTINUITY_C2
);
745 aPoly
.resetControlPoints();
746 CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
747 aPoly
.getB2DPoint(0) == B2DPoint(3,3));
748 CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
749 aPoly
.getPrevControlPoint(0) == B2DPoint(3,3));
750 CPPUNIT_ASSERT_MESSAGE("resetControlPoints() did not clear",
751 aPoly
.getNextControlPoint(0) == B2DPoint(3,3));
752 CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong #2",
753 aPoly
.areControlPointsUsed() == false);
756 aPoly
.append(B2DPoint(0,0));
757 aPoly
.appendBezierSegment(B2DPoint(1,1),B2DPoint(2,2),B2DPoint(3,3));
759 CPPUNIT_ASSERT_MESSAGE("#2 first polygon point wrong",
760 aPoly
.getB2DPoint(0) == B2DPoint(0,0));
761 CPPUNIT_ASSERT_MESSAGE("#2 first control point wrong",
762 aPoly
.getPrevControlPoint(0) == B2DPoint(0,0));
763 CPPUNIT_ASSERT_MESSAGE("#2 second control point wrong",
764 aPoly
.getNextControlPoint(0) == B2DPoint(1,1));
765 CPPUNIT_ASSERT_MESSAGE("#2 third control point wrong",
766 aPoly
.getPrevControlPoint(1) == B2DPoint(2,2));
767 CPPUNIT_ASSERT_MESSAGE("#2 fourth control point wrong",
768 aPoly
.getNextControlPoint(1) == B2DPoint(3,3));
769 CPPUNIT_ASSERT_MESSAGE("#2 second polygon point wrong",
770 aPoly
.getB2DPoint(1) == B2DPoint(3,3));
772 // Change the following lines only, if you add, remove or rename
773 // member functions of the current class,
774 // because these macros are need by auto register mechanism.
776 CPPUNIT_TEST_SUITE(b2dpolygon
);
777 CPPUNIT_TEST(testBasics
);
778 CPPUNIT_TEST_SUITE_END();
779 }; // class b2dpolygon
782 class b2dpolygontools
: public CppUnit::TestFixture
785 // insert your test code here.
786 // this is only demonstration code
787 void testIsRectangle()
790 tools::createPolygonFromRect(
791 B2DRange(0,0,1,1) ) );
794 aRect2
.append( B2DPoint(0,0) );
795 aRect2
.append( B2DPoint(1,0) );
796 aRect2
.append( B2DPoint(1,.5));
797 aRect2
.append( B2DPoint(1,1) );
798 aRect2
.append( B2DPoint(0,1) );
799 aRect2
.setClosed(true);
801 B2DPolygon aNonRect1
;
802 aNonRect1
.append( B2DPoint(0,0) );
803 aNonRect1
.append( B2DPoint(1,0) );
804 aNonRect1
.append( B2DPoint(1,1) );
805 aNonRect1
.append( B2DPoint(0.5,1) );
806 aNonRect1
.append( B2DPoint(0.5,0) );
807 aNonRect1
.setClosed(true);
809 B2DPolygon aNonRect2
;
810 aNonRect2
.append( B2DPoint(0,0) );
811 aNonRect2
.append( B2DPoint(1,1) );
812 aNonRect2
.append( B2DPoint(1,0) );
813 aNonRect2
.append( B2DPoint(0,1) );
814 aNonRect2
.setClosed(true);
816 B2DPolygon aNonRect3
;
817 aNonRect3
.append( B2DPoint(0,0) );
818 aNonRect3
.append( B2DPoint(1,0) );
819 aNonRect3
.append( B2DPoint(1,1) );
820 aNonRect3
.setClosed(true);
822 B2DPolygon aNonRect4
;
823 aNonRect4
.append( B2DPoint(0,0) );
824 aNonRect4
.append( B2DPoint(1,0) );
825 aNonRect4
.append( B2DPoint(1,1) );
826 aNonRect4
.append( B2DPoint(0,1) );
828 B2DPolygon aNonRect5
;
829 aNonRect5
.append( B2DPoint(0,0) );
830 aNonRect5
.append( B2DPoint(1,0) );
831 aNonRect5
.append( B2DPoint(1,1) );
832 aNonRect5
.append( B2DPoint(0,1) );
833 aNonRect5
.setControlPoints(1,B2DPoint(1,0),B2DPoint(-11,0));
834 aNonRect5
.setClosed(true);
836 CPPUNIT_ASSERT_MESSAGE("checking rectangle-ness of rectangle 1",
837 tools::isRectangle( aRect1
));
838 CPPUNIT_ASSERT_MESSAGE("checking rectangle-ness of rectangle 2",
839 tools::isRectangle( aRect2
));
840 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 1",
841 !tools::isRectangle( aNonRect1
));
842 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 2",
843 !tools::isRectangle( aNonRect2
));
844 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 3",
845 !tools::isRectangle( aNonRect3
));
846 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 4",
847 !tools::isRectangle( aNonRect4
));
848 CPPUNIT_ASSERT_MESSAGE("checking non-rectangle-ness of polygon 5",
849 !tools::isRectangle( aNonRect5
));
852 // Change the following lines only, if you add, remove or rename
853 // member functions of the current class,
854 // because these macros are need by auto register mechanism.
856 CPPUNIT_TEST_SUITE(b2dpolygontools
);
857 CPPUNIT_TEST(testIsRectangle
);
858 CPPUNIT_TEST_SUITE_END();
859 }; // class b2dpolygontools
862 class b2dpolypolygon
: public CppUnit::TestFixture
865 // insert your test code here.
870 // Change the following lines only, if you add, remove or rename
871 // member functions of the current class,
872 // because these macros are need by auto register mechanism.
874 CPPUNIT_TEST_SUITE(b2dpolypolygon
);
875 CPPUNIT_TEST(EmptyMethod
);
876 CPPUNIT_TEST_SUITE_END();
877 }; // class b2dpolypolygon
879 class b1Xrange
: public CppUnit::TestFixture
882 template<class Type
> void implCheck()
884 // test interval axioms
885 // (http://en.wikipedia.org/wiki/Interval_%28mathematics%29)
887 CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aRange
.isEmpty());
888 CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since range is empty", aRange
.getCenter()==0);
890 // degenerate interval
892 CPPUNIT_ASSERT_MESSAGE("degenerate range - still, not empty!", !aRange
.isEmpty());
893 CPPUNIT_ASSERT_MESSAGE("degenerate range - size of 0", aRange
.getRange() == 0);
894 CPPUNIT_ASSERT_MESSAGE("same value as degenerate range - is inside range", aRange
.isInside(1));
895 CPPUNIT_ASSERT_MESSAGE("center - must be the single range value", aRange
.getCenter()==1);
899 CPPUNIT_ASSERT_MESSAGE("proper range - size of 1", aRange
.getRange() == 1);
900 CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range", aRange
.isInside(1));
901 CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range", aRange
.isInside(2));
903 // center for proper interval that works for ints, too
905 CPPUNIT_ASSERT_MESSAGE("center - must be half of the range", aRange
.getCenter()==2);
909 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound", aRange
.overlaps(aRange2
));
910 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely", !aRange
.overlapsMore(aRange2
));
913 CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now", aRange
.overlapsMore(aRange3
));
917 aRange
.intersect(aRange4
);
918 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange
.isEmpty());
921 aRange
.intersect(aRange5
);
922 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange
.isEmpty());
924 // just so that this compiles -
925 Type
aRange6( aRange
);
931 implCheck
<B1DRange
>();
932 implCheck
<B1IRange
>();
935 // Change the following lines only, if you add, remove or rename
936 // member functions of the current class,
937 // because these macros are need by auto register mechanism.
939 CPPUNIT_TEST_SUITE(b1Xrange
);
941 CPPUNIT_TEST_SUITE_END();
945 class b1ibox
: public CppUnit::TestFixture
950 // test axioms - markedly different from proper mathematical
951 // intervals (behaviour modelled after how polygon fill
952 // algorithms fill pixels)
954 CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aBox
.isEmpty());
958 CPPUNIT_ASSERT_MESSAGE("degenerate box - still empty!", aBox
.isEmpty());
959 CPPUNIT_ASSERT_MESSAGE("degenerate box - size of 0", aBox
.getRange() == 0);
960 CPPUNIT_ASSERT_MESSAGE("same value as degenerate box - is outside (since empty)", !aBox
.isInside(1));
961 CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since box is empty", aBox
.getCenter()==0);
965 CPPUNIT_ASSERT_MESSAGE("proper box - size of 1", aBox
.getRange() == 1);
966 CPPUNIT_ASSERT_MESSAGE("smaller value of box", aBox
.isInside(1));
967 CPPUNIT_ASSERT_MESSAGE("larger value of box - must be outside", !aBox
.isInside(2));
969 // center for proper box that works for ints, too
971 CPPUNIT_ASSERT_MESSAGE("center - must be center pixel of the box", aBox
.getCenter()==2);
973 // check overlap, which is markedly different from Range
975 CPPUNIT_ASSERT_MESSAGE("box overlapping *excludes* upper bound", !aBox
.overlaps(aBox2
));
978 CPPUNIT_ASSERT_MESSAGE("box overlapping then includes upper bound-1", aBox
.overlaps(aBox3
));
982 aBox
.intersect(aBox4
);
983 CPPUNIT_ASSERT_MESSAGE("box intersection is yielding nonempty box!", aBox
.isEmpty());
986 aBox5
.intersect(aBox4
);
987 CPPUNIT_ASSERT_MESSAGE("box intersection is yielding empty box!", !aBox5
.isEmpty());
989 // just so that this compiles -
990 B1IBox
aBox6( aBox
);
994 // Change the following lines only, if you add, remove or rename
995 // member functions of the current class,
996 // because these macros are need by auto register mechanism.
998 CPPUNIT_TEST_SUITE(b1ibox
);
999 CPPUNIT_TEST(TestBox
);
1000 CPPUNIT_TEST_SUITE_END();
1004 class b2Xrange
: public CppUnit::TestFixture
1007 template<class Type
> void implCheck()
1009 // cohen sutherland clipping
1010 Type
aRange(0,0,10,10);
1012 CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
1013 tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aRange
) == 0);
1014 CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
1015 tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aRange
) ==
1016 (tools::RectClipFlags::LEFT
|tools::RectClipFlags::TOP
));
1017 CPPUNIT_ASSERT_MESSAGE("(10,10) is outside range!",
1018 tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aRange
) == 0);
1019 CPPUNIT_ASSERT_MESSAGE("(11,11) is inside range!",
1020 tools::getCohenSutherlandClipFlags(B2IPoint(11,11),aRange
) ==
1021 (tools::RectClipFlags::RIGHT
|tools::RectClipFlags::BOTTOM
));
1023 // just so that this compiles -
1024 Type
aRange1( aRange
);
1030 implCheck
<B2DRange
>();
1031 implCheck
<B2IRange
>();
1034 // Change the following lines only, if you add, remove or rename
1035 // member functions of the current class,
1036 // because these macros are need by auto register mechanism.
1038 CPPUNIT_TEST_SUITE(b2Xrange
);
1039 CPPUNIT_TEST(check
);
1040 CPPUNIT_TEST_SUITE_END();
1041 }; // class b2Xrange
1044 class b2ibox
: public CppUnit::TestFixture
1049 // cohen sutherland clipping
1050 B2IBox
aBox(0,0,10,10);
1052 CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
1053 tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aBox
) == 0);
1054 CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
1055 tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aBox
) ==
1056 (tools::RectClipFlags::LEFT
|tools::RectClipFlags::TOP
));
1057 CPPUNIT_ASSERT_MESSAGE("(9,9) is outside range!",
1058 tools::getCohenSutherlandClipFlags(B2IPoint(9,9),aBox
) == 0);
1059 CPPUNIT_ASSERT_MESSAGE("(10,10) is inside range!",
1060 tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aBox
) ==
1061 (tools::RectClipFlags::RIGHT
|tools::RectClipFlags::BOTTOM
));
1063 // just so that this compiles -
1064 B2IBox
aBox1( aBox
);
1068 // Change the following lines only, if you add, remove or rename
1069 // member functions of the current class,
1070 // because these macros are need by auto register mechanism.
1071 CPPUNIT_TEST_SUITE(b2ibox
);
1072 CPPUNIT_TEST(TestBox
);
1073 CPPUNIT_TEST_SUITE_END();
1077 class b2dtuple
: public CppUnit::TestFixture
1080 // insert your test code here.
1081 // this is only demonstration code
1084 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
1087 // Change the following lines only, if you add, remove or rename
1088 // member functions of the current class,
1089 // because these macros are need by auto register mechanism.
1091 CPPUNIT_TEST_SUITE(b2dtuple
);
1092 CPPUNIT_TEST(EmptyMethod
);
1093 CPPUNIT_TEST_SUITE_END();
1094 }; // class b2dtuple
1096 class bcolor
: public CppUnit::TestFixture
1119 // insert your test code here.
1122 CPPUNIT_ASSERT_MESSAGE("white",
1123 tools::rgb2hsl(maWhite
) == BColor(0,0,1));
1124 CPPUNIT_ASSERT_MESSAGE("black",
1125 tools::rgb2hsl(maBlack
) == BColor(0,0,0));
1126 CPPUNIT_ASSERT_MESSAGE("red",
1127 tools::rgb2hsl(maRed
) == BColor(0,1,0.5));
1128 CPPUNIT_ASSERT_MESSAGE("green",
1129 tools::rgb2hsl(maGreen
) == BColor(120,1,0.5));
1130 CPPUNIT_ASSERT_MESSAGE("blue",
1131 tools::rgb2hsl(maBlue
) == BColor(240,1,0.5));
1132 CPPUNIT_ASSERT_MESSAGE("yellow",
1133 tools::rgb2hsl(maYellow
) == BColor(60,1,0.5));
1134 CPPUNIT_ASSERT_MESSAGE("magenta",
1135 tools::rgb2hsl(maMagenta
) == BColor(300,1,0.5));
1136 CPPUNIT_ASSERT_MESSAGE("cyan",
1137 tools::rgb2hsl(maCyan
) == BColor(180,1,0.5));
1138 CPPUNIT_ASSERT_MESSAGE("third hue case",
1139 tools::rgb2hsl(BColor(0,0.5,1)) == BColor(210,1,0.5));
1141 CPPUNIT_ASSERT_MESSAGE("roundtrip white",
1142 tools::hsl2rgb(tools::rgb2hsl(maWhite
)) == maWhite
);
1143 CPPUNIT_ASSERT_MESSAGE("roundtrip black",
1144 tools::hsl2rgb(tools::rgb2hsl(maBlack
)) == maBlack
);
1145 CPPUNIT_ASSERT_MESSAGE("roundtrip red",
1146 tools::hsl2rgb(tools::rgb2hsl(maRed
)) == maRed
);
1147 CPPUNIT_ASSERT_MESSAGE("roundtrip green",
1148 tools::hsl2rgb(tools::rgb2hsl(maGreen
)) == maGreen
);
1149 CPPUNIT_ASSERT_MESSAGE("roundtrip blue",
1150 tools::hsl2rgb(tools::rgb2hsl(maBlue
)) == maBlue
);
1151 CPPUNIT_ASSERT_MESSAGE("roundtrip yellow",
1152 tools::hsl2rgb(tools::rgb2hsl(maYellow
)) == maYellow
);
1153 CPPUNIT_ASSERT_MESSAGE("roundtrip magenta",
1154 tools::hsl2rgb(tools::rgb2hsl(maMagenta
)) == maMagenta
);
1155 CPPUNIT_ASSERT_MESSAGE("roundtrip cyan",
1156 tools::hsl2rgb(tools::rgb2hsl(maCyan
)) == maCyan
);
1158 CPPUNIT_ASSERT_MESSAGE("grey10",
1159 tools::rgb2hsl(maWhite
*.1) == BColor(0,0,.1));
1160 CPPUNIT_ASSERT_MESSAGE("grey90",
1161 tools::rgb2hsl(maWhite
*.9) == BColor(0,0,.9));
1162 CPPUNIT_ASSERT_MESSAGE("red/2",
1163 tools::rgb2hsl(maRed
*.5) == BColor(0,1,0.25));
1164 CPPUNIT_ASSERT_MESSAGE("green/2",
1165 tools::rgb2hsl(maGreen
*.5) == BColor(120,1,0.25));
1166 CPPUNIT_ASSERT_MESSAGE("blue/2",
1167 tools::rgb2hsl(maBlue
*.5) == BColor(240,1,0.25));
1168 CPPUNIT_ASSERT_MESSAGE("yellow/2",
1169 tools::rgb2hsl(maYellow
*.5) == BColor(60,1,0.25));
1170 CPPUNIT_ASSERT_MESSAGE("magenta/2",
1171 tools::rgb2hsl(maMagenta
*.5) == BColor(300,1,0.25));
1172 CPPUNIT_ASSERT_MESSAGE("cyan/2",
1173 tools::rgb2hsl(maCyan
*.5) == BColor(180,1,0.25));
1175 CPPUNIT_ASSERT_MESSAGE("pastel",
1176 tools::rgb2hsl(BColor(.75,.25,.25)) == BColor(0,.5,.5));
1179 // insert your test code here.
1182 CPPUNIT_ASSERT_MESSAGE("white",
1183 tools::rgb2hsv(maWhite
) == BColor(0,0,1));
1184 CPPUNIT_ASSERT_MESSAGE("black",
1185 tools::rgb2hsv(maBlack
) == BColor(0,0,0));
1186 CPPUNIT_ASSERT_MESSAGE("red",
1187 tools::rgb2hsv(maRed
) == BColor(0,1,1));
1188 CPPUNIT_ASSERT_MESSAGE("green",
1189 tools::rgb2hsv(maGreen
) == BColor(120,1,1));
1190 CPPUNIT_ASSERT_MESSAGE("blue",
1191 tools::rgb2hsv(maBlue
) == BColor(240,1,1));
1192 CPPUNIT_ASSERT_MESSAGE("yellow",
1193 tools::rgb2hsv(maYellow
) == BColor(60,1,1));
1194 CPPUNIT_ASSERT_MESSAGE("magenta",
1195 tools::rgb2hsv(maMagenta
) == BColor(300,1,1));
1196 CPPUNIT_ASSERT_MESSAGE("cyan",
1197 tools::rgb2hsv(maCyan
) == BColor(180,1,1));
1199 CPPUNIT_ASSERT_MESSAGE("roundtrip white",
1200 tools::hsv2rgb(tools::rgb2hsv(maWhite
)) == maWhite
);
1201 CPPUNIT_ASSERT_MESSAGE("roundtrip black",
1202 tools::hsv2rgb(tools::rgb2hsv(maBlack
)) == maBlack
);
1203 CPPUNIT_ASSERT_MESSAGE("roundtrip red",
1204 tools::hsv2rgb(tools::rgb2hsv(maRed
)) == maRed
);
1205 CPPUNIT_ASSERT_MESSAGE("roundtrip green",
1206 tools::hsv2rgb(tools::rgb2hsv(maGreen
)) == maGreen
);
1207 CPPUNIT_ASSERT_MESSAGE("roundtrip blue",
1208 tools::hsv2rgb(tools::rgb2hsv(maBlue
)) == maBlue
);
1209 CPPUNIT_ASSERT_MESSAGE("roundtrip yellow",
1210 tools::hsv2rgb(tools::rgb2hsv(maYellow
)) == maYellow
);
1211 CPPUNIT_ASSERT_MESSAGE("roundtrip magenta",
1212 tools::hsv2rgb(tools::rgb2hsv(maMagenta
)) == maMagenta
);
1213 CPPUNIT_ASSERT_MESSAGE("roundtrip cyan",
1214 tools::hsv2rgb(tools::rgb2hsv(maCyan
)) == maCyan
);
1216 CPPUNIT_ASSERT_MESSAGE("grey10",
1217 tools::rgb2hsv(maWhite
*.1) == BColor(0,0,.1));
1218 CPPUNIT_ASSERT_MESSAGE("grey90",
1219 tools::rgb2hsv(maWhite
*.9) == BColor(0,0,.9));
1220 CPPUNIT_ASSERT_MESSAGE("red/2",
1221 tools::rgb2hsv(maRed
*.5) == BColor(0,1,0.5));
1222 CPPUNIT_ASSERT_MESSAGE("green/2",
1223 tools::rgb2hsv(maGreen
*.5) == BColor(120,1,0.5));
1224 CPPUNIT_ASSERT_MESSAGE("blue/2",
1225 tools::rgb2hsv(maBlue
*.5) == BColor(240,1,0.5));
1226 CPPUNIT_ASSERT_MESSAGE("yellow/2",
1227 tools::rgb2hsv(maYellow
*.5) == BColor(60,1,0.5));
1228 CPPUNIT_ASSERT_MESSAGE("magenta/2",
1229 tools::rgb2hsv(maMagenta
*.5) == BColor(300,1,0.5));
1230 CPPUNIT_ASSERT_MESSAGE("cyan/2",
1231 tools::rgb2hsv(maCyan
*.5) == BColor(180,1,0.5));
1233 CPPUNIT_ASSERT_MESSAGE("pastel",
1234 tools::rgb2hsv(BColor(.5,.25,.25)) == BColor(0,.5,.5));
1239 tools::rgb2ciexyz(maWhite
);
1240 tools::rgb2ciexyz(maBlack
);
1241 tools::rgb2ciexyz(maRed
);
1242 tools::rgb2ciexyz(maGreen
);
1243 tools::rgb2ciexyz(maBlue
);
1244 tools::rgb2ciexyz(maYellow
);
1245 tools::rgb2ciexyz(maMagenta
);
1246 tools::rgb2ciexyz(maCyan
);
1249 // Change the following lines only, if you add, remove or rename
1250 // member functions of the current class,
1251 // because these macros are need by auto register mechanism.
1253 CPPUNIT_TEST_SUITE(bcolor
);
1254 CPPUNIT_TEST(hslTest
);
1255 CPPUNIT_TEST(hsvTest
);
1256 CPPUNIT_TEST(ciexyzTest
);
1257 CPPUNIT_TEST_SUITE_END();
1258 }; // class b2dvector
1260 // -----------------------------------------------------------------------------
1262 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dsvgdimpex
);
1263 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2drange
);
1264 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolyrange
);
1265 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dhommatrix
);
1266 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpoint
);
1267 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygon
);
1268 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygontools
);
1269 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolypolygon
);
1270 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1Xrange
);
1271 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1ibox
);
1272 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2Xrange
);
1273 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2ibox
);
1274 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dtuple
);
1275 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::bcolor
);
1276 } // namespace basegfx2d
1279 // -----------------------------------------------------------------------------
1281 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1282 // to let the user the possibility to also register some functions by hand.
1285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */