Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: tests/Matrix44Test.cpp

Issue 22886010: Add perf benchmarks and more unit tests for matrix inversion (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bench/Matrix44Bench.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkMatrix44.h" 9 #include "SkMatrix44.h"
10 10
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 d.set(0, 0, 8); 312 d.set(0, 0, 8);
313 REPORTER_ASSERT(reporter, nearly_equal_double(16, d.determinant())); 313 REPORTER_ASSERT(reporter, nearly_equal_double(16, d.determinant()));
314 314
315 SkMatrix44 e = a; 315 SkMatrix44 e = a;
316 e.postConcat(d); 316 e.postConcat(d);
317 REPORTER_ASSERT(reporter, nearly_equal_double(32, e.determinant())); 317 REPORTER_ASSERT(reporter, nearly_equal_double(32, e.determinant()));
318 e.set(0, 0, 0); 318 e.set(0, 0, 0);
319 REPORTER_ASSERT(reporter, nearly_equal_double(0, e.determinant())); 319 REPORTER_ASSERT(reporter, nearly_equal_double(0, e.determinant()));
320 } 320 }
321 321
322 static void test_invert(skiatest::Reporter* reporter) {
323 SkMatrix44 inverse;
324 double inverseData[16];
325
326 SkMatrix44 identity;
327 identity.setIdentity();
328 identity.invert(&inverse);
329 inverse.asRowMajord(inverseData);
330 assert16<double>(reporter, inverseData,
331 1, 0, 0, 0,
332 0, 1, 0, 0,
333 0, 0, 1, 0,
334 0, 0, 0, 1);
335
336 SkMatrix44 translation;
337 translation.setTranslate(2, 3, 4);
338 translation.invert(&inverse);
339 inverse.asRowMajord(inverseData);
340 assert16<double>(reporter, inverseData,
341 1, 0, 0, -2,
342 0, 1, 0, -3,
343 0, 0, 1, -4,
344 0, 0, 0, 1);
345
346 SkMatrix44 scale;
347 scale.setScale(2, 4, 8);
348 scale.invert(&inverse);
349 inverse.asRowMajord(inverseData);
350 assert16<double>(reporter, inverseData,
351 0.5, 0, 0, 0,
352 0, 0.25, 0, 0,
353 0, 0, 0.125, 0,
354 0, 0, 0, 1);
355
356 SkMatrix44 scaleTranslation;
357 scaleTranslation.setScale(10, 100, 1000);
358 scaleTranslation.preTranslate(2, 3, 4);
359 scaleTranslation.invert(&inverse);
360 inverse.asRowMajord(inverseData);
361 assert16<double>(reporter, inverseData,
362 0.1, 0, 0, -2,
363 0, 0.01, 0, -3,
364 0, 0, 0.001, -4,
365 0, 0, 0, 1);
366
367 SkMatrix44 rotation;
368 rotation.setRotateDegreesAbout(0, 0, 1, 90);
369 rotation.invert(&inverse);
370 SkMatrix44 expected;
371 double expectedInverseRotation[16] =
372 {0, 1, 0, 0,
373 -1, 0, 0, 0,
374 0, 0, 1, 0,
375 0, 0, 0, 1};
376 expected.setRowMajord(expectedInverseRotation);
377 REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
378
379 SkMatrix44 affine;
380 affine.setRotateDegreesAbout(0, 0, 1, 90);
381 affine.preScale(10, 20, 100);
382 affine.preTranslate(2, 3, 4);
383 affine.invert(&inverse);
384 double expectedInverseAffine[16] =
385 {0, 0.1, 0, -2,
386 -0.05, 0, 0, -3,
387 0, 0, 0.01, -4,
388 0, 0, 0, 1};
389 expected.setRowMajord(expectedInverseAffine);
390 REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
391
392 SkMatrix44 perspective;
393 perspective.setIdentity();
394 perspective.setDouble(3, 2, 1.0);
395 perspective.invert(&inverse);
396 double expectedInversePerspective[16] =
397 {1, 0, 0, 0,
398 0, 1, 0, 0,
399 0, 0, 1, 0,
400 0, 0, -1, 1};
401 expected.setRowMajord(expectedInversePerspective);
402 REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
403
404 SkMatrix44 affineAndPerspective;
405 affineAndPerspective.setIdentity();
406 affineAndPerspective.setDouble(3, 2, 1.0);
407 affineAndPerspective.preScale(10, 20, 100);
408 affineAndPerspective.preTranslate(2, 3, 4);
409 affineAndPerspective.invert(&inverse);
410 double expectedInverseAffineAndPerspective[16] =
411 {0.1, 0, 2, -2,
412 0, 0.05, 3, -3,
413 0, 0, 4.01, -4,
414 0, 0, -1, 1};
415 expected.setRowMajord(expectedInverseAffineAndPerspective);
416 REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
417 }
418
322 static void test_transpose(skiatest::Reporter* reporter) { 419 static void test_transpose(skiatest::Reporter* reporter) {
323 SkMatrix44 a; 420 SkMatrix44 a;
324 SkMatrix44 b; 421 SkMatrix44 b;
325 422
326 int i = 0; 423 int i = 0;
327 for (int row = 0; row < 4; ++row) { 424 for (int row = 0; row < 4; ++row) {
328 for (int col = 0; col < 4; ++col) { 425 for (int col = 0; col < 4; ++col) {
329 a.setDouble(row, col, i); 426 a.setDouble(row, col, i);
330 b.setDouble(col, row, i++); 427 b.setDouble(col, row, i++);
331 } 428 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 531
435 test_concat(reporter); 532 test_concat(reporter);
436 533
437 if (false) { // avoid bit rot, suppress warning (working on making this pass ) 534 if (false) { // avoid bit rot, suppress warning (working on making this pass )
438 test_common_angles(reporter); 535 test_common_angles(reporter);
439 } 536 }
440 537
441 test_constructor(reporter); 538 test_constructor(reporter);
442 test_gettype(reporter); 539 test_gettype(reporter);
443 test_determinant(reporter); 540 test_determinant(reporter);
541 test_invert(reporter);
444 test_transpose(reporter); 542 test_transpose(reporter);
445 test_get_set_double(reporter); 543 test_get_set_double(reporter);
446 test_set_row_col_major(reporter); 544 test_set_row_col_major(reporter);
447 test_translate(reporter); 545 test_translate(reporter);
448 test_scale(reporter); 546 test_scale(reporter);
449 test_map2(reporter); 547 test_map2(reporter);
450 } 548 }
451 549
452 #include "TestClassDef.h" 550 #include "TestClassDef.h"
453 DEFINE_TESTCLASS("Matrix44", Matrix44TestClass, TestMatrix44) 551 DEFINE_TESTCLASS("Matrix44", Matrix44TestClass, TestMatrix44)
OLDNEW
« no previous file with comments | « bench/Matrix44Bench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698