OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/math_util.h" | 5 #include "cc/math_util.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 EXPECT_ROW1_EQ(10, 14, 18, 22, B); | 324 EXPECT_ROW1_EQ(10, 14, 18, 22, B); |
325 EXPECT_ROW2_EQ(11, 15, 19, 23, B); | 325 EXPECT_ROW2_EQ(11, 15, 19, 23, B); |
326 EXPECT_ROW3_EQ(12, 16, 20, 24, B); | 326 EXPECT_ROW3_EQ(12, 16, 20, 24, B); |
327 EXPECT_ROW4_EQ(13, 17, 21, 25, B); | 327 EXPECT_ROW4_EQ(13, 17, 21, 25, B); |
328 } | 328 } |
329 | 329 |
330 TEST(MathUtilGfxTransformTest, verifyMatrixInversion) | 330 TEST(MathUtilGfxTransformTest, verifyMatrixInversion) |
331 { | 331 { |
332 // Invert a translation | 332 // Invert a translation |
333 gfx::Transform translation; | 333 gfx::Transform translation; |
334 translation.PreconcatTranslate3d(2, 3, 4); | 334 translation.Translate3d(2, 3, 4); |
335 EXPECT_TRUE(MathUtil::isInvertible(translation)); | 335 EXPECT_TRUE(MathUtil::isInvertible(translation)); |
336 | 336 |
337 gfx::Transform inverseTranslation = MathUtil::inverse(translation); | 337 gfx::Transform inverseTranslation = MathUtil::inverse(translation); |
338 EXPECT_ROW1_EQ(1, 0, 0, -2, inverseTranslation); | 338 EXPECT_ROW1_EQ(1, 0, 0, -2, inverseTranslation); |
339 EXPECT_ROW2_EQ(0, 1, 0, -3, inverseTranslation); | 339 EXPECT_ROW2_EQ(0, 1, 0, -3, inverseTranslation); |
340 EXPECT_ROW3_EQ(0, 0, 1, -4, inverseTranslation); | 340 EXPECT_ROW3_EQ(0, 0, 1, -4, inverseTranslation); |
341 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseTranslation); | 341 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseTranslation); |
342 | 342 |
343 // Note that inversion should not have changed the original matrix. | 343 // Note that inversion should not have changed the original matrix. |
344 EXPECT_ROW1_EQ(1, 0, 0, 2, translation); | 344 EXPECT_ROW1_EQ(1, 0, 0, 2, translation); |
345 EXPECT_ROW2_EQ(0, 1, 0, 3, translation); | 345 EXPECT_ROW2_EQ(0, 1, 0, 3, translation); |
346 EXPECT_ROW3_EQ(0, 0, 1, 4, translation); | 346 EXPECT_ROW3_EQ(0, 0, 1, 4, translation); |
347 EXPECT_ROW4_EQ(0, 0, 0, 1, translation); | 347 EXPECT_ROW4_EQ(0, 0, 0, 1, translation); |
348 | 348 |
349 // Invert a non-uniform scale | 349 // Invert a non-uniform scale |
350 gfx::Transform scale; | 350 gfx::Transform scale; |
351 scale.PreconcatScale3d(4, 10, 100); | 351 scale.Scale3d(4, 10, 100); |
352 EXPECT_TRUE(MathUtil::isInvertible(scale)); | 352 EXPECT_TRUE(MathUtil::isInvertible(scale)); |
353 | 353 |
354 gfx::Transform inverseScale = MathUtil::inverse(scale); | 354 gfx::Transform inverseScale = MathUtil::inverse(scale); |
355 EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverseScale); | 355 EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverseScale); |
356 EXPECT_ROW2_EQ(0, .1f, 0, 0, inverseScale); | 356 EXPECT_ROW2_EQ(0, .1f, 0, 0, inverseScale); |
357 EXPECT_ROW3_EQ(0, 0, .01f, 0, inverseScale); | 357 EXPECT_ROW3_EQ(0, 0, .01f, 0, inverseScale); |
358 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseScale); | 358 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseScale); |
359 | 359 |
360 // Try to invert a matrix that is not invertible. | 360 // Try to invert a matrix that is not invertible. |
361 // The inverse() function should simply return an identity matrix. | 361 // The inverse() function should simply return an identity matrix. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 gfx::Transform C = A * B; | 505 gfx::Transform C = A * B; |
506 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, C); | 506 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, C); |
507 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, C); | 507 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, C); |
508 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, C); | 508 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, C); |
509 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, C); | 509 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, C); |
510 | 510 |
511 // Just an additional sanity check; matrix multiplication is not commutative
. | 511 // Just an additional sanity check; matrix multiplication is not commutative
. |
512 EXPECT_FALSE(A * B == B * A); | 512 EXPECT_FALSE(A * B == B * A); |
513 } | 513 } |
514 | 514 |
| 515 TEST(MathUtilGfxTransformTest, verifyMultiplyAndAssignOperator) |
| 516 { |
| 517 gfx::Transform A; |
| 518 initializeTestMatrix(&A); |
| 519 |
| 520 gfx::Transform B; |
| 521 initializeTestMatrix2(&B); |
| 522 |
| 523 A *= B; |
| 524 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A); |
| 525 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, A); |
| 526 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, A); |
| 527 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, A); |
| 528 |
| 529 // Just an additional sanity check; matrix multiplication is not commutative
. |
| 530 gfx::Transform C = A; |
| 531 C *= B; |
| 532 gfx::Transform D = B; |
| 533 D *= A; |
| 534 EXPECT_FALSE(C == D); |
| 535 } |
| 536 |
515 TEST(MathUtilGfxTransformTest, verifyMatrixMultiplication) | 537 TEST(MathUtilGfxTransformTest, verifyMatrixMultiplication) |
516 { | 538 { |
517 gfx::Transform A; | 539 gfx::Transform A; |
518 initializeTestMatrix(&A); | 540 initializeTestMatrix(&A); |
519 | 541 |
520 gfx::Transform B; | 542 gfx::Transform B; |
521 initializeTestMatrix2(&B); | 543 initializeTestMatrix2(&B); |
522 | 544 |
523 A.PreconcatTransform(B); | 545 A.PreconcatTransform(B); |
524 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A); | 546 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A); |
(...skipping 10 matching lines...) Expand all Loading... |
535 EXPECT_ROW1_EQ(1, 0, 0, 0, A); | 557 EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
536 EXPECT_ROW2_EQ(0, 1, 0, 0, A); | 558 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
537 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 559 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
538 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 560 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
539 EXPECT_TRUE(MathUtil::isIdentity(A)); | 561 EXPECT_TRUE(MathUtil::isIdentity(A)); |
540 } | 562 } |
541 | 563 |
542 TEST(MathUtilGfxTransformTest, verifyTranslate) | 564 TEST(MathUtilGfxTransformTest, verifyTranslate) |
543 { | 565 { |
544 gfx::Transform A; | 566 gfx::Transform A; |
545 A.PreconcatTranslate(2, 3); | 567 A.Translate(2, 3); |
546 EXPECT_ROW1_EQ(1, 0, 0, 2, A); | 568 EXPECT_ROW1_EQ(1, 0, 0, 2, A); |
547 EXPECT_ROW2_EQ(0, 1, 0, 3, A); | 569 EXPECT_ROW2_EQ(0, 1, 0, 3, A); |
548 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 570 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
549 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 571 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
550 | 572 |
551 // Verify that PreconcatTranslate() post-multiplies the existing matrix. | 573 // Verify that Translate() post-multiplies the existing matrix. |
552 MathUtil::makeIdentity(&A); | 574 MathUtil::makeIdentity(&A); |
553 A.PreconcatScale(5, 5); | 575 A.Scale(5, 5); |
554 A.PreconcatTranslate(2, 3); | 576 A.Translate(2, 3); |
555 EXPECT_ROW1_EQ(5, 0, 0, 10, A); | 577 EXPECT_ROW1_EQ(5, 0, 0, 10, A); |
556 EXPECT_ROW2_EQ(0, 5, 0, 15, A); | 578 EXPECT_ROW2_EQ(0, 5, 0, 15, A); |
557 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 579 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
558 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 580 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
559 } | 581 } |
560 | 582 |
561 TEST(MathUtilGfxTransformTest, verifyTranslate3d) | 583 TEST(MathUtilGfxTransformTest, verifyTranslate3d) |
562 { | 584 { |
563 gfx::Transform A; | 585 gfx::Transform A; |
564 A.PreconcatTranslate3d(2, 3, 4); | 586 A.Translate3d(2, 3, 4); |
565 EXPECT_ROW1_EQ(1, 0, 0, 2, A); | 587 EXPECT_ROW1_EQ(1, 0, 0, 2, A); |
566 EXPECT_ROW2_EQ(0, 1, 0, 3, A); | 588 EXPECT_ROW2_EQ(0, 1, 0, 3, A); |
567 EXPECT_ROW3_EQ(0, 0, 1, 4, A); | 589 EXPECT_ROW3_EQ(0, 0, 1, 4, A); |
568 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 590 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
569 | 591 |
570 // Verify that PreconcatTranslate3d() post-multiplies the existing matrix. | 592 // Verify that Translate3d() post-multiplies the existing matrix. |
571 MathUtil::makeIdentity(&A); | 593 MathUtil::makeIdentity(&A); |
572 A.PreconcatScale3d(6, 7, 8); | 594 A.Scale3d(6, 7, 8); |
573 A.PreconcatTranslate3d(2, 3, 4); | 595 A.Translate3d(2, 3, 4); |
574 EXPECT_ROW1_EQ(6, 0, 0, 12, A); | 596 EXPECT_ROW1_EQ(6, 0, 0, 12, A); |
575 EXPECT_ROW2_EQ(0, 7, 0, 21, A); | 597 EXPECT_ROW2_EQ(0, 7, 0, 21, A); |
576 EXPECT_ROW3_EQ(0, 0, 8, 32, A); | 598 EXPECT_ROW3_EQ(0, 0, 8, 32, A); |
577 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 599 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
578 } | 600 } |
579 | 601 |
580 TEST(MathUtilGfxTransformTest, verifyScale) | 602 TEST(MathUtilGfxTransformTest, verifyScale) |
581 { | 603 { |
582 gfx::Transform A; | 604 gfx::Transform A; |
583 A.PreconcatScale(6, 7); | 605 A.Scale(6, 7); |
584 EXPECT_ROW1_EQ(6, 0, 0, 0, A); | 606 EXPECT_ROW1_EQ(6, 0, 0, 0, A); |
585 EXPECT_ROW2_EQ(0, 7, 0, 0, A); | 607 EXPECT_ROW2_EQ(0, 7, 0, 0, A); |
586 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 608 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
587 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 609 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
588 | 610 |
589 // Verify that PreconcatScale() post-multiplies the existing matrix. | 611 // Verify that Scale() post-multiplies the existing matrix. |
590 MathUtil::makeIdentity(&A); | 612 MathUtil::makeIdentity(&A); |
591 A.PreconcatTranslate3d(2, 3, 4); | 613 A.Translate3d(2, 3, 4); |
592 A.PreconcatScale(6, 7); | 614 A.Scale(6, 7); |
593 EXPECT_ROW1_EQ(6, 0, 0, 2, A); | 615 EXPECT_ROW1_EQ(6, 0, 0, 2, A); |
594 EXPECT_ROW2_EQ(0, 7, 0, 3, A); | 616 EXPECT_ROW2_EQ(0, 7, 0, 3, A); |
595 EXPECT_ROW3_EQ(0, 0, 1, 4, A); | 617 EXPECT_ROW3_EQ(0, 0, 1, 4, A); |
596 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 618 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
597 } | 619 } |
598 | 620 |
599 TEST(MathUtilGfxTransformTest, verifyScale3d) | 621 TEST(MathUtilGfxTransformTest, verifyScale3d) |
600 { | 622 { |
601 gfx::Transform A; | 623 gfx::Transform A; |
602 A.PreconcatScale3d(6, 7, 8); | 624 A.Scale3d(6, 7, 8); |
603 EXPECT_ROW1_EQ(6, 0, 0, 0, A); | 625 EXPECT_ROW1_EQ(6, 0, 0, 0, A); |
604 EXPECT_ROW2_EQ(0, 7, 0, 0, A); | 626 EXPECT_ROW2_EQ(0, 7, 0, 0, A); |
605 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 627 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
606 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 628 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
607 | 629 |
608 // Verify that scale3d() post-multiplies the existing matrix. | 630 // Verify that scale3d() post-multiplies the existing matrix. |
609 MathUtil::makeIdentity(&A); | 631 MathUtil::makeIdentity(&A); |
610 A.PreconcatTranslate3d(2, 3, 4); | 632 A.Translate3d(2, 3, 4); |
611 A.PreconcatScale3d(6, 7, 8); | 633 A.Scale3d(6, 7, 8); |
612 EXPECT_ROW1_EQ(6, 0, 0, 2, A); | 634 EXPECT_ROW1_EQ(6, 0, 0, 2, A); |
613 EXPECT_ROW2_EQ(0, 7, 0, 3, A); | 635 EXPECT_ROW2_EQ(0, 7, 0, 3, A); |
614 EXPECT_ROW3_EQ(0, 0, 8, 4, A); | 636 EXPECT_ROW3_EQ(0, 0, 8, 4, A); |
615 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 637 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
616 } | 638 } |
617 | 639 |
618 TEST(MathUtilGfxTransformTest, verifyRotate) | 640 TEST(MathUtilGfxTransformTest, verifyRotate) |
619 { | 641 { |
620 gfx::Transform A; | 642 gfx::Transform A; |
621 A.PreconcatRotate(90); | 643 A.Rotate(90); |
622 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); | 644 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); |
623 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); | 645 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); |
624 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 646 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
625 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 647 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
626 | 648 |
627 // Verify that PreconcatRotate() post-multiplies the existing matrix. | 649 // Verify that Rotate() post-multiplies the existing matrix. |
628 MathUtil::makeIdentity(&A); | 650 MathUtil::makeIdentity(&A); |
629 A.PreconcatScale3d(6, 7, 8); | 651 A.Scale3d(6, 7, 8); |
630 A.PreconcatRotate(90); | 652 A.Rotate(90); |
631 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); | 653 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); |
632 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); | 654 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); |
633 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 655 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
634 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 656 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
635 } | 657 } |
636 | 658 |
637 TEST(MathUtilGfxTransformTest, verifyRotateEulerAngles) | 659 TEST(MathUtilGfxTransformTest, verifyRotateEulerAngles) |
638 { | 660 { |
639 gfx::Transform A; | 661 gfx::Transform A; |
640 | 662 |
(...skipping 17 matching lines...) Expand all Loading... |
658 // Note carefully, the expected pattern is inverted compared to rotating abo
ut x axis or z axis. | 680 // Note carefully, the expected pattern is inverted compared to rotating abo
ut x axis or z axis. |
659 MathUtil::makeIdentity(&A); | 681 MathUtil::makeIdentity(&A); |
660 MathUtil::rotateEulerAngles(&A, 0, 90, 0); | 682 MathUtil::rotateEulerAngles(&A, 0, 90, 0); |
661 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); | 683 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); |
662 EXPECT_ROW2_EQ(0, 1, 0, 0, A); | 684 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
663 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); | 685 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); |
664 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 686 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
665 | 687 |
666 // Verify that rotate3d(rx, ry, rz) post-multiplies the existing matrix. | 688 // Verify that rotate3d(rx, ry, rz) post-multiplies the existing matrix. |
667 MathUtil::makeIdentity(&A); | 689 MathUtil::makeIdentity(&A); |
668 A.PreconcatScale3d(6, 7, 8); | 690 A.Scale3d(6, 7, 8); |
669 MathUtil::rotateEulerAngles(&A, 0, 0, 90); | 691 MathUtil::rotateEulerAngles(&A, 0, 0, 90); |
670 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); | 692 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); |
671 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); | 693 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); |
672 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 694 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
673 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 695 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
674 } | 696 } |
675 | 697 |
676 TEST(MathUtilGfxTransformTest, verifyRotateEulerAnglesOrderOfCompositeRotations) | 698 TEST(MathUtilGfxTransformTest, verifyRotateEulerAnglesOrderOfCompositeRotations) |
677 { | 699 { |
678 // Rotate3d(degreesX, degreesY, degreesZ) is actually composite transform co
nsiting of | 700 // Rotate3d(degreesX, degreesY, degreesZ) is actually composite transform co
nsiting of |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 // Note carefully, the expected pattern is inverted compared to rotating abo
ut x axis or z axis. | 753 // Note carefully, the expected pattern is inverted compared to rotating abo
ut x axis or z axis. |
732 MathUtil::makeIdentity(&A); | 754 MathUtil::makeIdentity(&A); |
733 MathUtil::rotateAxisAngle(&A, 0, 1, 0, 90); | 755 MathUtil::rotateAxisAngle(&A, 0, 1, 0, 90); |
734 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); | 756 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); |
735 EXPECT_ROW2_EQ(0, 1, 0, 0, A); | 757 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
736 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); | 758 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); |
737 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 759 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
738 | 760 |
739 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix. | 761 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix. |
740 MathUtil::makeIdentity(&A); | 762 MathUtil::makeIdentity(&A); |
741 A.PreconcatScale3d(6, 7, 8); | 763 A.Scale3d(6, 7, 8); |
742 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); | 764 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); |
743 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); | 765 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); |
744 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); | 766 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); |
745 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 767 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
746 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 768 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
747 } | 769 } |
748 | 770 |
749 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis) | 771 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis) |
750 { | 772 { |
751 // Check rotation about an arbitrary non-axis-aligned vector. | 773 // Check rotation about an arbitrary non-axis-aligned vector. |
(...skipping 30 matching lines...) Expand all Loading... |
782 // Verify that A remains unchanged. | 804 // Verify that A remains unchanged. |
783 EXPECT_ROW1_EQ(10, 14, 18, 22, A); | 805 EXPECT_ROW1_EQ(10, 14, 18, 22, A); |
784 EXPECT_ROW2_EQ(11, 15, 19, 23, A); | 806 EXPECT_ROW2_EQ(11, 15, 19, 23, A); |
785 EXPECT_ROW3_EQ(12, 16, 20, 24, A); | 807 EXPECT_ROW3_EQ(12, 16, 20, 24, A); |
786 EXPECT_ROW4_EQ(13, 17, 21, 25, A); | 808 EXPECT_ROW4_EQ(13, 17, 21, 25, A); |
787 } | 809 } |
788 | 810 |
789 TEST(MathUtilGfxTransformTest, verifySkewX) | 811 TEST(MathUtilGfxTransformTest, verifySkewX) |
790 { | 812 { |
791 gfx::Transform A; | 813 gfx::Transform A; |
792 A.PreconcatSkewX(45); | 814 A.SkewX(45); |
793 EXPECT_ROW1_EQ(1, 1, 0, 0, A); | 815 EXPECT_ROW1_EQ(1, 1, 0, 0, A); |
794 EXPECT_ROW2_EQ(0, 1, 0, 0, A); | 816 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
795 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 817 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
796 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 818 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
797 | 819 |
798 // Verify that skewX() post-multiplies the existing matrix. | 820 // Verify that skewX() post-multiplies the existing matrix. |
799 // Row 1, column 2, would incorrectly have value "7" if the matrix is pre-mu
ltiplied instead of post-multiplied. | 821 // Row 1, column 2, would incorrectly have value "7" if the matrix is pre-mu
ltiplied instead of post-multiplied. |
800 MathUtil::makeIdentity(&A); | 822 MathUtil::makeIdentity(&A); |
801 A.PreconcatScale3d(6, 7, 8); | 823 A.Scale3d(6, 7, 8); |
802 A.PreconcatSkewX(45); | 824 A.SkewX(45); |
803 EXPECT_ROW1_EQ(6, 6, 0, 0, A); | 825 EXPECT_ROW1_EQ(6, 6, 0, 0, A); |
804 EXPECT_ROW2_EQ(0, 7, 0, 0, A); | 826 EXPECT_ROW2_EQ(0, 7, 0, 0, A); |
805 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 827 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
806 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 828 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
807 } | 829 } |
808 | 830 |
809 TEST(MathUtilGfxTransformTest, verifySkewY) | 831 TEST(MathUtilGfxTransformTest, verifySkewY) |
810 { | 832 { |
811 gfx::Transform A; | 833 gfx::Transform A; |
812 A.PreconcatSkewY(45); | 834 A.SkewY(45); |
813 EXPECT_ROW1_EQ(1, 0, 0, 0, A); | 835 EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
814 EXPECT_ROW2_EQ(1, 1, 0, 0, A); | 836 EXPECT_ROW2_EQ(1, 1, 0, 0, A); |
815 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 837 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
816 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 838 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
817 | 839 |
818 // Verify that skewY() post-multiplies the existing matrix. | 840 // Verify that skewY() post-multiplies the existing matrix. |
819 // Row 2, column 1, would incorrectly have value "6" if the matrix is pre-mu
ltiplied instead of post-multiplied. | 841 // Row 2, column 1, would incorrectly have value "6" if the matrix is pre-mu
ltiplied instead of post-multiplied. |
820 MathUtil::makeIdentity(&A); | 842 MathUtil::makeIdentity(&A); |
821 A.PreconcatScale3d(6, 7, 8); | 843 A.Scale3d(6, 7, 8); |
822 A.PreconcatSkewY(45); | 844 A.SkewY(45); |
823 EXPECT_ROW1_EQ(6, 0, 0, 0, A); | 845 EXPECT_ROW1_EQ(6, 0, 0, 0, A); |
824 EXPECT_ROW2_EQ(7, 7, 0, 0, A); | 846 EXPECT_ROW2_EQ(7, 7, 0, 0, A); |
825 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 847 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
826 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 848 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
827 } | 849 } |
828 | 850 |
829 TEST(MathUtilGfxTransformTest, verifyPerspectiveDepth) | 851 TEST(MathUtilGfxTransformTest, verifyPerspectiveDepth) |
830 { | 852 { |
831 gfx::Transform A; | 853 gfx::Transform A; |
832 A.PreconcatPerspectiveDepth(1); | 854 A.ApplyPerspectiveDepth(1); |
833 EXPECT_ROW1_EQ(1, 0, 0, 0, A); | 855 EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
834 EXPECT_ROW2_EQ(0, 1, 0, 0, A); | 856 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
835 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 857 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
836 EXPECT_ROW4_EQ(0, 0, -1, 1, A); | 858 EXPECT_ROW4_EQ(0, 0, -1, 1, A); |
837 | 859 |
838 // Verify that PreconcatPerspectiveDepth() post-multiplies the existing matr
ix. | 860 // Verify that PerspectiveDepth() post-multiplies the existing matrix. |
839 MathUtil::makeIdentity(&A); | 861 MathUtil::makeIdentity(&A); |
840 A.PreconcatTranslate3d(2, 3, 4); | 862 A.Translate3d(2, 3, 4); |
841 A.PreconcatPerspectiveDepth(1); | 863 A.ApplyPerspectiveDepth(1); |
842 EXPECT_ROW1_EQ(1, 0, -2, 2, A); | 864 EXPECT_ROW1_EQ(1, 0, -2, 2, A); |
843 EXPECT_ROW2_EQ(0, 1, -3, 3, A); | 865 EXPECT_ROW2_EQ(0, 1, -3, 3, A); |
844 EXPECT_ROW3_EQ(0, 0, -3, 4, A); | 866 EXPECT_ROW3_EQ(0, 0, -3, 4, A); |
845 EXPECT_ROW4_EQ(0, 0, -1, 1, A); | 867 EXPECT_ROW4_EQ(0, 0, -1, 1, A); |
846 } | 868 } |
847 | 869 |
848 TEST(MathUtilGfxTransformTest, verifyHasPerspective) | 870 TEST(MathUtilGfxTransformTest, verifyHasPerspective) |
849 { | 871 { |
850 gfx::Transform A; | 872 gfx::Transform A; |
851 A.PreconcatPerspectiveDepth(1); | 873 A.ApplyPerspectiveDepth(1); |
852 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 874 EXPECT_TRUE(MathUtil::hasPerspective(A)); |
853 | 875 |
854 MathUtil::makeIdentity(&A); | 876 MathUtil::makeIdentity(&A); |
855 A.PreconcatPerspectiveDepth(0); | 877 A.ApplyPerspectiveDepth(0); |
856 EXPECT_FALSE(MathUtil::hasPerspective(A)); | 878 EXPECT_FALSE(MathUtil::hasPerspective(A)); |
857 | 879 |
858 MathUtil::makeIdentity(&A); | 880 MathUtil::makeIdentity(&A); |
859 A.matrix().setDouble(3, 0, -1); | 881 A.matrix().setDouble(3, 0, -1); |
860 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 882 EXPECT_TRUE(MathUtil::hasPerspective(A)); |
861 | 883 |
862 MathUtil::makeIdentity(&A); | 884 MathUtil::makeIdentity(&A); |
863 A.matrix().setDouble(3, 1, -1); | 885 A.matrix().setDouble(3, 1, -1); |
864 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 886 EXPECT_TRUE(MathUtil::hasPerspective(A)); |
865 | 887 |
(...skipping 12 matching lines...) Expand all Loading... |
878 | 900 |
879 TEST(MathUtilGfxTransformTest, verifyIsInvertible) | 901 TEST(MathUtilGfxTransformTest, verifyIsInvertible) |
880 { | 902 { |
881 gfx::Transform A; | 903 gfx::Transform A; |
882 | 904 |
883 // Translations, rotations, scales, skews and arbitrary combinations of them
are invertible. | 905 // Translations, rotations, scales, skews and arbitrary combinations of them
are invertible. |
884 MathUtil::makeIdentity(&A); | 906 MathUtil::makeIdentity(&A); |
885 EXPECT_TRUE(MathUtil::isInvertible(A)); | 907 EXPECT_TRUE(MathUtil::isInvertible(A)); |
886 | 908 |
887 MathUtil::makeIdentity(&A); | 909 MathUtil::makeIdentity(&A); |
888 A.PreconcatTranslate3d(2, 3, 4); | 910 A.Translate3d(2, 3, 4); |
889 EXPECT_TRUE(MathUtil::isInvertible(A)); | 911 EXPECT_TRUE(MathUtil::isInvertible(A)); |
890 | 912 |
891 MathUtil::makeIdentity(&A); | 913 MathUtil::makeIdentity(&A); |
892 A.PreconcatScale3d(6, 7, 8); | 914 A.Scale3d(6, 7, 8); |
893 EXPECT_TRUE(MathUtil::isInvertible(A)); | 915 EXPECT_TRUE(MathUtil::isInvertible(A)); |
894 | 916 |
895 MathUtil::makeIdentity(&A); | 917 MathUtil::makeIdentity(&A); |
896 MathUtil::rotateEulerAngles(&A, 10, 20, 30); | 918 MathUtil::rotateEulerAngles(&A, 10, 20, 30); |
897 EXPECT_TRUE(MathUtil::isInvertible(A)); | 919 EXPECT_TRUE(MathUtil::isInvertible(A)); |
898 | 920 |
899 MathUtil::makeIdentity(&A); | 921 MathUtil::makeIdentity(&A); |
900 A.PreconcatSkewX(45); | 922 A.SkewX(45); |
901 EXPECT_TRUE(MathUtil::isInvertible(A)); | 923 EXPECT_TRUE(MathUtil::isInvertible(A)); |
902 | 924 |
903 // A perspective matrix (projection plane at z=0) is invertible. The intuiti
ve | 925 // A perspective matrix (projection plane at z=0) is invertible. The intuiti
ve |
904 // explanation is that perspective is eqivalent to a skew of the w-axis; ske
ws are | 926 // explanation is that perspective is eqivalent to a skew of the w-axis; ske
ws are |
905 // invertible. | 927 // invertible. |
906 MathUtil::makeIdentity(&A); | 928 MathUtil::makeIdentity(&A); |
907 A.PreconcatPerspectiveDepth(1); | 929 A.ApplyPerspectiveDepth(1); |
908 EXPECT_TRUE(MathUtil::isInvertible(A)); | 930 EXPECT_TRUE(MathUtil::isInvertible(A)); |
909 | 931 |
910 // A "pure" perspective matrix derived by similar triangles, with m44() set
to zero | 932 // A "pure" perspective matrix derived by similar triangles, with m44() set
to zero |
911 // (i.e. camera positioned at the origin), is not invertible. | 933 // (i.e. camera positioned at the origin), is not invertible. |
912 MathUtil::makeIdentity(&A); | 934 MathUtil::makeIdentity(&A); |
913 A.PreconcatPerspectiveDepth(1); | 935 A.ApplyPerspectiveDepth(1); |
914 A.matrix().setDouble(3, 3, 0); | 936 A.matrix().setDouble(3, 3, 0); |
915 EXPECT_FALSE(MathUtil::isInvertible(A)); | 937 EXPECT_FALSE(MathUtil::isInvertible(A)); |
916 | 938 |
917 // Adding more to a non-invertible matrix will not make it invertible in the
general case. | 939 // Adding more to a non-invertible matrix will not make it invertible in the
general case. |
918 MathUtil::makeIdentity(&A); | 940 MathUtil::makeIdentity(&A); |
919 A.PreconcatPerspectiveDepth(1); | 941 A.ApplyPerspectiveDepth(1); |
920 A.matrix().setDouble(3, 3, 0); | 942 A.matrix().setDouble(3, 3, 0); |
921 A.PreconcatScale3d(6, 7, 8); | 943 A.Scale3d(6, 7, 8); |
922 MathUtil::rotateEulerAngles(&A, 10, 20, 30); | 944 MathUtil::rotateEulerAngles(&A, 10, 20, 30); |
923 A.PreconcatTranslate3d(6, 7, 8); | 945 A.Translate3d(6, 7, 8); |
924 EXPECT_FALSE(MathUtil::isInvertible(A)); | 946 EXPECT_FALSE(MathUtil::isInvertible(A)); |
925 | 947 |
926 // A degenerate matrix of all zeros is not invertible. | 948 // A degenerate matrix of all zeros is not invertible. |
927 MathUtil::makeIdentity(&A); | 949 MathUtil::makeIdentity(&A); |
928 A.matrix().setDouble(0, 0, 0); | 950 A.matrix().setDouble(0, 0, 0); |
929 A.matrix().setDouble(1, 1, 0); | 951 A.matrix().setDouble(1, 1, 0); |
930 A.matrix().setDouble(2, 2, 0); | 952 A.matrix().setDouble(2, 2, 0); |
931 A.matrix().setDouble(3, 3, 0); | 953 A.matrix().setDouble(3, 3, 0); |
932 EXPECT_FALSE(MathUtil::isInvertible(A)); | 954 EXPECT_FALSE(MathUtil::isInvertible(A)); |
933 } | 955 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 A.matrix().setDouble(2, 3, 2); | 1106 A.matrix().setDouble(2, 3, 2); |
1085 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1107 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); |
1086 | 1108 |
1087 MathUtil::makeIdentity(&A); | 1109 MathUtil::makeIdentity(&A); |
1088 A.matrix().setDouble(3, 3, 2); | 1110 A.matrix().setDouble(3, 3, 2); |
1089 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1111 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
1090 } | 1112 } |
1091 | 1113 |
1092 } // namespace | 1114 } // namespace |
1093 } // namespace cc | 1115 } // namespace cc |
OLD | NEW |