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

Side by Side Diff: tests/Matrix44Test.cpp

Issue 25484006: Add perspective support to SkMatrix44 initializers. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add test and header comments Created 7 years, 2 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
« include/utils/SkMatrix44.h ('K') | « src/utils/SkMatrix44.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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 b.transpose(); 464 b.transpose();
465 REPORTER_ASSERT(reporter, nearly_equal(a, b)); 465 REPORTER_ASSERT(reporter, nearly_equal(a, b));
466 a.asColMajorf(bufferf); 466 a.asColMajorf(bufferf);
467 b.setColMajorf(bufferf); 467 b.setColMajorf(bufferf);
468 REPORTER_ASSERT(reporter, nearly_equal(a, b)); 468 REPORTER_ASSERT(reporter, nearly_equal(a, b));
469 b.setRowMajorf(bufferf); 469 b.setRowMajorf(bufferf);
470 b.transpose(); 470 b.transpose();
471 REPORTER_ASSERT(reporter, nearly_equal(a, b)); 471 REPORTER_ASSERT(reporter, nearly_equal(a, b));
472 } 472 }
473 473
474 static void test_3x3_conversion(skiatest::Reporter* reporter) {
475 SkMScalar values4x4[16] = { 1, 2, 3, 4,
476 5, 6, 7, 8,
477 9, 10, 11, 12,
478 13, 14, 15, 16 };
479 SkMScalar values3x3[9] = { 1, 2, 4,
480 5, 6, 8,
481 13, 14, 16 };
482 SkMScalar values4x4flattened[16] = { 1, 2, 0, 4,
483 5, 6, 0, 8,
484 0, 0, 1, 0,
485 13, 14, 0, 16 };
486 SkMatrix44 a44;
487 a44.setRowMajor(values4x4);
488
489 SkMatrix a33 = a44;
490 SkMatrix expected33;
491 for (int i = 0; i < 9; i++) expected33[i] = values3x3[i];
492 REPORTER_ASSERT(reporter, expected33 == a33);
493
494 SkMatrix44 a44flattened = a33;
495 SkMatrix44 expected44flattened;
496 expected44flattened.setRowMajor(values4x4flattened);
497 REPORTER_ASSERT(reporter, nearly_equal(a44flattened, expected44flattened));
498
499 // Test that a point with a Z value of 0 is transformed the same way.
500 SkScalar vec4[4] = { 2, 4, 0, 8 };
501 SkScalar vec3[3] = { 2, 4, 8 };
502
503 SkScalar vec4transformed[4];
504 SkScalar vec3transformed[3];
505 SkScalar vec4transformed2[4];
506 a44.mapScalars(vec4, vec4transformed);
507 a33.mapHomogeneousPoints(vec3transformed, vec3, 1);
508 a44flattened.mapScalars(vec4, vec4transformed2);
509 REPORTER_ASSERT(reporter, vec4transformed[0] == vec3transformed[0]);
510 REPORTER_ASSERT(reporter, vec4transformed[1] == vec3transformed[1]);
511 REPORTER_ASSERT(reporter, vec4transformed[3] == vec3transformed[2]);
512 REPORTER_ASSERT(reporter, vec4transformed[0] == vec4transformed2[0]);
513 REPORTER_ASSERT(reporter, vec4transformed[1] == vec4transformed2[1]);
514 REPORTER_ASSERT(reporter, vec4transformed[2] != vec4transformed2[2]);
515 REPORTER_ASSERT(reporter, vec4transformed[3] == vec4transformed2[3]);
516 }
517
474 static void TestMatrix44(skiatest::Reporter* reporter) { 518 static void TestMatrix44(skiatest::Reporter* reporter) {
475 SkMatrix44 mat, inverse, iden1, iden2, rot; 519 SkMatrix44 mat, inverse, iden1, iden2, rot;
476 520
477 mat.reset(); 521 mat.reset();
478 mat.setTranslate(1, 1, 1); 522 mat.setTranslate(1, 1, 1);
479 mat.invert(&inverse); 523 mat.invert(&inverse);
480 iden1.setConcat(mat, inverse); 524 iden1.setConcat(mat, inverse);
481 REPORTER_ASSERT(reporter, is_identity(iden1)); 525 REPORTER_ASSERT(reporter, is_identity(iden1));
482 526
483 mat.setScale(2, 2, 2); 527 mat.setScale(2, 2, 2);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 test_constructor(reporter); 609 test_constructor(reporter);
566 test_gettype(reporter); 610 test_gettype(reporter);
567 test_determinant(reporter); 611 test_determinant(reporter);
568 test_invert(reporter); 612 test_invert(reporter);
569 test_transpose(reporter); 613 test_transpose(reporter);
570 test_get_set_double(reporter); 614 test_get_set_double(reporter);
571 test_set_row_col_major(reporter); 615 test_set_row_col_major(reporter);
572 test_translate(reporter); 616 test_translate(reporter);
573 test_scale(reporter); 617 test_scale(reporter);
574 test_map2(reporter); 618 test_map2(reporter);
619 test_3x3_conversion(reporter);
575 } 620 }
576 621
577 #include "TestClassDef.h" 622 #include "TestClassDef.h"
578 DEFINE_TESTCLASS("Matrix44", Matrix44TestClass, TestMatrix44) 623 DEFINE_TESTCLASS("Matrix44", Matrix44TestClass, TestMatrix44)
OLDNEW
« include/utils/SkMatrix44.h ('K') | « src/utils/SkMatrix44.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698