Bump version to 24.04.3.4
[LibreOffice.git] / basegfx / test / B2DHomMatrixTest.cxx
blobaace816d3e3a8c2ae913623960931f4eac5ec4b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/numeric/ftools.hxx>
27 #include <basegfx/tuple/b2dtuple.hxx>
28 #include <basegfx/range/b2drange.hxx>
30 namespace basegfx
32 class b2dhommatrix : public CppUnit::TestFixture
34 private:
35 B2DHomMatrix maIdentity;
36 B2DHomMatrix maScale;
37 B2DHomMatrix maTranslate;
38 B2DHomMatrix maShear;
39 B2DHomMatrix maAffine;
40 B2DHomMatrix maPerspective;
42 public:
43 // initialise your test code values here.
44 void setUp() override
46 // setup some test matrices
47 maIdentity.identity(); // force compact layout
48 maIdentity.set(0, 0, 1.0);
49 maIdentity.set(0, 1, 0.0);
50 maIdentity.set(0, 2, 0.0);
51 maIdentity.set(1, 0, 0.0);
52 maIdentity.set(1, 1, 1.0);
53 maIdentity.set(1, 2, 0.0);
55 maScale.identity(); // force compact layout
56 maScale.set(0, 0, 2.0);
57 maScale.set(1, 1, 20.0);
59 maTranslate.identity(); // force compact layout
60 maTranslate.set(0, 2, 20.0);
61 maTranslate.set(1, 2, 2.0);
63 maShear.identity(); // force compact layout
64 maShear.set(0, 1, 3.0);
65 maShear.set(1, 0, 7.0);
66 maShear.set(1, 1, 22.0);
68 maAffine.identity(); // force compact layout
69 maAffine.set(0, 0, 1.0);
70 maAffine.set(0, 1, 2.0);
71 maAffine.set(0, 2, 3.0);
72 maAffine.set(1, 0, 4.0);
73 maAffine.set(1, 1, 5.0);
74 maAffine.set(1, 2, 6.0);
76 maPerspective.set(0, 0, 1.0);
77 maPerspective.set(0, 1, 2.0);
78 maPerspective.set(0, 2, 3.0);
79 maPerspective.set(1, 0, 4.0);
80 maPerspective.set(1, 1, 5.0);
81 maPerspective.set(1, 2, 6.0);
84 void equal()
86 B2DHomMatrix aIdentity;
87 B2DHomMatrix aScale;
88 B2DHomMatrix aTranslate;
89 B2DHomMatrix aShear;
90 B2DHomMatrix aAffine;
91 B2DHomMatrix aPerspective;
93 // setup some test matrices
94 aIdentity.identity(); // force compact layout
95 aIdentity.set(0, 0, 1.0);
96 aIdentity.set(0, 1, 0.0);
97 aIdentity.set(0, 2, 0.0);
98 aIdentity.set(1, 0, 0.0);
99 aIdentity.set(1, 1, 1.0);
100 aIdentity.set(1, 2, 0.0);
102 aScale.identity(); // force compact layout
103 aScale.set(0, 0, 2.0);
104 aScale.set(1, 1, 20.0);
106 aTranslate.identity(); // force compact layout
107 aTranslate.set(0, 2, 20.0);
108 aTranslate.set(1, 2, 2.0);
110 aShear.identity(); // force compact layout
111 aShear.set(0, 1, 3.0);
112 aShear.set(1, 0, 7.0);
113 aShear.set(1, 1, 22.0);
115 aAffine.identity(); // force compact layout
116 aAffine.set(0, 0, 1.0);
117 aAffine.set(0, 1, 2.0);
118 aAffine.set(0, 2, 3.0);
119 aAffine.set(1, 0, 4.0);
120 aAffine.set(1, 1, 5.0);
121 aAffine.set(1, 2, 6.0);
123 aPerspective.set(0, 0, 1.0);
124 aPerspective.set(0, 1, 2.0);
125 aPerspective.set(0, 2, 3.0);
126 aPerspective.set(1, 0, 4.0);
127 aPerspective.set(1, 1, 5.0);
128 aPerspective.set(1, 2, 6.0);
130 CPPUNIT_ASSERT_MESSAGE("operator==: identity matrix", aIdentity.operator==(maIdentity));
131 CPPUNIT_ASSERT_MESSAGE("operator==: scale matrix", aScale.operator==(maScale));
132 CPPUNIT_ASSERT_MESSAGE("operator==: translate matrix", aTranslate.operator==(maTranslate));
133 CPPUNIT_ASSERT_MESSAGE("operator==: shear matrix", aShear.operator==(maShear));
134 CPPUNIT_ASSERT_MESSAGE("operator==: affine matrix", aAffine.operator==(maAffine));
135 CPPUNIT_ASSERT_MESSAGE("operator==: perspective matrix",
136 aPerspective.operator==(maPerspective));
139 void identity()
141 B2DHomMatrix ident;
143 CPPUNIT_ASSERT_EQUAL_MESSAGE("identity", maIdentity, ident);
146 void scale()
148 B2DHomMatrix mat;
149 mat.scale(2.0, 20.0);
150 CPPUNIT_ASSERT_EQUAL_MESSAGE("scale", maScale, mat);
153 void rotate()
155 B2DHomMatrix mat;
156 mat.rotate(M_PI_2);
157 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi/2 yields exact matrix", 0.0, mat.get(0, 0),
158 1E-12);
159 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi/2 yields exact matrix", -1.0, mat.get(0, 1),
160 1E-12);
161 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi/2 yields exact matrix", 0.0, mat.get(0, 2),
162 1E-12);
163 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi/2 yields exact matrix", 1.0, mat.get(1, 0),
164 1E-12);
165 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi/2 yields exact matrix", 0.0, mat.get(1, 1),
166 1E-12);
167 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi/2 yields exact matrix", 0.0, mat.get(1, 2),
168 1E-12);
169 mat.rotate(M_PI_2);
170 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi yields exact matrix", -1.0, mat.get(0, 0),
171 1E-12);
172 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi yields exact matrix", 0.0, mat.get(0, 1),
173 1E-12);
174 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi yields exact matrix", 0.0, mat.get(0, 2),
175 1E-12);
176 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi yields exact matrix", 0.0, mat.get(1, 0),
177 1E-12);
178 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi yields exact matrix", -1.0, mat.get(1, 1),
179 1E-12);
180 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate pi yields exact matrix", 0.0, mat.get(1, 2),
181 1E-12);
182 mat.rotate(M_PI_2);
183 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 3/2 pi yields exact matrix", 0.0,
184 mat.get(0, 0), 1E-12);
185 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 3/2 pi yields exact matrix", 1.0,
186 mat.get(0, 1), 1E-12);
187 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 3/2 pi yields exact matrix", 0.0,
188 mat.get(0, 2), 1E-12);
189 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 3/2 pi yields exact matrix", -1.0,
190 mat.get(1, 0), 1E-12);
191 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 3/2 pi yields exact matrix", 0.0,
192 mat.get(1, 1), 1E-12);
193 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 3/2 pi yields exact matrix", 0.0,
194 mat.get(1, 2), 1E-12);
195 mat.rotate(M_PI_2);
196 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 2 pi yields exact matrix", 1.0, mat.get(0, 0),
197 1E-12);
198 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 2 pi yields exact matrix", 0.0, mat.get(0, 1),
199 1E-12);
200 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 2 pi yields exact matrix", 0.0, mat.get(0, 2),
201 1E-12);
202 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 2 pi yields exact matrix", 0.0, mat.get(1, 0),
203 1E-12);
204 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 2 pi yields exact matrix", 1.0, mat.get(1, 1),
205 1E-12);
206 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("rotate 2 pi yields exact matrix", 0.0, mat.get(1, 2),
207 1E-12);
210 void translate()
212 B2DHomMatrix mat;
213 mat.translate(20.0, 2.0);
214 CPPUNIT_ASSERT_EQUAL_MESSAGE("translate", maTranslate, mat);
217 void shear()
219 B2DHomMatrix mat;
220 mat.shearX(3.0);
221 mat.shearY(7.0);
222 CPPUNIT_ASSERT_EQUAL_MESSAGE("translate", maShear, mat);
225 void multiply()
227 B2DHomMatrix affineAffineProd;
229 affineAffineProd.set(0, 0, 9);
230 affineAffineProd.set(0, 1, 12);
231 affineAffineProd.set(0, 2, 18);
232 affineAffineProd.set(1, 0, 24);
233 affineAffineProd.set(1, 1, 33);
234 affineAffineProd.set(1, 2, 48);
236 B2DHomMatrix temp;
238 temp = maAffine;
239 temp *= maAffine;
240 CPPUNIT_ASSERT_EQUAL_MESSAGE("multiply: both compact", affineAffineProd, temp);
243 void impFillMatrix(B2DHomMatrix& rSource, double fScaleX, double fScaleY, double fShearX,
244 double fRotate) const
246 // fill rSource with a linear combination of scale, shear and rotate
247 rSource.identity();
248 rSource.scale(fScaleX, fScaleY);
249 rSource.shearX(fShearX);
250 rSource.rotate(fRotate);
253 bool impDecomposeComposeTest(double fScaleX, double fScaleY, double fShearX,
254 double fRotate) const
256 // linear combine matrix with given values
257 B2DHomMatrix aSource;
258 impFillMatrix(aSource, fScaleX, fScaleY, fShearX, fRotate);
260 // decompose that matrix
261 B2DTuple aDScale;
262 B2DTuple aDTrans;
263 double fDRot;
264 double fDShX;
265 bool bWorked = aSource.decompose(aDScale, aDTrans, fDRot, fDShX);
267 // linear combine another matrix with decomposition results
268 B2DHomMatrix aRecombined;
269 impFillMatrix(aRecombined, aDScale.getX(), aDScale.getY(), fDShX, fDRot);
271 // if decomposition worked, matrices need to be the same
272 return bWorked && aSource == aRecombined;
275 void decompose()
277 // test matrix decompositions. Each matrix decomposed and rebuilt
278 // using the decompose result should be the same as before. Test
279 // with all ranges of values. Translations are not tested since these
280 // are just the two rightmost values and uncritical
281 static const double fSX(10.0);
282 static const double fSY(12.0);
283 static const double fR(M_PI_4);
284 static const double fS(deg2rad(15.0));
286 // check all possible scaling combinations
287 CPPUNIT_ASSERT_MESSAGE("decompose: error test A1",
288 impDecomposeComposeTest(fSX, fSY, 0.0, 0.0));
289 CPPUNIT_ASSERT_MESSAGE("decompose: error test A2",
290 impDecomposeComposeTest(-fSX, fSY, 0.0, 0.0));
291 CPPUNIT_ASSERT_MESSAGE("decompose: error test A3",
292 impDecomposeComposeTest(fSX, -fSY, 0.0, 0.0));
293 CPPUNIT_ASSERT_MESSAGE("decompose: error test A4",
294 impDecomposeComposeTest(-fSX, -fSY, 0.0, 0.0));
296 // check all possible scaling combinations with positive rotation
297 CPPUNIT_ASSERT_MESSAGE("decompose: error test B1",
298 impDecomposeComposeTest(fSX, fSY, 0.0, fR));
299 CPPUNIT_ASSERT_MESSAGE("decompose: error test B2",
300 impDecomposeComposeTest(-fSX, fSY, 0.0, fR));
301 CPPUNIT_ASSERT_MESSAGE("decompose: error test B3",
302 impDecomposeComposeTest(fSX, -fSY, 0.0, fR));
303 CPPUNIT_ASSERT_MESSAGE("decompose: error test B4",
304 impDecomposeComposeTest(-fSX, -fSY, 0.0, fR));
306 // check all possible scaling combinations with negative rotation
307 CPPUNIT_ASSERT_MESSAGE("decompose: error test C1",
308 impDecomposeComposeTest(fSX, fSY, 0.0, -fR));
309 CPPUNIT_ASSERT_MESSAGE("decompose: error test C2",
310 impDecomposeComposeTest(-fSX, fSY, 0.0, -fR));
311 CPPUNIT_ASSERT_MESSAGE("decompose: error test C3",
312 impDecomposeComposeTest(fSX, -fSY, 0.0, -fR));
313 CPPUNIT_ASSERT_MESSAGE("decompose: error test C4",
314 impDecomposeComposeTest(-fSX, -fSY, 0.0, -fR));
316 // check all possible scaling combinations with positive shear
317 CPPUNIT_ASSERT_MESSAGE("decompose: error test D1",
318 impDecomposeComposeTest(fSX, fSY, tan(fS), 0.0));
319 CPPUNIT_ASSERT_MESSAGE("decompose: error test D2",
320 impDecomposeComposeTest(-fSX, fSY, tan(fS), 0.0));
321 CPPUNIT_ASSERT_MESSAGE("decompose: error test D3",
322 impDecomposeComposeTest(fSX, -fSY, tan(fS), 0.0));
323 CPPUNIT_ASSERT_MESSAGE("decompose: error test D4",
324 impDecomposeComposeTest(-fSX, -fSY, tan(fS), 0.0));
326 // check all possible scaling combinations with negative shear
327 CPPUNIT_ASSERT_MESSAGE("decompose: error test E1",
328 impDecomposeComposeTest(fSX, fSY, tan(-fS), 0.0));
329 CPPUNIT_ASSERT_MESSAGE("decompose: error test E2",
330 impDecomposeComposeTest(-fSX, fSY, tan(-fS), 0.0));
331 CPPUNIT_ASSERT_MESSAGE("decompose: error test E3",
332 impDecomposeComposeTest(fSX, -fSY, tan(-fS), 0.0));
333 CPPUNIT_ASSERT_MESSAGE("decompose: error test E4",
334 impDecomposeComposeTest(-fSX, -fSY, tan(-fS), 0.0));
336 // check all possible scaling combinations with positive rotate and positive shear
337 CPPUNIT_ASSERT_MESSAGE("decompose: error test F1",
338 impDecomposeComposeTest(fSX, fSY, tan(fS), fR));
339 CPPUNIT_ASSERT_MESSAGE("decompose: error test F2",
340 impDecomposeComposeTest(-fSX, fSY, tan(fS), fR));
341 CPPUNIT_ASSERT_MESSAGE("decompose: error test F3",
342 impDecomposeComposeTest(fSX, -fSY, tan(fS), fR));
343 CPPUNIT_ASSERT_MESSAGE("decompose: error test F4",
344 impDecomposeComposeTest(-fSX, -fSY, tan(fS), fR));
346 // check all possible scaling combinations with negative rotate and positive shear
347 CPPUNIT_ASSERT_MESSAGE("decompose: error test G1",
348 impDecomposeComposeTest(fSX, fSY, tan(fS), -fR));
349 CPPUNIT_ASSERT_MESSAGE("decompose: error test G2",
350 impDecomposeComposeTest(-fSX, fSY, tan(fS), -fR));
351 CPPUNIT_ASSERT_MESSAGE("decompose: error test G3",
352 impDecomposeComposeTest(fSX, -fSY, tan(fS), -fR));
353 CPPUNIT_ASSERT_MESSAGE("decompose: error test G4",
354 impDecomposeComposeTest(-fSX, -fSY, tan(fS), -fR));
356 // check all possible scaling combinations with positive rotate and negative shear
357 CPPUNIT_ASSERT_MESSAGE("decompose: error test H1",
358 impDecomposeComposeTest(fSX, fSY, tan(-fS), fR));
359 CPPUNIT_ASSERT_MESSAGE("decompose: error test H2",
360 impDecomposeComposeTest(-fSX, fSY, tan(-fS), fR));
361 CPPUNIT_ASSERT_MESSAGE("decompose: error test H3",
362 impDecomposeComposeTest(fSX, -fSY, tan(-fS), fR));
363 CPPUNIT_ASSERT_MESSAGE("decompose: error test H4",
364 impDecomposeComposeTest(-fSX, -fSY, tan(-fS), fR));
366 // check all possible scaling combinations with negative rotate and negative shear
367 CPPUNIT_ASSERT_MESSAGE("decompose: error test I1",
368 impDecomposeComposeTest(fSX, fSY, tan(-fS), -fR));
369 CPPUNIT_ASSERT_MESSAGE("decompose: error test I2",
370 impDecomposeComposeTest(-fSX, fSY, tan(-fS), -fR));
371 CPPUNIT_ASSERT_MESSAGE("decompose: error test I3",
372 impDecomposeComposeTest(fSX, -fSY, tan(-fS), -fR));
373 CPPUNIT_ASSERT_MESSAGE("decompose: error test I4",
374 impDecomposeComposeTest(-fSX, -fSY, tan(-fS), -fR));
376 // cover special case of 180 degree rotation
377 B2DHomMatrix aTest
378 = utils::createScaleShearXRotateTranslateB2DHomMatrix(6425, 3938, 0, M_PI, 10482, 4921);
379 // decompose that matrix
380 B2DTuple aDScale;
381 B2DTuple aDTrans;
382 double fDRot;
383 double fDShX;
384 aTest.decompose(aDScale, aDTrans, fDRot, fDShX);
385 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 6425.0, aDScale.getX(),
386 1E-12);
387 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 3938.0, aDScale.getY(),
388 1E-12);
389 CPPUNIT_ASSERT_EQUAL_MESSAGE("decompose: error test J1", 10482.0, aDTrans.getX());
390 CPPUNIT_ASSERT_EQUAL_MESSAGE("decompose: error test J1", 4921.0, aDTrans.getY());
391 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", M_PI, fDRot, 1E-12);
394 void testCreate_abcdef()
396 B2DHomMatrix aB2DMatrix(00, 01, 02, 10, 11, 12);
398 CPPUNIT_ASSERT_DOUBLES_EQUAL(00, aB2DMatrix.a(), 1E-12);
399 CPPUNIT_ASSERT_DOUBLES_EQUAL(10, aB2DMatrix.b(), 1E-12);
400 CPPUNIT_ASSERT_DOUBLES_EQUAL(01, aB2DMatrix.c(), 1E-12);
401 CPPUNIT_ASSERT_DOUBLES_EQUAL(11, aB2DMatrix.d(), 1E-12);
402 CPPUNIT_ASSERT_DOUBLES_EQUAL(02, aB2DMatrix.e(), 1E-12);
403 CPPUNIT_ASSERT_DOUBLES_EQUAL(12, aB2DMatrix.f(), 1E-12);
405 CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 0), aB2DMatrix.a(), 1E-12);
406 CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 0), aB2DMatrix.b(), 1E-12);
407 CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 1), aB2DMatrix.c(), 1E-12);
408 CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 1), aB2DMatrix.d(), 1E-12);
409 CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 2), aB2DMatrix.e(), 1E-12);
410 CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 2), aB2DMatrix.f(), 1E-12);
413 void testMultiplyWithAnotherMatrix()
415 B2DHomMatrix aB2DMatrix(00, 01, 02, 10, 11, 12);
416 B2DHomMatrix aNewB2DMatrix = B2DHomMatrix::abcdef(1, 2, 3, 4, 5, 6);
418 aB2DMatrix *= aNewB2DMatrix;
420 CPPUNIT_ASSERT_DOUBLES_EQUAL(30, aB2DMatrix.get(0, 0), 1E-12);
421 CPPUNIT_ASSERT_DOUBLES_EQUAL(40, aB2DMatrix.get(1, 0), 1E-12);
422 CPPUNIT_ASSERT_DOUBLES_EQUAL(34, aB2DMatrix.get(0, 1), 1E-12);
423 CPPUNIT_ASSERT_DOUBLES_EQUAL(46, aB2DMatrix.get(1, 1), 1E-12);
424 CPPUNIT_ASSERT_DOUBLES_EQUAL(43, aB2DMatrix.get(0, 2), 1E-12);
425 CPPUNIT_ASSERT_DOUBLES_EQUAL(58, aB2DMatrix.get(1, 2), 1E-12);
428 void testTransformPoint()
430 B2DHomMatrix aNewB2DMatrix = B2DHomMatrix::abcdef(1, 2, 3, 4, 5, 6);
432 B2DPoint aPoint(1, 2);
433 aPoint *= aNewB2DMatrix;
435 CPPUNIT_ASSERT_DOUBLES_EQUAL(12, aPoint.getX(), 1E-12);
436 CPPUNIT_ASSERT_DOUBLES_EQUAL(16, aPoint.getY(), 1E-12);
439 void testTransformRange()
441 B2DHomMatrix aNewB2DMatrix = B2DHomMatrix::abcdef(1, 2, 3, 4, 5, 6);
443 B2DRange aRange(2, 1, 4, 3);
444 aRange *= aNewB2DMatrix;
446 CPPUNIT_ASSERT_DOUBLES_EQUAL(10, aRange.getMinX(), 1E-12);
447 CPPUNIT_ASSERT_DOUBLES_EQUAL(18, aRange.getMaxX(), 1E-12);
448 CPPUNIT_ASSERT_DOUBLES_EQUAL(14, aRange.getMinY(), 1E-12);
449 CPPUNIT_ASSERT_DOUBLES_EQUAL(26, aRange.getMaxY(), 1E-12);
452 void testCoordinateSystemConversion()
454 // Use case when we convert
456 B2DRange aWindow(50, 50, 150, 150);
458 B2DRange aSubPage(0, 0, 2000, 2000);
460 B2DHomMatrix aB2DMatrix;
461 aB2DMatrix.scale(aWindow.getWidth() / aSubPage.getWidth(),
462 aWindow.getHeight() / aSubPage.getHeight());
463 aB2DMatrix.translate(aWindow.getMinX(), aWindow.getMinY());
465 B2DPoint aPoint1(0, 0);
466 aPoint1 *= aB2DMatrix;
468 CPPUNIT_ASSERT_DOUBLES_EQUAL(50, aPoint1.getX(), 1E-12);
469 CPPUNIT_ASSERT_DOUBLES_EQUAL(50, aPoint1.getY(), 1E-12);
471 B2DPoint aPoint2(1000, 1000);
472 aPoint2 *= aB2DMatrix;
473 CPPUNIT_ASSERT_DOUBLES_EQUAL(100, aPoint2.getX(), 1E-12);
474 CPPUNIT_ASSERT_DOUBLES_EQUAL(100, aPoint2.getY(), 1E-12);
476 B2DPoint aPoint3(2000, 2000);
477 aPoint3 *= aB2DMatrix;
478 CPPUNIT_ASSERT_DOUBLES_EQUAL(150, aPoint3.getX(), 1E-12);
479 CPPUNIT_ASSERT_DOUBLES_EQUAL(150, aPoint3.getY(), 1E-12);
482 // Change the following lines only, if you add, remove or rename
483 // member functions of the current class,
484 // because these macros are need by auto register mechanism.
486 CPPUNIT_TEST_SUITE(b2dhommatrix);
487 CPPUNIT_TEST(equal);
488 CPPUNIT_TEST(identity);
489 CPPUNIT_TEST(scale);
490 CPPUNIT_TEST(translate);
491 CPPUNIT_TEST(rotate);
492 CPPUNIT_TEST(shear);
493 CPPUNIT_TEST(multiply);
494 CPPUNIT_TEST(decompose);
495 CPPUNIT_TEST(testCreate_abcdef);
496 CPPUNIT_TEST(testMultiplyWithAnotherMatrix);
497 CPPUNIT_TEST(testTransformPoint);
498 CPPUNIT_TEST(testTransformRange);
499 CPPUNIT_TEST(testCoordinateSystemConversion);
501 CPPUNIT_TEST_SUITE_END();
503 }; // class b2dhommatrix
506 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b2dhommatrix);
508 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */