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

Side by Side Diff: ui/gfx/transform_unittest.cc

Issue 11774005: Migrate more functions from MathUtil to gfx::Transform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Converted constructors to row-major input Created 7 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/gfx/transform.h" 8 #include "ui/gfx/transform.h"
9 9
10 #include <cmath> 10 #include <cmath>
11 #include <ostream> 11 #include <ostream>
12 #include <limits> 12 #include <limits>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/point.h" 16 #include "ui/gfx/point.h"
17 #include "ui/gfx/point3_f.h" 17 #include "ui/gfx/point3_f.h"
18 #include "ui/gfx/transform_util.h" 18 #include "ui/gfx/transform_util.h"
19 #include "ui/gfx/vector3d_f.h" 19 #include "ui/gfx/vector3d_f.h"
20 20
21 namespace gfx { 21 namespace gfx {
22 22
23 namespace { 23 namespace {
24 24
25 bool PointsAreNearlyEqual(const Point3F& lhs,
26 const Point3F& rhs) {
27 float epsilon = 0.0001f;
28 return lhs.SquaredDistanceTo(rhs) < epsilon;
29 }
30
31 bool MatricesAreNearlyEqual(const Transform& lhs,
32 const Transform& rhs) {
33 float epsilon = 0.0001f;
34 for (int row = 0; row < 4; ++row) {
35 for (int col = 0; col < 4; ++col) {
36 if (std::abs(lhs.matrix().get(row, col) -
37 rhs.matrix().get(row, col)) > epsilon)
38 return false;
39 }
40 }
41 return true;
42 }
43
44 #define EXPECT_ROW1_EQ(a, b, c, d, transform) \ 25 #define EXPECT_ROW1_EQ(a, b, c, d, transform) \
45 EXPECT_FLOAT_EQ((a), (transform).matrix().get(0, 0)); \ 26 EXPECT_FLOAT_EQ((a), (transform).matrix().get(0, 0)); \
46 EXPECT_FLOAT_EQ((b), (transform).matrix().get(0, 1)); \ 27 EXPECT_FLOAT_EQ((b), (transform).matrix().get(0, 1)); \
47 EXPECT_FLOAT_EQ((c), (transform).matrix().get(0, 2)); \ 28 EXPECT_FLOAT_EQ((c), (transform).matrix().get(0, 2)); \
48 EXPECT_FLOAT_EQ((d), (transform).matrix().get(0, 3)); 29 EXPECT_FLOAT_EQ((d), (transform).matrix().get(0, 3));
49 30
50 #define EXPECT_ROW2_EQ(a, b, c, d, transform) \ 31 #define EXPECT_ROW2_EQ(a, b, c, d, transform) \
51 EXPECT_FLOAT_EQ((a), (transform).matrix().get(1, 0)); \ 32 EXPECT_FLOAT_EQ((a), (transform).matrix().get(1, 0)); \
52 EXPECT_FLOAT_EQ((b), (transform).matrix().get(1, 1)); \ 33 EXPECT_FLOAT_EQ((b), (transform).matrix().get(1, 1)); \
53 EXPECT_FLOAT_EQ((c), (transform).matrix().get(1, 2)); \ 34 EXPECT_FLOAT_EQ((c), (transform).matrix().get(1, 2)); \
54 EXPECT_FLOAT_EQ((d), (transform).matrix().get(1, 3)); 35 EXPECT_FLOAT_EQ((d), (transform).matrix().get(1, 3));
55 36
56 #define EXPECT_ROW3_EQ(a, b, c, d, transform) \ 37 #define EXPECT_ROW3_EQ(a, b, c, d, transform) \
57 EXPECT_FLOAT_EQ((a), (transform).matrix().get(2, 0)); \ 38 EXPECT_FLOAT_EQ((a), (transform).matrix().get(2, 0)); \
58 EXPECT_FLOAT_EQ((b), (transform).matrix().get(2, 1)); \ 39 EXPECT_FLOAT_EQ((b), (transform).matrix().get(2, 1)); \
59 EXPECT_FLOAT_EQ((c), (transform).matrix().get(2, 2)); \ 40 EXPECT_FLOAT_EQ((c), (transform).matrix().get(2, 2)); \
60 EXPECT_FLOAT_EQ((d), (transform).matrix().get(2, 3)); 41 EXPECT_FLOAT_EQ((d), (transform).matrix().get(2, 3));
61 42
62 #define EXPECT_ROW4_EQ(a, b, c, d, transform) \ 43 #define EXPECT_ROW4_EQ(a, b, c, d, transform) \
63 EXPECT_FLOAT_EQ((a), (transform).matrix().get(3, 0)); \ 44 EXPECT_FLOAT_EQ((a), (transform).matrix().get(3, 0)); \
64 EXPECT_FLOAT_EQ((b), (transform).matrix().get(3, 1)); \ 45 EXPECT_FLOAT_EQ((b), (transform).matrix().get(3, 1)); \
65 EXPECT_FLOAT_EQ((c), (transform).matrix().get(3, 2)); \ 46 EXPECT_FLOAT_EQ((c), (transform).matrix().get(3, 2)); \
66 EXPECT_FLOAT_EQ((d), (transform).matrix().get(3, 3)); \ 47 EXPECT_FLOAT_EQ((d), (transform).matrix().get(3, 3)); \
67 48
68 // Checking float values for equality close to zero is not robust using 49 // Checking float values for equality close to zero is not robust using
69 // EXPECT_FLOAT_EQ (see gtest documentation). So, to verify rotation matrices, 50 // EXPECT_FLOAT_EQ (see gtest documentation). So, to verify rotation matrices,
70 // we must use a looser absolute error threshold in some places. 51 // we must use a looser absolute error threshold in some places.
71 #define EXPECT_ROW1_NEAR(a, b, c, d, transform, errorThreshold) \ 52 #define EXPECT_ROW1_NEAR(a, b, c, d, transform, errorThreshold) \
72 EXPECT_NEAR((a), (transform).matrix().get(0, 0), (errorThreshold)); \ 53 EXPECT_NEAR((a), (transform).matrix().get(0, 0), (errorThreshold)); \
73 EXPECT_NEAR((b), (transform).matrix().get(0, 1), (errorThreshold)); \ 54 EXPECT_NEAR((b), (transform).matrix().get(0, 1), (errorThreshold)); \
74 EXPECT_NEAR((c), (transform).matrix().get(0, 2), (errorThreshold)); \ 55 EXPECT_NEAR((c), (transform).matrix().get(0, 2), (errorThreshold)); \
75 EXPECT_NEAR((d), (transform).matrix().get(0, 3), (errorThreshold)); 56 EXPECT_NEAR((d), (transform).matrix().get(0, 3), (errorThreshold));
76 57
77 #define EXPECT_ROW2_NEAR(a, b, c, d, transform, errorThreshold) \ 58 #define EXPECT_ROW2_NEAR(a, b, c, d, transform, errorThreshold) \
78 EXPECT_NEAR((a), (transform).matrix().get(1, 0), (errorThreshold)); \ 59 EXPECT_NEAR((a), (transform).matrix().get(1, 0), (errorThreshold)); \
79 EXPECT_NEAR((b), (transform).matrix().get(1, 1), (errorThreshold)); \ 60 EXPECT_NEAR((b), (transform).matrix().get(1, 1), (errorThreshold)); \
80 EXPECT_NEAR((c), (transform).matrix().get(1, 2), (errorThreshold)); \ 61 EXPECT_NEAR((c), (transform).matrix().get(1, 2), (errorThreshold)); \
81 EXPECT_NEAR((d), (transform).matrix().get(1, 3), (errorThreshold)); 62 EXPECT_NEAR((d), (transform).matrix().get(1, 3), (errorThreshold));
82 63
83 #define EXPECT_ROW3_NEAR(a, b, c, d, transform, errorThreshold) \ 64 #define EXPECT_ROW3_NEAR(a, b, c, d, transform, errorThreshold) \
84 EXPECT_NEAR((a), (transform).matrix().get(2, 0), (errorThreshold)); \ 65 EXPECT_NEAR((a), (transform).matrix().get(2, 0), (errorThreshold)); \
85 EXPECT_NEAR((b), (transform).matrix().get(2, 1), (errorThreshold)); \ 66 EXPECT_NEAR((b), (transform).matrix().get(2, 1), (errorThreshold)); \
86 EXPECT_NEAR((c), (transform).matrix().get(2, 2), (errorThreshold)); \ 67 EXPECT_NEAR((c), (transform).matrix().get(2, 2), (errorThreshold)); \
87 EXPECT_NEAR((d), (transform).matrix().get(2, 3), (errorThreshold)); 68 EXPECT_NEAR((d), (transform).matrix().get(2, 3), (errorThreshold));
88 69
70 bool PointsAreNearlyEqual(const Point3F& lhs,
71 const Point3F& rhs) {
72 float epsilon = 0.0001f;
73 return lhs.SquaredDistanceTo(rhs) < epsilon;
74 }
75
76 bool MatricesAreNearlyEqual(const Transform& lhs,
77 const Transform& rhs) {
78 float epsilon = 0.0001f;
79 for (int row = 0; row < 4; ++row) {
80 for (int col = 0; col < 4; ++col) {
81 if (std::abs(lhs.matrix().get(row, col) -
82 rhs.matrix().get(row, col)) > epsilon)
83 return false;
84 }
85 }
86 return true;
87 }
88
89 void InitializeTestMatrix(Transform* transform) {
90 SkMatrix44& matrix = transform->matrix();
91 matrix.setDouble(0, 0, 10.0);
92 matrix.setDouble(1, 0, 11.0);
93 matrix.setDouble(2, 0, 12.0);
94 matrix.setDouble(3, 0, 13.0);
95 matrix.setDouble(0, 1, 14.0);
96 matrix.setDouble(1, 1, 15.0);
97 matrix.setDouble(2, 1, 16.0);
98 matrix.setDouble(3, 1, 17.0);
99 matrix.setDouble(0, 2, 18.0);
100 matrix.setDouble(1, 2, 19.0);
101 matrix.setDouble(2, 2, 20.0);
102 matrix.setDouble(3, 2, 21.0);
103 matrix.setDouble(0, 3, 22.0);
104 matrix.setDouble(1, 3, 23.0);
105 matrix.setDouble(2, 3, 24.0);
106 matrix.setDouble(3, 3, 25.0);
107
108 // Sanity check
109 EXPECT_ROW1_EQ(10.0, 14.0, 18.0, 22.0, (*transform));
110 EXPECT_ROW2_EQ(11.0, 15.0, 19.0, 23.0, (*transform));
111 EXPECT_ROW3_EQ(12.0, 16.0, 20.0, 24.0, (*transform));
112 EXPECT_ROW4_EQ(13.0, 17.0, 21.0, 25.0, (*transform));
113 }
114
115 void InitializeTestMatrix2(Transform* transform) {
116 SkMatrix44& matrix = transform->matrix();
117 matrix.setDouble(0, 0, 30.0);
118 matrix.setDouble(1, 0, 31.0);
119 matrix.setDouble(2, 0, 32.0);
120 matrix.setDouble(3, 0, 33.0);
121 matrix.setDouble(0, 1, 34.0);
122 matrix.setDouble(1, 1, 35.0);
123 matrix.setDouble(2, 1, 36.0);
124 matrix.setDouble(3, 1, 37.0);
125 matrix.setDouble(0, 2, 38.0);
126 matrix.setDouble(1, 2, 39.0);
127 matrix.setDouble(2, 2, 40.0);
128 matrix.setDouble(3, 2, 41.0);
129 matrix.setDouble(0, 3, 42.0);
130 matrix.setDouble(1, 3, 43.0);
131 matrix.setDouble(2, 3, 44.0);
132 matrix.setDouble(3, 3, 45.0);
133
134 // Sanity check
135 EXPECT_ROW1_EQ(30.0, 34.0, 38.0, 42.0, (*transform));
136 EXPECT_ROW2_EQ(31.0, 35.0, 39.0, 43.0, (*transform));
137 EXPECT_ROW3_EQ(32.0, 36.0, 40.0, 44.0, (*transform));
138 EXPECT_ROW4_EQ(33.0, 37.0, 41.0, 45.0, (*transform));
139 }
140
89 #ifdef SK_MSCALAR_IS_DOUBLE 141 #ifdef SK_MSCALAR_IS_DOUBLE
90 #define ERROR_THRESHOLD 1e-14 142 #define ERROR_THRESHOLD 1e-14
91 #else 143 #else
92 #define ERROR_THRESHOLD 1e-7 144 #define ERROR_THRESHOLD 1e-7
93 #endif 145 #endif
94 #define LOOSE_ERROR_THRESHOLD 1e-7 146 #define LOOSE_ERROR_THRESHOLD 1e-7
95 147
96 TEST(XFormTest, Equality) { 148 TEST(XFormTest, Equality) {
97 Transform lhs, rhs, interpolated; 149 Transform lhs, rhs, interpolated;
98 rhs.matrix().set3x3(1, 2, 3, 150 rhs.matrix().set3x3(1, 2, 3,
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 EXPECT_EQ(to, from); 752 EXPECT_EQ(to, from);
701 } 753 }
702 754
703 TEST(XFormTest, CannotBlendSingularMatrix) { 755 TEST(XFormTest, CannotBlendSingularMatrix) {
704 Transform from; 756 Transform from;
705 Transform to; 757 Transform to;
706 to.matrix().set(1, 1, SkDoubleToMScalar(0)); 758 to.matrix().set(1, 1, SkDoubleToMScalar(0));
707 EXPECT_FALSE(to.Blend(from, 0.5)); 759 EXPECT_FALSE(to.Blend(from, 0.5));
708 } 760 }
709 761
710 TEST(XFormTest, VerifyBlendForTranslation) 762 TEST(XFormTest, VerifyBlendForTranslation) {
711 {
712 Transform from; 763 Transform from;
713 from.Translate3d(100, 200, 100); 764 from.Translate3d(100.0, 200.0, 100.0);
714 765
715 Transform to; 766 Transform to;
716 767
717 to.Translate3d(200, 100, 300); 768 to.Translate3d(200.0, 100.0, 300.0);
718 to.Blend(from, 0); 769 to.Blend(from, 0.0);
719 EXPECT_EQ(from, to); 770 EXPECT_EQ(from, to);
720 771
721 to = Transform(); 772 to = Transform();
722 to.Translate3d(200, 100, 300); 773 to.Translate3d(200.0, 100.0, 300.0);
723 to.Blend(from, 0.25); 774 to.Blend(from, 0.25);
724 EXPECT_ROW1_EQ(1, 0, 0, 125, to); 775 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 125.0, to);
725 EXPECT_ROW2_EQ(0, 1, 0, 175, to); 776 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 175.0, to);
726 EXPECT_ROW3_EQ(0, 0, 1, 150, to); 777 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 150.0, to);
727 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 778 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
728 779
729 to = Transform(); 780 to = Transform();
730 to.Translate3d(200, 100, 300); 781 to.Translate3d(200.0, 100.0, 300.0);
731 to.Blend(from, 0.5); 782 to.Blend(from, 0.5);
732 EXPECT_ROW1_EQ(1, 0, 0, 150, to); 783 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 150.0, to);
733 EXPECT_ROW2_EQ(0, 1, 0, 150, to); 784 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 150.0, to);
734 EXPECT_ROW3_EQ(0, 0, 1, 200, to); 785 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 200.0, to);
735 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 786 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
736 787
737 to = Transform(); 788 to = Transform();
738 to.Translate3d(200, 100, 300); 789 to.Translate3d(200.0, 100.0, 300.0);
739 to.Blend(from, 1); 790 to.Blend(from, 1.0);
740 EXPECT_ROW1_EQ(1, 0, 0, 200, to); 791 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 200.0, to);
741 EXPECT_ROW2_EQ(0, 1, 0, 100, to); 792 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 100.0, to);
742 EXPECT_ROW3_EQ(0, 0, 1, 300, to); 793 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 300.0, to);
743 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 794 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
744 } 795 }
745 796
746 TEST(XFormTest, VerifyBlendForScale) 797 TEST(XFormTest, VerifyBlendForScale) {
747 {
748 Transform from; 798 Transform from;
749 from.Scale3d(100, 200, 100); 799 from.Scale3d(100.0, 200.0, 100.0);
750 800
751 Transform to; 801 Transform to;
752 802
753 to.Scale3d(200, 100, 300); 803 to.Scale3d(200.0, 100.0, 300.0);
754 to.Blend(from, 0); 804 to.Blend(from, 0.0);
755 EXPECT_EQ(from, to); 805 EXPECT_EQ(from, to);
756 806
757 to = Transform(); 807 to = Transform();
758 to.Scale3d(200, 100, 300); 808 to.Scale3d(200.0, 100.0, 300.0);
759 to.Blend(from, 0.25); 809 to.Blend(from, 0.25);
760 EXPECT_ROW1_EQ(125, 0, 0, 0, to); 810 EXPECT_ROW1_EQ(125.0, 0.0, 0.0, 0.0, to);
761 EXPECT_ROW2_EQ(0, 175, 0, 0, to); 811 EXPECT_ROW2_EQ(0.0, 175.0, 0.0, 0.0, to);
762 EXPECT_ROW3_EQ(0, 0, 150, 0, to); 812 EXPECT_ROW3_EQ(0.0, 0.0, 150.0, 0.0, to);
763 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 813 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
764 814
765 to = Transform(); 815 to = Transform();
766 to.Scale3d(200, 100, 300); 816 to.Scale3d(200.0, 100.0, 300.0);
767 to.Blend(from, 0.5); 817 to.Blend(from, 0.5);
768 EXPECT_ROW1_EQ(150, 0, 0, 0, to); 818 EXPECT_ROW1_EQ(150.0, 0.0, 0.0, 0.0, to);
769 EXPECT_ROW2_EQ(0, 150, 0, 0, to); 819 EXPECT_ROW2_EQ(0.0, 150.0, 0.0, 0.0, to);
770 EXPECT_ROW3_EQ(0, 0, 200, 0, to); 820 EXPECT_ROW3_EQ(0.0, 0.0, 200.0, 0.0, to);
771 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 821 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
772 822
773 to = Transform(); 823 to = Transform();
774 to.Scale3d(200, 100, 300); 824 to.Scale3d(200.0, 100.0, 300.0);
775 to.Blend(from, 1); 825 to.Blend(from, 1.0);
776 EXPECT_ROW1_EQ(200, 0, 0, 0, to); 826 EXPECT_ROW1_EQ(200.0, 0.0, 0.0, 0.0, to);
777 EXPECT_ROW2_EQ(0, 100, 0, 0, to); 827 EXPECT_ROW2_EQ(0.0, 100.0, 0.0, 0.0, to);
778 EXPECT_ROW3_EQ(0, 0, 300, 0, to); 828 EXPECT_ROW3_EQ(0.0, 0.0, 300.0, 0.0, to);
779 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 829 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
780 } 830 }
781 831
782 TEST(XFormTest, VerifyBlendForSkewX) 832 TEST(XFormTest, VerifyBlendForSkewX) {
783 {
784 Transform from; 833 Transform from;
785 from.SkewX(0); 834 from.SkewX(0.0);
786 835
787 Transform to; 836 Transform to;
788 837
789 to.SkewX(45); 838 to.SkewX(45.0);
790 to.Blend(from, 0); 839 to.Blend(from, 0.0);
791 EXPECT_EQ(from, to); 840 EXPECT_EQ(from, to);
792 841
793 to = Transform(); 842 to = Transform();
794 to.SkewX(45); 843 to.SkewX(45.0);
795 to.Blend(from, 0.5); 844 to.Blend(from, 0.5);
796 EXPECT_ROW1_EQ(1, 0.5, 0, 0, to); 845 EXPECT_ROW1_EQ(1.0, 0.5, 0.0, 0.0, to);
797 EXPECT_ROW2_EQ(0, 1, 0, 0, to); 846 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, to);
798 EXPECT_ROW3_EQ(0, 0, 1, 0, to); 847 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, to);
799 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 848 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
800 849
801 to = Transform(); 850 to = Transform();
802 to.SkewX(45); 851 to.SkewX(45.0);
803 to.Blend(from, 0.25); 852 to.Blend(from, 0.25);
804 EXPECT_ROW1_EQ(1, 0.25, 0, 0, to); 853 EXPECT_ROW1_EQ(1.0, 0.25, 0.0, 0.0, to);
805 EXPECT_ROW2_EQ(0, 1, 0, 0, to); 854 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, to);
806 EXPECT_ROW3_EQ(0, 0, 1, 0, to); 855 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, to);
807 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 856 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
808 857
809 to = Transform(); 858 to = Transform();
810 to.SkewX(45); 859 to.SkewX(45.0);
811 to.Blend(from, 1); 860 to.Blend(from, 1.0);
812 EXPECT_ROW1_EQ(1, 1, 0, 0, to); 861 EXPECT_ROW1_EQ(1.0, 1.0, 0.0, 0.0, to);
813 EXPECT_ROW2_EQ(0, 1, 0, 0, to); 862 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, to);
814 EXPECT_ROW3_EQ(0, 0, 1, 0, to); 863 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, to);
815 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 864 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
816 } 865 }
817 866
818 TEST(XFormTest, VerifyBlendForSkewY) 867 TEST(XFormTest, VerifyBlendForSkewY) {
819 {
820 // NOTE CAREFULLY: Decomposition of skew and rotation terms of the matrix 868 // NOTE CAREFULLY: Decomposition of skew and rotation terms of the matrix
821 // is inherently underconstrained, and so it does not always compute the 869 // is inherently underconstrained, and so it does not always compute the
822 // originally intended skew parameters. The current implementation uses QR 870 // originally intended skew parameters. The current implementation uses QR
823 // decomposition, which decomposes the shear into a rotation + non-uniform 871 // decomposition, which decomposes the shear into a rotation + non-uniform
824 // scale. 872 // scale.
825 // 873 //
826 // It is unlikely that the decomposition implementation will need to change 874 // It is unlikely that the decomposition implementation will need to change
827 // very often, so to get any test coverage, the compromise is to verify the 875 // very often, so to get any test coverage, the compromise is to verify the
828 // exact matrix that the.Blend() operation produces. 876 // exact matrix that the.Blend() operation produces.
829 // 877 //
830 // This problem also potentially exists for skewX, but the current QR 878 // This problem also potentially exists for skewX, but the current QR
831 // decomposition implementation just happens to decompose those test 879 // decomposition implementation just happens to decompose those test
832 // matrices intuitively. 880 // matrices intuitively.
833 // 881 //
834 // Unfortunately, this case suffers from uncomfortably large precision 882 // Unfortunately, this case suffers from uncomfortably large precision
835 // error. 883 // error.
836 884
837 Transform from; 885 Transform from;
838 from.SkewY(0); 886 from.SkewY(0.0);
839 887
840 Transform to; 888 Transform to;
841 889
842 to.SkewY(45); 890 to.SkewY(45.0);
843 to.Blend(from, 0); 891 to.Blend(from, 0.0);
844 EXPECT_EQ(from, to); 892 EXPECT_EQ(from, to);
845 893
846 to = Transform(); 894 to = Transform();
847 to.SkewY(45); 895 to.SkewY(45.0);
848 to.Blend(from, 0.25); 896 to.Blend(from, 0.25);
849 EXPECT_ROW1_NEAR(1.0823489449280947471976333, 897 EXPECT_ROW1_NEAR(1.0823489449280947471976333,
850 0.0464370719145053845178239, 898 0.0464370719145053845178239,
851 0, 899 0.0,
852 0, 900 0.0,
853 to, 901 to,
854 LOOSE_ERROR_THRESHOLD); 902 LOOSE_ERROR_THRESHOLD);
855 EXPECT_ROW2_NEAR(0.2152925909665224513123150, 903 EXPECT_ROW2_NEAR(0.2152925909665224513123150,
856 0.9541702441750861130032035, 904 0.9541702441750861130032035,
857 0, 905 0.0,
858 0, 906 0.0,
859 to, 907 to,
860 LOOSE_ERROR_THRESHOLD); 908 LOOSE_ERROR_THRESHOLD);
861 EXPECT_ROW3_EQ(0, 0, 1, 0, to); 909 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, to);
862 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 910 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
863 911
864 to = Transform(); 912 to = Transform();
865 to.SkewY(45); 913 to.SkewY(45.0);
866 to.Blend(from, 0.5); 914 to.Blend(from, 0.5);
867 EXPECT_ROW1_NEAR(1.1152212925809066312865525, 915 EXPECT_ROW1_NEAR(1.1152212925809066312865525,
868 0.0676495144007326631996335, 916 0.0676495144007326631996335,
869 0, 917 0.0,
870 0, 918 0.0,
871 to, 919 to,
872 LOOSE_ERROR_THRESHOLD); 920 LOOSE_ERROR_THRESHOLD);
873 EXPECT_ROW2_NEAR(0.4619397844342648662419037, 921 EXPECT_ROW2_NEAR(0.4619397844342648662419037,
874 0.9519009045724774464858342, 922 0.9519009045724774464858342,
875 0, 923 0.0,
876 0, 924 0.0,
877 to, 925 to,
878 LOOSE_ERROR_THRESHOLD); 926 LOOSE_ERROR_THRESHOLD);
879 EXPECT_ROW3_EQ(0, 0, 1, 0, to); 927 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, to);
880 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 928 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
881 929
882 to = Transform(); 930 to = Transform();
883 to.SkewY(45); 931 to.SkewY(45.0);
884 to.Blend(from, 1); 932 to.Blend(from, 1.0);
885 EXPECT_ROW1_NEAR(1, 0, 0, 0, to, LOOSE_ERROR_THRESHOLD); 933 EXPECT_ROW1_NEAR(1.0, 0.0, 0.0, 0.0, to, LOOSE_ERROR_THRESHOLD);
886 EXPECT_ROW2_NEAR(1, 1, 0, 0, to, LOOSE_ERROR_THRESHOLD); 934 EXPECT_ROW2_NEAR(1.0, 1.0, 0.0, 0.0, to, LOOSE_ERROR_THRESHOLD);
887 EXPECT_ROW3_EQ(0, 0, 1, 0, to); 935 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, to);
888 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 936 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
889 } 937 }
890 938
891 TEST(XFormTest, VerifyBlendForRotationAboutX) 939 TEST(XFormTest, VerifyBlendForRotationAboutX) {
892 {
893 // Even though.Blending uses quaternions, axis-aligned rotations should. 940 // Even though.Blending uses quaternions, axis-aligned rotations should.
894 // Blend the same with quaternions or Euler angles. So we can test 941 // Blend the same with quaternions or Euler angles. So we can test
895 // rotation.Blending by comparing against manually specified matrices from 942 // rotation.Blending by comparing against manually specified matrices from
896 // Euler angles. 943 // Euler angles.
897 944
898 Transform from; 945 Transform from;
899 from.RotateAbout(Vector3dF(1, 0, 0), 0); 946 from.RotateAbout(Vector3dF(1.0, 0.0, 0.0), 0.0);
900 947
901 Transform to; 948 Transform to;
902 949
903 to.RotateAbout(Vector3dF(1, 0, 0), 90); 950 to.RotateAbout(Vector3dF(1.0, 0.0, 0.0), 90.0);
904 to.Blend(from, 0); 951 to.Blend(from, 0.0);
905 EXPECT_EQ(from, to); 952 EXPECT_EQ(from, to);
906 953
907 double expectedRotationAngle = 22.5 * M_PI / 180.0; 954 double expectedRotationAngle = 22.5 * M_PI / 180.0;
908 to = Transform(); 955 to = Transform();
909 to.RotateAbout(Vector3dF(1, 0, 0), 90); 956 to.RotateAbout(Vector3dF(1.0, 0.0, 0.0), 90.0);
910 to.Blend(from, 0.25); 957 to.Blend(from, 0.25);
911 EXPECT_ROW1_NEAR(1, 0, 0, 0, to, ERROR_THRESHOLD); 958 EXPECT_ROW1_NEAR(1.0, 0.0, 0.0, 0.0, to, ERROR_THRESHOLD);
912 EXPECT_ROW2_NEAR(0, 959 EXPECT_ROW2_NEAR(0.0,
913 std::cos(expectedRotationAngle), 960 std::cos(expectedRotationAngle),
914 -std::sin(expectedRotationAngle), 961 -std::sin(expectedRotationAngle),
915 0, 962 0.0,
916 to, 963 to,
917 ERROR_THRESHOLD); 964 ERROR_THRESHOLD);
918 EXPECT_ROW3_NEAR(0, 965 EXPECT_ROW3_NEAR(0,
919 std::sin(expectedRotationAngle), 966 std::sin(expectedRotationAngle),
920 std::cos(expectedRotationAngle), 967 std::cos(expectedRotationAngle),
921 0, 968 0.0,
922 to, 969 to,
923 ERROR_THRESHOLD); 970 ERROR_THRESHOLD);
924 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 971 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
925 972
926 expectedRotationAngle = 45 * M_PI / 180.0; 973 expectedRotationAngle = 45.0 * M_PI / 180.0;
927 to = Transform(); 974 to = Transform();
928 to.RotateAbout(Vector3dF(1, 0, 0), 90); 975 to.RotateAbout(Vector3dF(1.0, 0.0, 0.0), 90.0);
929 to.Blend(from, 0.5); 976 to.Blend(from, 0.5);
930 EXPECT_ROW1_NEAR(1, 0, 0, 0, to, ERROR_THRESHOLD); 977 EXPECT_ROW1_NEAR(1.0, 0.0, 0.0, 0.0, to, ERROR_THRESHOLD);
931 EXPECT_ROW2_NEAR(0, 978 EXPECT_ROW2_NEAR(0.0,
932 std::cos(expectedRotationAngle), 979 std::cos(expectedRotationAngle),
933 -std::sin(expectedRotationAngle), 980 -std::sin(expectedRotationAngle),
934 0, 981 0.0,
935 to, 982 to,
936 ERROR_THRESHOLD); 983 ERROR_THRESHOLD);
937 EXPECT_ROW3_NEAR(0, 984 EXPECT_ROW3_NEAR(0.0,
938 std::sin(expectedRotationAngle), 985 std::sin(expectedRotationAngle),
939 std::cos(expectedRotationAngle), 986 std::cos(expectedRotationAngle),
940 0, 987 0.0,
941 to, 988 to,
942 ERROR_THRESHOLD); 989 ERROR_THRESHOLD);
943 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 990 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
944 991
945 to = Transform(); 992 to = Transform();
946 to.RotateAbout(Vector3dF(1, 0, 0), 90); 993 to.RotateAbout(Vector3dF(1.0, 0.0, 0.0), 90.0);
947 to.Blend(from, 1); 994 to.Blend(from, 1.0);
948 EXPECT_ROW1_NEAR(1, 0, 0, 0, to, ERROR_THRESHOLD); 995 EXPECT_ROW1_NEAR(1.0, 0.0, 0.0, 0.0, to, ERROR_THRESHOLD);
949 EXPECT_ROW2_NEAR(0, 0, -1, 0, to, ERROR_THRESHOLD); 996 EXPECT_ROW2_NEAR(0.0, 0.0, -1.0, 0.0, to, ERROR_THRESHOLD);
950 EXPECT_ROW3_NEAR(0, 1, 0, 0, to, ERROR_THRESHOLD); 997 EXPECT_ROW3_NEAR(0.0, 1.0, 0.0, 0.0, to, ERROR_THRESHOLD);
951 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 998 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
952 } 999 }
953 1000
954 TEST(XFormTest, VerifyBlendForRotationAboutY) 1001 TEST(XFormTest, VerifyBlendForRotationAboutY) {
955 { 1002 Transform from;
956 Transform from; 1003 from.RotateAbout(Vector3dF(0.0, 1.0, 0.0), 0.0);
957 from.RotateAbout(Vector3dF(0, 1, 0), 0); 1004
958 1005 Transform to;
959 Transform to; 1006
960 1007 to.RotateAbout(Vector3dF(0.0, 1.0, 0.0), 90.0);
961 to.RotateAbout(Vector3dF(0, 1, 0), 90); 1008 to.Blend(from, 0.0);
962 to.Blend(from, 0);
963 EXPECT_EQ(from, to); 1009 EXPECT_EQ(from, to);
964 1010
965 double expectedRotationAngle = 22.5 * M_PI / 180.0; 1011 double expectedRotationAngle = 22.5 * M_PI / 180.0;
966 to = Transform(); 1012 to = Transform();
967 to.RotateAbout(Vector3dF(0, 1, 0), 90); 1013 to.RotateAbout(Vector3dF(0.0, 1.0, 0.0), 90.0);
968 to.Blend(from, 0.25); 1014 to.Blend(from, 0.25);
969 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle), 1015 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle),
970 0, 1016 0.0,
971 std::sin(expectedRotationAngle), 1017 std::sin(expectedRotationAngle),
972 0, 1018 0.0,
973 to, 1019 to,
974 ERROR_THRESHOLD); 1020 ERROR_THRESHOLD);
975 EXPECT_ROW2_NEAR(0, 1, 0, 0, to, ERROR_THRESHOLD); 1021 EXPECT_ROW2_NEAR(0.0, 1.0, 0.0, 0.0, to, ERROR_THRESHOLD);
976 EXPECT_ROW3_NEAR(-std::sin(expectedRotationAngle), 1022 EXPECT_ROW3_NEAR(-std::sin(expectedRotationAngle),
977 0, 1023 0.0,
978 std::cos(expectedRotationAngle), 1024 std::cos(expectedRotationAngle),
979 0, 1025 0.0,
980 to, 1026 to,
981 ERROR_THRESHOLD); 1027 ERROR_THRESHOLD);
982 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 1028 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
983 1029
984 expectedRotationAngle = 45 * M_PI / 180.0; 1030 expectedRotationAngle = 45.0 * M_PI / 180.0;
985 to = Transform(); 1031 to = Transform();
986 to.RotateAbout(Vector3dF(0, 1, 0), 90); 1032 to.RotateAbout(Vector3dF(0.0, 1.0, 0.0), 90.0);
987 to.Blend(from, 0.5); 1033 to.Blend(from, 0.5);
988 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle), 1034 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle),
989 0, 1035 0.0,
990 std::sin(expectedRotationAngle), 1036 std::sin(expectedRotationAngle),
991 0, 1037 0.0,
992 to, 1038 to,
993 ERROR_THRESHOLD); 1039 ERROR_THRESHOLD);
994 EXPECT_ROW2_NEAR(0, 1, 0, 0, to, ERROR_THRESHOLD); 1040 EXPECT_ROW2_NEAR(0.0, 1.0, 0.0, 0.0, to, ERROR_THRESHOLD);
995 EXPECT_ROW3_NEAR(-std::sin(expectedRotationAngle), 1041 EXPECT_ROW3_NEAR(-std::sin(expectedRotationAngle),
996 0, 1042 0.0,
997 std::cos(expectedRotationAngle), 1043 std::cos(expectedRotationAngle),
998 0, 1044 0.0,
999 to, 1045 to,
1000 ERROR_THRESHOLD); 1046 ERROR_THRESHOLD);
1001 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 1047 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
1002 1048
1003 to = Transform(); 1049 to = Transform();
1004 to.RotateAbout(Vector3dF(0, 1, 0), 90); 1050 to.RotateAbout(Vector3dF(0.0, 1.0, 0.0), 90.0);
1005 to.Blend(from, 1); 1051 to.Blend(from, 1.0);
1006 EXPECT_ROW1_NEAR(0, 0, 1, 0, to, ERROR_THRESHOLD); 1052 EXPECT_ROW1_NEAR(0.0, 0.0, 1.0, 0.0, to, ERROR_THRESHOLD);
1007 EXPECT_ROW2_NEAR(0, 1, 0, 0, to, ERROR_THRESHOLD); 1053 EXPECT_ROW2_NEAR(0.0, 1.0, 0.0, 0.0, to, ERROR_THRESHOLD);
1008 EXPECT_ROW3_NEAR(-1, 0, 0, 0, to, ERROR_THRESHOLD); 1054 EXPECT_ROW3_NEAR(-1.0, 0.0, 0.0, 0.0, to, ERROR_THRESHOLD);
1009 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 1055 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
1010 } 1056 }
1011 1057
1012 TEST(XFormTest, VerifyBlendForRotationAboutZ) 1058 TEST(XFormTest, VerifyBlendForRotationAboutZ) {
1013 { 1059 Transform from;
1014 Transform from; 1060 from.RotateAbout(Vector3dF(0.0, 0.0, 1.0), 0.0);
1015 from.RotateAbout(Vector3dF(0, 0, 1), 0); 1061
1016 1062 Transform to;
1017 Transform to; 1063
1018 1064 to.RotateAbout(Vector3dF(0.0, 0.0, 1.0), 90.0);
1019 to.RotateAbout(Vector3dF(0, 0, 1), 90); 1065 to.Blend(from, 0.0);
1020 to.Blend(from, 0);
1021 EXPECT_EQ(from, to); 1066 EXPECT_EQ(from, to);
1022 1067
1023 double expectedRotationAngle = 22.5 * M_PI / 180.0; 1068 double expectedRotationAngle = 22.5 * M_PI / 180.0;
1024 to = Transform(); 1069 to = Transform();
1025 to.RotateAbout(Vector3dF(0, 0, 1), 90); 1070 to.RotateAbout(Vector3dF(0.0, 0.0, 1.0), 90.0);
1026 to.Blend(from, 0.25); 1071 to.Blend(from, 0.25);
1027 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle), 1072 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle),
1028 -std::sin(expectedRotationAngle), 1073 -std::sin(expectedRotationAngle),
1029 0, 1074 0.0,
1030 0, 1075 0.0,
1031 to, 1076 to,
1032 ERROR_THRESHOLD); 1077 ERROR_THRESHOLD);
1033 EXPECT_ROW2_NEAR(std::sin(expectedRotationAngle), 1078 EXPECT_ROW2_NEAR(std::sin(expectedRotationAngle),
1034 std::cos(expectedRotationAngle), 1079 std::cos(expectedRotationAngle),
1035 0, 1080 0.0,
1036 0, 1081 0.0,
1037 to, 1082 to,
1038 ERROR_THRESHOLD); 1083 ERROR_THRESHOLD);
1039 EXPECT_ROW3_NEAR(0, 0, 1, 0, to, ERROR_THRESHOLD); 1084 EXPECT_ROW3_NEAR(0.0, 0.0, 1.0, 0.0, to, ERROR_THRESHOLD);
1040 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 1085 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
1041 1086
1042 expectedRotationAngle = 45 * M_PI / 180.0; 1087 expectedRotationAngle = 45.0 * M_PI / 180.0;
1043 to = Transform(); 1088 to = Transform();
1044 to.RotateAbout(Vector3dF(0, 0, 1), 90); 1089 to.RotateAbout(Vector3dF(0.0, 0.0, 1.0), 90.0);
1045 to.Blend(from, 0.5); 1090 to.Blend(from, 0.5);
1046 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle), 1091 EXPECT_ROW1_NEAR(std::cos(expectedRotationAngle),
1047 -std::sin(expectedRotationAngle), 1092 -std::sin(expectedRotationAngle),
1048 0, 1093 0.0,
1049 0, 1094 0.0,
1050 to, 1095 to,
1051 ERROR_THRESHOLD); 1096 ERROR_THRESHOLD);
1052 EXPECT_ROW2_NEAR(std::sin(expectedRotationAngle), 1097 EXPECT_ROW2_NEAR(std::sin(expectedRotationAngle),
1053 std::cos(expectedRotationAngle), 1098 std::cos(expectedRotationAngle),
1054 0, 1099 0.0,
1055 0, 1100 0.0,
1056 to, 1101 to,
1057 ERROR_THRESHOLD); 1102 ERROR_THRESHOLD);
1058 EXPECT_ROW3_NEAR(0, 0, 1, 0, to, ERROR_THRESHOLD); 1103 EXPECT_ROW3_NEAR(0.0, 0.0, 1.0, 0.0, to, ERROR_THRESHOLD);
1059 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 1104 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
1060 1105
1061 to = Transform(); 1106 to = Transform();
1062 to.RotateAbout(Vector3dF(0, 0, 1), 90); 1107 to.RotateAbout(Vector3dF(0.0, 0.0, 1.0), 90.0);
1063 to.Blend(from, 1); 1108 to.Blend(from, 1.0);
1064 EXPECT_ROW1_NEAR(0, -1, 0, 0, to, ERROR_THRESHOLD); 1109 EXPECT_ROW1_NEAR(0.0, -1.0, 0.0, 0.0, to, ERROR_THRESHOLD);
1065 EXPECT_ROW2_NEAR(1, 0, 0, 0, to, ERROR_THRESHOLD); 1110 EXPECT_ROW2_NEAR(1.0, 0.0, 0.0, 0.0, to, ERROR_THRESHOLD);
1066 EXPECT_ROW3_NEAR(0, 0, 1, 0, to, ERROR_THRESHOLD); 1111 EXPECT_ROW3_NEAR(0.0, 0.0, 1.0, 0.0, to, ERROR_THRESHOLD);
1067 EXPECT_ROW4_EQ(0, 0, 0, 1, to); 1112 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, to);
1068 } 1113 }
1069 1114
1070 TEST(XFormTest, VerifyBlendForCompositeTransform) 1115 TEST(XFormTest, VerifyBlendForCompositeTransform) {
1071 {
1072 // Verify that the.Blending was done with a decomposition in correct order 1116 // Verify that the.Blending was done with a decomposition in correct order
1073 // by blending a composite transform. Using matrix x vector notation 1117 // by blending a composite transform. Using matrix x vector notation
1074 // (Ax = b, where x is column vector), the ordering should be: 1118 // (Ax = b, where x is column vector), the ordering should be:
1075 // perspective * translation * rotation * skew * scale 1119 // perspective * translation * rotation * skew * scale
1076 // 1120 //
1077 // It is not as important (or meaningful) to check intermediate 1121 // It is not as important (or meaningful) to check intermediate
1078 // interpolations; order of operations will be tested well enough by the 1122 // interpolations; order of operations will be tested well enough by the
1079 // end cases that are easier to specify. 1123 // end cases that are easier to specify.
1080 1124
1081 Transform from; 1125 Transform from;
1082 Transform to; 1126 Transform to;
1083 1127
1084 Transform expectedEndOfAnimation; 1128 Transform expectedEndOfAnimation;
1085 expectedEndOfAnimation.ApplyPerspectiveDepth(1); 1129 expectedEndOfAnimation.ApplyPerspectiveDepth(1.0);
1086 expectedEndOfAnimation.Translate3d(10, 20, 30); 1130 expectedEndOfAnimation.Translate3d(10.0, 20.0, 30.0);
1087 expectedEndOfAnimation.RotateAbout(Vector3dF(0, 0, 1), 25); 1131 expectedEndOfAnimation.RotateAbout(Vector3dF(0.0, 0.0, 1.0), 25.0);
1088 expectedEndOfAnimation.SkewY(45); 1132 expectedEndOfAnimation.SkewY(45.0);
1089 expectedEndOfAnimation.Scale3d(6, 7, 8); 1133 expectedEndOfAnimation.Scale3d(6.0, 7.0, 8.0);
1090 1134
1091 to = expectedEndOfAnimation; 1135 to = expectedEndOfAnimation;
1092 to.Blend(from, 0); 1136 to.Blend(from, 0.0);
1093 EXPECT_EQ(from, to); 1137 EXPECT_EQ(from, to);
1094 1138
1095 to = expectedEndOfAnimation; 1139 to = expectedEndOfAnimation;
1096 // We short circuit if blend is >= 1, so to check the numerics, we will 1140 // We short circuit if blend is >= 1, so to check the numerics, we will
1097 // check that we get close to what we expect when we're nearly done 1141 // check that we get close to what we expect when we're nearly done
1098 // interpolating. 1142 // interpolating.
1099 to.Blend(from, .99999); 1143 to.Blend(from, .99999);
1100 1144
1101 // Recomposing the matrix results in a normalized matrix, so to verify we 1145 // Recomposing the matrix results in a normalized matrix, so to verify we
1102 // need to normalize the expectedEndOfAnimation before comparing elements. 1146 // need to normalize the expectedEndOfAnimation before comparing elements.
1103 // Normalizing means dividing everything by expectedEndOfAnimation.m44(). 1147 // Normalizing means dividing everything by expectedEndOfAnimation.m44().
1104 Transform normalizedExpectedEndOfAnimation = expectedEndOfAnimation; 1148 Transform normalizedExpectedEndOfAnimation = expectedEndOfAnimation;
1105 Transform normalizationMatrix; 1149 Transform normalizationMatrix;
1106 normalizationMatrix.matrix().set( 1150 normalizationMatrix.matrix().set(
1107 0, 0, SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3, 3))); 1151 0.0,
1152 0.0,
1153 SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3.0, 3.0)));
1108 normalizationMatrix.matrix().set( 1154 normalizationMatrix.matrix().set(
1109 1, 1, SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3, 3))); 1155 1.0,
1156 1.0,
1157 SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3.0, 3.0)));
1110 normalizationMatrix.matrix().set( 1158 normalizationMatrix.matrix().set(
1111 2, 2, SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3, 3))); 1159 2.0,
1160 2.0,
1161 SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3.0, 3.0)));
1112 normalizationMatrix.matrix().set( 1162 normalizationMatrix.matrix().set(
1113 3, 3, SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3, 3))); 1163 3.0,
1164 3.0,
1165 SkDoubleToMScalar(1 / expectedEndOfAnimation.matrix().get(3.0, 3.0)));
1114 normalizedExpectedEndOfAnimation.PreconcatTransform(normalizationMatrix); 1166 normalizedExpectedEndOfAnimation.PreconcatTransform(normalizationMatrix);
1115 1167
1116 EXPECT_TRUE(MatricesAreNearlyEqual(normalizedExpectedEndOfAnimation, to)); 1168 EXPECT_TRUE(MatricesAreNearlyEqual(normalizedExpectedEndOfAnimation, to));
1117 } 1169 }
1118 1170
1119 TEST(XFormTest, DecomposedTransformCtor) 1171 TEST(XFormTest, DecomposedTransformCtor) {
1120 {
1121 DecomposedTransform decomp; 1172 DecomposedTransform decomp;
1122 for (int i = 0; i < 3; ++i) { 1173 for (int i = 0; i < 3; ++i) {
1123 EXPECT_EQ(0.0, decomp.translate[i]); 1174 EXPECT_EQ(0.0, decomp.translate[i]);
1124 EXPECT_EQ(1.0, decomp.scale[i]); 1175 EXPECT_EQ(1.0, decomp.scale[i]);
1125 EXPECT_EQ(0.0, decomp.skew[i]); 1176 EXPECT_EQ(0.0, decomp.skew[i]);
1126 EXPECT_EQ(0.0, decomp.quaternion[i]); 1177 EXPECT_EQ(0.0, decomp.quaternion[i]);
1127 EXPECT_EQ(0.0, decomp.perspective[i]); 1178 EXPECT_EQ(0.0, decomp.perspective[i]);
1128 } 1179 }
1129 EXPECT_EQ(1.0, decomp.quaternion[3]); 1180 EXPECT_EQ(1.0, decomp.quaternion[3]);
1130 EXPECT_EQ(1.0, decomp.perspective[3]); 1181 EXPECT_EQ(1.0, decomp.perspective[3]);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 1226
1176 transform.MakeIdentity(); 1227 transform.MakeIdentity();
1177 transform.Translate3d(0, -6.7, 0); 1228 transform.Translate3d(0, -6.7, 0);
1178 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation()); 1229 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation());
1179 1230
1180 transform.MakeIdentity(); 1231 transform.MakeIdentity();
1181 transform.Translate3d(0, 0, 8.9); 1232 transform.Translate3d(0, 0, 8.9);
1182 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation()); 1233 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation());
1183 } 1234 }
1184 1235
1185 TEST(XFormTest, verifyMatrixInversion) 1236 TEST(XFormTest, verifyMatrixInversion) {
1186 {
1187 { 1237 {
1188 // Invert a translation 1238 // Invert a translation
1189 gfx::Transform translation; 1239 gfx::Transform translation;
1190 translation.Translate3d(2, 3, 4); 1240 translation.Translate3d(2.0, 3.0, 4.0);
1191 EXPECT_TRUE(translation.IsInvertible()); 1241 EXPECT_TRUE(translation.IsInvertible());
1192 1242
1193 gfx::Transform inverse_translation; 1243 gfx::Transform inverse_translation;
1194 bool is_invertible = translation.GetInverse(&inverse_translation); 1244 bool is_invertible = translation.GetInverse(&inverse_translation);
1195 EXPECT_TRUE(is_invertible); 1245 EXPECT_TRUE(is_invertible);
1196 EXPECT_ROW1_EQ(1, 0, 0, -2, inverse_translation); 1246 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, -2.0, inverse_translation);
1197 EXPECT_ROW2_EQ(0, 1, 0, -3, inverse_translation); 1247 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, -3.0, inverse_translation);
1198 EXPECT_ROW3_EQ(0, 0, 1, -4, inverse_translation); 1248 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, -4.0, inverse_translation);
1199 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_translation); 1249 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, inverse_translation);
1200 } 1250 }
1201 1251
1202 { 1252 {
1203 // Invert a non-uniform scale 1253 // Invert a non-uniform scale
1204 gfx::Transform scale; 1254 gfx::Transform scale;
1205 scale.Scale3d(4, 10, 100); 1255 scale.Scale3d(4.0, 10.0, 100.0);
1206 EXPECT_TRUE(scale.IsInvertible()); 1256 EXPECT_TRUE(scale.IsInvertible());
1207 1257
1208 gfx::Transform inverse_scale; 1258 gfx::Transform inverse_scale;
1209 bool is_invertible = scale.GetInverse(&inverse_scale); 1259 bool is_invertible = scale.GetInverse(&inverse_scale);
1210 EXPECT_TRUE(is_invertible); 1260 EXPECT_TRUE(is_invertible);
1211 EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverse_scale); 1261 EXPECT_ROW1_EQ(0.25, 0.0, 0.0, 0.0, inverse_scale);
1212 EXPECT_ROW2_EQ(0, .1f, 0, 0, inverse_scale); 1262 EXPECT_ROW2_EQ(0.0, 0.1, 0.0, 0.0, inverse_scale);
1213 EXPECT_ROW3_EQ(0, 0, .01f, 0, inverse_scale); 1263 EXPECT_ROW3_EQ(0.0, 0.0, 0.01, 0.0, inverse_scale);
1214 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_scale); 1264 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, inverse_scale);
1215 } 1265 }
1216 1266
1217 { 1267 {
1218 // Try to invert a matrix that is not invertible. 1268 // Try to invert a matrix that is not invertible.
1219 // The inverse() function should reset the output matrix to identity. 1269 // The inverse() function should reset the output matrix to identity.
1220 gfx::Transform uninvertible; 1270 gfx::Transform uninvertible;
1221 uninvertible.matrix().setDouble(0, 0, 0); 1271 uninvertible.matrix().setDouble(0, 0, 0.0);
1222 uninvertible.matrix().setDouble(1, 1, 0); 1272 uninvertible.matrix().setDouble(1, 1, 0.0);
1223 uninvertible.matrix().setDouble(2, 2, 0); 1273 uninvertible.matrix().setDouble(2, 2, 0.0);
1224 uninvertible.matrix().setDouble(3, 3, 0); 1274 uninvertible.matrix().setDouble(3, 3, 0.0);
1225 EXPECT_FALSE(uninvertible.IsInvertible()); 1275 EXPECT_FALSE(uninvertible.IsInvertible());
1226 1276
1227 gfx::Transform inverse_of_uninvertible; 1277 gfx::Transform inverse_of_uninvertible;
1228 1278
1229 // Add a scale just to more easily ensure that inverse_of_uninvertible is 1279 // Add a scale just to more easily ensure that inverse_of_uninvertible is
1230 // reset to identity. 1280 // reset to identity.
1231 inverse_of_uninvertible.Scale3d(4, 10, 100); 1281 inverse_of_uninvertible.Scale3d(4.0, 10.0, 100.0);
1232 1282
1233 bool is_invertible = uninvertible.GetInverse(&inverse_of_uninvertible); 1283 bool is_invertible = uninvertible.GetInverse(&inverse_of_uninvertible);
1234 EXPECT_FALSE(is_invertible); 1284 EXPECT_FALSE(is_invertible);
1235 EXPECT_TRUE(inverse_of_uninvertible.IsIdentity()); 1285 EXPECT_TRUE(inverse_of_uninvertible.IsIdentity());
1236 EXPECT_ROW1_EQ(1, 0, 0, 0, inverse_of_uninvertible); 1286 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, inverse_of_uninvertible);
1237 EXPECT_ROW2_EQ(0, 1, 0, 0, inverse_of_uninvertible); 1287 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, inverse_of_uninvertible);
1238 EXPECT_ROW3_EQ(0, 0, 1, 0, inverse_of_uninvertible); 1288 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, inverse_of_uninvertible);
1239 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_of_uninvertible); 1289 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, inverse_of_uninvertible);
1240 } 1290 }
1241 } 1291 }
1242 1292
1293 TEST(XFormTest, verifyBackfaceVisibilityBasicCases) {
1294 Transform transform;
1295
1296 transform.MakeIdentity();
1297 EXPECT_FALSE(transform.IsBackFaceVisible());
1298
1299 transform.MakeIdentity();
1300 transform.RotateAboutYAxis(80.0);
1301 EXPECT_FALSE(transform.IsBackFaceVisible());
1302
1303 transform.MakeIdentity();
1304 transform.RotateAboutYAxis(100.0);
1305 EXPECT_TRUE(transform.IsBackFaceVisible());
1306
1307 // Edge case, 90 degree rotation should return false.
1308 transform.MakeIdentity();
1309 transform.RotateAboutYAxis(90.0);
1310 EXPECT_FALSE(transform.IsBackFaceVisible());
1311 }
1312
1313 TEST(XFormTest, verifyBackfaceVisibilityForPerspective) {
1314 Transform layer_space_to_projection_plane;
1315
1316 // This tests if IsBackFaceVisible works properly under perspective
1317 // transforms. Specifically, layers that may have their back face visible in
1318 // orthographic projection, may not actually have back face visible under
1319 // perspective projection.
1320
1321 // Case 1: Layer is rotated by slightly more than 90 degrees, at the center
1322 // of the prespective projection. In this case, the layer's back-side
1323 // is visible to the camera.
1324 layer_space_to_projection_plane.MakeIdentity();
1325 layer_space_to_projection_plane.ApplyPerspectiveDepth(1.0);
1326 layer_space_to_projection_plane.Translate3d(0.0, 0.0, 0.0);
1327 layer_space_to_projection_plane.RotateAboutYAxis(100.0);
1328 EXPECT_TRUE(layer_space_to_projection_plane.IsBackFaceVisible());
1329
1330 // Case 2: Layer is rotated by slightly more than 90 degrees, but shifted off
1331 // to the side of the camera. Because of the wide field-of-view, the
1332 // layer's front side is still visible.
1333 //
1334 // |<-- front side of layer is visible to camera
1335 // \ | /
1336 // \ | /
1337 // \| /
1338 // | /
1339 // |\ /<-- camera field of view
1340 // | \ /
1341 // back side of layer -->| \ /
1342 // \./ <-- camera origin
1343 //
1344 layer_space_to_projection_plane.MakeIdentity();
1345 layer_space_to_projection_plane.ApplyPerspectiveDepth(1.0);
1346 layer_space_to_projection_plane.Translate3d(-10.0, 0.0, 0.0);
1347 layer_space_to_projection_plane.RotateAboutYAxis(100.0);
1348 EXPECT_FALSE(layer_space_to_projection_plane.IsBackFaceVisible());
1349
1350 // Case 3: Additionally rotating the layer by 180 degrees should of course
1351 // show the opposite result of case 2.
1352 layer_space_to_projection_plane.RotateAboutYAxis(180.0);
1353 EXPECT_TRUE(layer_space_to_projection_plane.IsBackFaceVisible());
1354 }
1355
1356 TEST(XFormTest, verifyDefaultConstructorCreatesIdentityMatrix) {
1357 Transform A;
1358 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, A);
1359 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, A);
1360 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1361 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1362 EXPECT_TRUE(A.IsIdentity());
1363 }
1364
1365 TEST(XFormTest, verifyCopyConstructor) {
1366 Transform A;
1367 InitializeTestMatrix(&A);
1368
1369 // Copy constructor should produce exact same elements as matrix A.
1370 Transform B(A);
1371 EXPECT_ROW1_EQ(10.0, 14.0, 18.0, 22.0, B);
1372 EXPECT_ROW2_EQ(11.0, 15.0, 19.0, 23.0, B);
1373 EXPECT_ROW3_EQ(12.0, 16.0, 20.0, 24.0, B);
1374 EXPECT_ROW4_EQ(13.0, 17.0, 21.0, 25.0, B);
1375 }
1376
1377 TEST(XFormTest, verifyConstructorFor16Elements) {
1378 Transform transform(1.0, 2.0, 3.0, 4.0,
1379 5.0, 6.0, 7.0, 8.0,
1380 9.0, 10.0, 11.0, 12.0,
1381 13.0, 14.0, 15.0, 16.0);
1382
1383 EXPECT_ROW1_EQ(1.0, 2.0, 3.0, 4.0, transform);
1384 EXPECT_ROW2_EQ(5.0, 6.0, 7.0, 8.0, transform);
1385 EXPECT_ROW3_EQ(9.0, 10.0, 11.0, 12.0, transform);
1386 EXPECT_ROW4_EQ(13.0, 14.0, 15.0, 16.0, transform);
1387 }
1388
1389 TEST(XFormTest, verifyConstructorFor2dElements) {
1390 Transform transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
1391
1392 EXPECT_ROW1_EQ(1.0, 2.0, 0.0, 5.0, transform);
1393 EXPECT_ROW2_EQ(3.0, 4.0, 0.0, 6.0, transform);
1394 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, transform);
1395 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, transform);
1396 }
1397
1398
1399 TEST(XFormTest, verifyAssignmentOperator) {
1400 Transform A;
1401 InitializeTestMatrix(&A);
1402 Transform B;
1403 InitializeTestMatrix2(&B);
1404 Transform C;
1405 InitializeTestMatrix2(&C);
1406 C = B = A;
1407
1408 // Both B and C should now have been re-assigned to the value of A.
1409 EXPECT_ROW1_EQ(10.0, 14.0, 18.0, 22.0, B);
1410 EXPECT_ROW2_EQ(11.0, 15.0, 19.0, 23.0, B);
1411 EXPECT_ROW3_EQ(12.0, 16.0, 20.0, 24.0, B);
1412 EXPECT_ROW4_EQ(13.0, 17.0, 21.0, 25.0, B);
1413
1414 EXPECT_ROW1_EQ(10.0, 14.0, 18.0, 22.0, C);
1415 EXPECT_ROW2_EQ(11.0, 15.0, 19.0, 23.0, C);
1416 EXPECT_ROW3_EQ(12.0, 16.0, 20.0, 24.0, C);
1417 EXPECT_ROW4_EQ(13.0, 17.0, 21.0, 25.0, C);
1418 }
1419
1420 TEST(XFormTest, verifyEqualsBooleanOperator) {
1421 Transform A;
1422 InitializeTestMatrix(&A);
1423
1424 Transform B;
1425 InitializeTestMatrix(&B);
1426 EXPECT_TRUE(A == B);
1427
1428 // Modifying multiple elements should cause equals operator to return false.
1429 Transform C;
1430 InitializeTestMatrix2(&C);
1431 EXPECT_FALSE(A == C);
1432
1433 // Modifying any one individual element should cause equals operator to
1434 // return false.
1435 Transform D;
1436 D = A;
1437 D.matrix().setDouble(0, 0, 0.0);
1438 EXPECT_FALSE(A == D);
1439
1440 D = A;
1441 D.matrix().setDouble(1, 0, 0.0);
1442 EXPECT_FALSE(A == D);
1443
1444 D = A;
1445 D.matrix().setDouble(2, 0, 0.0);
1446 EXPECT_FALSE(A == D);
1447
1448 D = A;
1449 D.matrix().setDouble(3, 0, 0.0);
1450 EXPECT_FALSE(A == D);
1451
1452 D = A;
1453 D.matrix().setDouble(0, 1, 0.0);
1454 EXPECT_FALSE(A == D);
1455
1456 D = A;
1457 D.matrix().setDouble(1, 1, 0.0);
1458 EXPECT_FALSE(A == D);
1459
1460 D = A;
1461 D.matrix().setDouble(2, 1, 0.0);
1462 EXPECT_FALSE(A == D);
1463
1464 D = A;
1465 D.matrix().setDouble(3, 1, 0.0);
1466 EXPECT_FALSE(A == D);
1467
1468 D = A;
1469 D.matrix().setDouble(0, 2, 0.0);
1470 EXPECT_FALSE(A == D);
1471
1472 D = A;
1473 D.matrix().setDouble(1, 2, 0.0);
1474 EXPECT_FALSE(A == D);
1475
1476 D = A;
1477 D.matrix().setDouble(2, 2, 0.0);
1478 EXPECT_FALSE(A == D);
1479
1480 D = A;
1481 D.matrix().setDouble(3, 2, 0.0);
1482 EXPECT_FALSE(A == D);
1483
1484 D = A;
1485 D.matrix().setDouble(0, 3, 0.0);
1486 EXPECT_FALSE(A == D);
1487
1488 D = A;
1489 D.matrix().setDouble(1, 3, 0.0);
1490 EXPECT_FALSE(A == D);
1491
1492 D = A;
1493 D.matrix().setDouble(2, 3, 0.0);
1494 EXPECT_FALSE(A == D);
1495
1496 D = A;
1497 D.matrix().setDouble(3, 3, 0.0);
1498 EXPECT_FALSE(A == D);
1499 }
1500
1501 TEST(XFormTest, verifyMultiplyOperator) {
1502 Transform A;
1503 InitializeTestMatrix(&A);
1504
1505 Transform B;
1506 InitializeTestMatrix2(&B);
1507
1508 Transform C = A * B;
1509 EXPECT_ROW1_EQ(2036.0, 2292.0, 2548.0, 2804.0, C);
1510 EXPECT_ROW2_EQ(2162.0, 2434.0, 2706.0, 2978.0, C);
1511 EXPECT_ROW3_EQ(2288.0, 2576.0, 2864.0, 3152.0, C);
1512 EXPECT_ROW4_EQ(2414.0, 2718.0, 3022.0, 3326.0, C);
1513
1514 // Just an additional sanity check; matrix multiplication is not commutative.
1515 EXPECT_FALSE(A * B == B * A);
1516 }
1517
1518 TEST(XFormTest, verifyMultiplyAndAssignOperator) {
1519 Transform A;
1520 InitializeTestMatrix(&A);
1521
1522 Transform B;
1523 InitializeTestMatrix2(&B);
1524
1525 A *= B;
1526 EXPECT_ROW1_EQ(2036.0, 2292.0, 2548.0, 2804.0, A);
1527 EXPECT_ROW2_EQ(2162.0, 2434.0, 2706.0, 2978.0, A);
1528 EXPECT_ROW3_EQ(2288.0, 2576.0, 2864.0, 3152.0, A);
1529 EXPECT_ROW4_EQ(2414.0, 2718.0, 3022.0, 3326.0, A);
1530
1531 // Just an additional sanity check; matrix multiplication is not commutative.
1532 Transform C = A;
1533 C *= B;
1534 Transform D = B;
1535 D *= A;
1536 EXPECT_FALSE(C == D);
1537 }
1538
1539 TEST(XFormTest, verifyMatrixMultiplication) {
1540 Transform A;
1541 InitializeTestMatrix(&A);
1542
1543 Transform B;
1544 InitializeTestMatrix2(&B);
1545
1546 A.PreconcatTransform(B);
1547 EXPECT_ROW1_EQ(2036.0, 2292.0, 2548.0, 2804.0, A);
1548 EXPECT_ROW2_EQ(2162.0, 2434.0, 2706.0, 2978.0, A);
1549 EXPECT_ROW3_EQ(2288.0, 2576.0, 2864.0, 3152.0, A);
1550 EXPECT_ROW4_EQ(2414.0, 2718.0, 3022.0, 3326.0, A);
1551 }
1552
1553 TEST(XFormTest, verifyMakeIdentiy) {
1554 Transform A;
1555 InitializeTestMatrix(&A);
1556 A.MakeIdentity();
1557 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, A);
1558 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, A);
1559 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1560 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1561 EXPECT_TRUE(A.IsIdentity());
1562 }
1563
1564 TEST(XFormTest, verifyTranslate) {
1565 Transform A;
1566 A.Translate(2.0, 3.0);
1567 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 2.0, A);
1568 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 3.0, A);
1569 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1570 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1571
1572 // Verify that Translate() post-multiplies the existing matrix.
1573 A.MakeIdentity();
1574 A.Scale(5.0, 5.0);
1575 A.Translate(2.0, 3.0);
1576 EXPECT_ROW1_EQ(5.0, 0.0, 0.0, 10.0, A);
1577 EXPECT_ROW2_EQ(0.0, 5.0, 0.0, 15.0, A);
1578 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1579 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1580 }
1581
1582 TEST(XFormTest, verifyTranslate3d) {
1583 Transform A;
1584 A.Translate3d(2.0, 3.0, 4.0);
1585 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 2.0, A);
1586 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 3.0, A);
1587 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 4.0, A);
1588 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1589
1590 // Verify that Translate3d() post-multiplies the existing matrix.
1591 A.MakeIdentity();
1592 A.Scale3d(6.0, 7.0, 8.0);
1593 A.Translate3d(2.0, 3.0, 4.0);
1594 EXPECT_ROW1_EQ(6.0, 0.0, 0.0, 12.0, A);
1595 EXPECT_ROW2_EQ(0.0, 7.0, 0.0, 21.0, A);
1596 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 32.0, A);
1597 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1598 }
1599
1600 TEST(XFormTest, verifyScale) {
1601 Transform A;
1602 A.Scale(6.0, 7.0);
1603 EXPECT_ROW1_EQ(6.0, 0.0, 0.0, 0.0, A);
1604 EXPECT_ROW2_EQ(0.0, 7.0, 0.0, 0.0, A);
1605 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1606 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1607
1608 // Verify that Scale() post-multiplies the existing matrix.
1609 A.MakeIdentity();
1610 A.Translate3d(2.0, 3.0, 4.0);
1611 A.Scale(6.0, 7.0);
1612 EXPECT_ROW1_EQ(6.0, 0.0, 0.0, 2.0, A);
1613 EXPECT_ROW2_EQ(0.0, 7.0, 0.0, 3.0, A);
1614 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 4.0, A);
1615 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1616 }
1617
1618 TEST(XFormTest, verifyScale3d) {
1619 Transform A;
1620 A.Scale3d(6.0, 7.0, 8.0);
1621 EXPECT_ROW1_EQ(6.0, 0.0, 0.0, 0.0, A);
1622 EXPECT_ROW2_EQ(0.0, 7.0, 0.0, 0.0, A);
1623 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 0.0, A);
1624 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1625
1626 // Verify that scale3d() post-multiplies the existing matrix.
1627 A.MakeIdentity();
1628 A.Translate3d(2.0, 3.0, 4.0);
1629 A.Scale3d(6.0, 7.0, 8.0);
1630 EXPECT_ROW1_EQ(6.0, 0.0, 0.0, 2.0, A);
1631 EXPECT_ROW2_EQ(0.0, 7.0, 0.0, 3.0, A);
1632 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 4.0, A);
1633 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1634 }
1635
1636 TEST(XFormTest, verifyRotate) {
1637 Transform A;
1638 A.Rotate(90.0);
1639 EXPECT_ROW1_NEAR(0.0, -1.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1640 EXPECT_ROW2_NEAR(1.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1641 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1642 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1643
1644 // Verify that Rotate() post-multiplies the existing matrix.
1645 A.MakeIdentity();
1646 A.Scale3d(6.0, 7.0, 8.0);
1647 A.Rotate(90.0);
1648 EXPECT_ROW1_NEAR(0.0, -6.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1649 EXPECT_ROW2_NEAR(7.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1650 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 0.0, A);
1651 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1652 }
1653
1654 TEST(XFormTest, verifyRotateAboutXAxis) {
1655 Transform A;
1656 double sin45 = 0.5 * sqrt(2.0);
1657 double cos45 = sin45;
1658
1659 A.MakeIdentity();
1660 A.RotateAboutXAxis(90.0);
1661 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, A);
1662 EXPECT_ROW2_NEAR(0.0, 0.0, -1.0, 0.0, A, ERROR_THRESHOLD);
1663 EXPECT_ROW3_NEAR(0.0, 1.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1664 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1665
1666 A.MakeIdentity();
1667 A.RotateAboutXAxis(45.0);
1668 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, A);
1669 EXPECT_ROW2_NEAR(0.0, cos45, -sin45, 0.0, A, ERROR_THRESHOLD);
1670 EXPECT_ROW3_NEAR(0.0, sin45, cos45, 0.0, A, ERROR_THRESHOLD);
1671 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1672
1673 // Verify that RotateAboutXAxis(angle) post-multiplies the existing matrix.
1674 A.MakeIdentity();
1675 A.Scale3d(6.0, 7.0, 8.0);
1676 A.RotateAboutXAxis(90.0);
1677 EXPECT_ROW1_NEAR(6.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1678 EXPECT_ROW2_NEAR(0.0, 0.0, -7.0, 0.0, A, ERROR_THRESHOLD);
1679 EXPECT_ROW3_NEAR(0.0, 8.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1680 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1681 }
1682
1683 TEST(XFormTest, verifyRotateAboutYAxis) {
1684 Transform A;
1685 double sin45 = 0.5 * sqrt(2.0);
1686 double cos45 = sin45;
1687
1688 // Note carefully, the expected pattern is inverted compared to rotating
1689 // about x axis or z axis.
1690 A.MakeIdentity();
1691 A.RotateAboutYAxis(90.0);
1692 EXPECT_ROW1_NEAR(0.0, 0.0, 1.0, 0.0, A, ERROR_THRESHOLD);
1693 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, A);
1694 EXPECT_ROW3_NEAR(-1.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1695 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1696
1697 A.MakeIdentity();
1698 A.RotateAboutYAxis(45.0);
1699 EXPECT_ROW1_NEAR(cos45, 0.0, sin45, 0.0, A, ERROR_THRESHOLD);
1700 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, A);
1701 EXPECT_ROW3_NEAR(-sin45, 0.0, cos45, 0.0, A, ERROR_THRESHOLD);
1702 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1703
1704 // Verify that RotateAboutYAxis(angle) post-multiplies the existing matrix.
1705 A.MakeIdentity();
1706 A.Scale3d(6.0, 7.0, 8.0);
1707 A.RotateAboutYAxis(90.0);
1708 EXPECT_ROW1_NEAR(0.0, 0.0, 6.0, 0.0, A, ERROR_THRESHOLD);
1709 EXPECT_ROW2_NEAR(0.0, 7.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1710 EXPECT_ROW3_NEAR(-8.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1711 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1712 }
1713
1714 TEST(XFormTest, verifyRotateAboutZAxis) {
1715 Transform A;
1716 double sin45 = 0.5 * sqrt(2.0);
1717 double cos45 = sin45;
1718
1719 A.MakeIdentity();
1720 A.RotateAboutZAxis(90.0);
1721 EXPECT_ROW1_NEAR(0.0, -1.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1722 EXPECT_ROW2_NEAR(1.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1723 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1724 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1725
1726 A.MakeIdentity();
1727 A.RotateAboutZAxis(45.0);
1728 EXPECT_ROW1_NEAR(cos45, -sin45, 0.0, 0.0, A, ERROR_THRESHOLD);
1729 EXPECT_ROW2_NEAR(sin45, cos45, 0.0, 0.0, A, ERROR_THRESHOLD);
1730 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1731 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1732
1733 // Verify that RotateAboutZAxis(angle) post-multiplies the existing matrix.
1734 A.MakeIdentity();
1735 A.Scale3d(6.0, 7.0, 8.0);
1736 A.RotateAboutZAxis(90.0);
1737 EXPECT_ROW1_NEAR(0.0, -6.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1738 EXPECT_ROW2_NEAR(7.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1739 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 0.0, A);
1740 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1741 }
1742
1743 TEST(XFormTest, verifyRotateAboutForAlignedAxes) {
1744 Transform A;
1745
1746 // Check rotation about z-axis
1747 A.MakeIdentity();
1748 A.RotateAbout(Vector3dF(0.0, 0.0, 1.0), 90.0);
1749 EXPECT_ROW1_NEAR(0.0, -1.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1750 EXPECT_ROW2_NEAR(1.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1751 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1752 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1753
1754 // Check rotation about x-axis
1755 A.MakeIdentity();
1756 A.RotateAbout(Vector3dF(1.0, 0.0, 0.0), 90.0);
1757 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, A);
1758 EXPECT_ROW2_NEAR(0.0, 0.0, -1.0, 0.0, A, ERROR_THRESHOLD);
1759 EXPECT_ROW3_NEAR(0.0, 1.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1760 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1761
1762 // Check rotation about y-axis. Note carefully, the expected pattern is
1763 // inverted compared to rotating about x axis or z axis.
1764 A.MakeIdentity();
1765 A.RotateAbout(Vector3dF(0.0, 1.0, 0.0), 90.0);
1766 EXPECT_ROW1_NEAR(0.0, 0.0, 1.0, 0.0, A, ERROR_THRESHOLD);
1767 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, A);
1768 EXPECT_ROW3_NEAR(-1.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1769 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1770
1771 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix.
1772 A.MakeIdentity();
1773 A.Scale3d(6.0, 7.0, 8.0);
1774 A.RotateAboutZAxis(90.0);
1775 EXPECT_ROW1_NEAR(0.0, -6.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1776 EXPECT_ROW2_NEAR(7.0, 0.0, 0.0, 0.0, A, ERROR_THRESHOLD);
1777 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 0.0, A);
1778 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1779 }
1780
1781 TEST(XFormTest, verifyRotateAboutForArbitraryAxis) {
1782 // Check rotation about an arbitrary non-axis-aligned vector.
1783 Transform A;
1784 A.RotateAbout(Vector3dF(1.0, 1.0, 1.0), 90.0);
1785 EXPECT_ROW1_NEAR(0.3333333333333334258519187,
1786 -0.2440169358562924717404030,
1787 0.9106836025229592124219380,
1788 0.0, A, ERROR_THRESHOLD);
1789 EXPECT_ROW2_NEAR(0.9106836025229592124219380,
1790 0.3333333333333334258519187,
1791 -0.2440169358562924717404030,
1792 0.0, A, ERROR_THRESHOLD);
1793 EXPECT_ROW3_NEAR(-0.2440169358562924717404030,
1794 0.9106836025229592124219380,
1795 0.3333333333333334258519187,
1796 0.0, A, ERROR_THRESHOLD);
1797 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1798 }
1799
1800 TEST(XFormTest, verifyRotateAboutForDegenerateAxis) {
1801 // Check rotation about a degenerate zero vector.
1802 // It is expected to skip applying the rotation.
1803 Transform A;
1804
1805 A.RotateAbout(Vector3dF(0.0, 0.0, 0.0), 45.0);
1806 // Verify that A remains unchanged.
1807 EXPECT_TRUE(A.IsIdentity());
1808
1809 InitializeTestMatrix(&A);
1810 A.RotateAbout(Vector3dF(0.0, 0.0, 0.0), 35.0);
1811
1812 // Verify that A remains unchanged.
1813 EXPECT_ROW1_EQ(10.0, 14.0, 18.0, 22.0, A);
1814 EXPECT_ROW2_EQ(11.0, 15.0, 19.0, 23.0, A);
1815 EXPECT_ROW3_EQ(12.0, 16.0, 20.0, 24.0, A);
1816 EXPECT_ROW4_EQ(13.0, 17.0, 21.0, 25.0, A);
1817 }
1818
1819 TEST(XFormTest, verifySkewX) {
1820 Transform A;
1821 A.SkewX(45.0);
1822 EXPECT_ROW1_EQ(1.0, 1.0, 0.0, 0.0, A);
1823 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, A);
1824 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1825 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1826
1827 // Verify that skewX() post-multiplies the existing matrix. Row 1, column 2,
1828 // would incorrectly have value "7" if the matrix is pre-multiplied instead
1829 // of post-multiplied.
1830 A.MakeIdentity();
1831 A.Scale3d(6.0, 7.0, 8.0);
1832 A.SkewX(45.0);
1833 EXPECT_ROW1_EQ(6.0, 6.0, 0.0, 0.0, A);
1834 EXPECT_ROW2_EQ(0.0, 7.0, 0.0, 0.0, A);
1835 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 0.0, A);
1836 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1837 }
1838
1839 TEST(XFormTest, verifySkewY) {
1840 Transform A;
1841 A.SkewY(45.0);
1842 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, A);
1843 EXPECT_ROW2_EQ(1.0, 1.0, 0.0, 0.0, A);
1844 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1845 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1846
1847 // Verify that skewY() post-multiplies the existing matrix. Row 2, column 1 ,
1848 // would incorrectly have value "6" if the matrix is pre-multiplied instead
1849 // of post-multiplied.
1850 A.MakeIdentity();
1851 A.Scale3d(6.0, 7.0, 8.0);
1852 A.SkewY(45.0);
1853 EXPECT_ROW1_EQ(6.0, 0.0, 0.0, 0.0, A);
1854 EXPECT_ROW2_EQ(7.0, 7.0, 0.0, 0.0, A);
1855 EXPECT_ROW3_EQ(0.0, 0.0, 8.0, 0.0, A);
1856 EXPECT_ROW4_EQ(0.0, 0.0, 0.0, 1.0, A);
1857 }
1858
1859 TEST(XFormTest, verifyPerspectiveDepth) {
1860 Transform A;
1861 A.ApplyPerspectiveDepth(1.0);
1862 EXPECT_ROW1_EQ(1.0, 0.0, 0.0, 0.0, A);
1863 EXPECT_ROW2_EQ(0.0, 1.0, 0.0, 0.0, A);
1864 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
1865 EXPECT_ROW4_EQ(0.0, 0.0, -1.0, 1.0, A);
1866
1867 // Verify that PerspectiveDepth() post-multiplies the existing matrix.
1868 A.MakeIdentity();
1869 A.Translate3d(2.0, 3.0, 4.0);
1870 A.ApplyPerspectiveDepth(1.0);
1871 EXPECT_ROW1_EQ(1.0, 0.0, -2.0, 2.0, A);
1872 EXPECT_ROW2_EQ(0.0, 1.0, -3.0, 3.0, A);
1873 EXPECT_ROW3_EQ(0.0, 0.0, -3.0, 4.0, A);
1874 EXPECT_ROW4_EQ(0.0, 0.0, -1.0, 1.0, A);
1875 }
1876
1877 TEST(XFormTest, verifyHasPerspective) {
1878 Transform A;
1879 A.ApplyPerspectiveDepth(1.0);
1880 EXPECT_TRUE(A.HasPerspective());
1881
1882 A.MakeIdentity();
1883 A.ApplyPerspectiveDepth(0.0);
1884 EXPECT_FALSE(A.HasPerspective());
1885
1886 A.MakeIdentity();
1887 A.matrix().setDouble(3, 0, -1.0);
1888 EXPECT_TRUE(A.HasPerspective());
1889
1890 A.MakeIdentity();
1891 A.matrix().setDouble(3, 1, -1.0);
1892 EXPECT_TRUE(A.HasPerspective());
1893
1894 A.MakeIdentity();
1895 A.matrix().setDouble(3, 2, -0.3);
1896 EXPECT_TRUE(A.HasPerspective());
1897
1898 A.MakeIdentity();
1899 A.matrix().setDouble(3, 3, 0.5);
1900 EXPECT_TRUE(A.HasPerspective());
1901
1902 A.MakeIdentity();
1903 A.matrix().setDouble(3, 3, 0.0);
1904 EXPECT_TRUE(A.HasPerspective());
1905 }
1906
1907 TEST(XFormTest, verifyIsInvertible) {
1908 Transform A;
1909
1910 // Translations, rotations, scales, skews and arbitrary combinations of them
1911 // are invertible.
1912 A.MakeIdentity();
1913 EXPECT_TRUE(A.IsInvertible());
1914
1915 A.MakeIdentity();
1916 A.Translate3d(2.0, 3.0, 4.0);
1917 EXPECT_TRUE(A.IsInvertible());
1918
1919 A.MakeIdentity();
1920 A.Scale3d(6.0, 7.0, 8.0);
1921 EXPECT_TRUE(A.IsInvertible());
1922
1923 A.MakeIdentity();
1924 A.RotateAboutXAxis(10.0);
1925 A.RotateAboutYAxis(20.0);
1926 A.RotateAboutZAxis(30.0);
1927 EXPECT_TRUE(A.IsInvertible());
1928
1929 A.MakeIdentity();
1930 A.SkewX(45.0);
1931 EXPECT_TRUE(A.IsInvertible());
1932
1933 // A perspective matrix (projection plane at z=0) is invertible. The
1934 // intuitive explanation is that perspective is eqivalent to a skew of the
1935 // w-axis; skews are invertible.
1936 A.MakeIdentity();
1937 A.ApplyPerspectiveDepth(1.0);
1938 EXPECT_TRUE(A.IsInvertible());
1939
1940 // A "pure" perspective matrix derived by similar triangles, with m44() set
1941 // to zero (i.e. camera positioned at the origin), is not invertible.
1942 A.MakeIdentity();
1943 A.ApplyPerspectiveDepth(1.0);
1944 A.matrix().setDouble(3, 3, 0.0);
1945 EXPECT_FALSE(A.IsInvertible());
1946
1947 // Adding more to a non-invertible matrix will not make it invertible in the
1948 // general case.
1949 A.MakeIdentity();
1950 A.ApplyPerspectiveDepth(1.0);
1951 A.matrix().setDouble(3, 3, 0.0);
1952 A.Scale3d(6.0, 7.0, 8.0);
1953 A.RotateAboutXAxis(10.0);
1954 A.RotateAboutYAxis(20.0);
1955 A.RotateAboutZAxis(30.0);
1956 A.Translate3d(6.0, 7.0, 8.0);
1957 EXPECT_FALSE(A.IsInvertible());
1958
1959 // A degenerate matrix of all zeros is not invertible.
1960 A.MakeIdentity();
1961 A.matrix().setDouble(0, 0, 0.0);
1962 A.matrix().setDouble(1, 1, 0.0);
1963 A.matrix().setDouble(2, 2, 0.0);
1964 A.matrix().setDouble(3, 3, 0.0);
1965 EXPECT_FALSE(A.IsInvertible());
1966 }
1967
1968 TEST(XFormTest, verifyIsIdentity) {
1969 Transform A;
1970
1971 InitializeTestMatrix(&A);
1972 EXPECT_FALSE(A.IsIdentity());
1973
1974 A.MakeIdentity();
1975 EXPECT_TRUE(A.IsIdentity());
1976
1977 // Modifying any one individual element should cause the matrix to no longer
1978 // be identity.
1979 A.MakeIdentity();
1980 A.matrix().setDouble(0, 0, 2.0);
1981 EXPECT_FALSE(A.IsIdentity());
1982
1983 A.MakeIdentity();
1984 A.matrix().setDouble(1, 0, 2.0);
1985 EXPECT_FALSE(A.IsIdentity());
1986
1987 A.MakeIdentity();
1988 A.matrix().setDouble(2, 0, 2.0);
1989 EXPECT_FALSE(A.IsIdentity());
1990
1991 A.MakeIdentity();
1992 A.matrix().setDouble(3, 0, 2.0);
1993 EXPECT_FALSE(A.IsIdentity());
1994
1995 A.MakeIdentity();
1996 A.matrix().setDouble(0, 1, 2.0);
1997 EXPECT_FALSE(A.IsIdentity());
1998
1999 A.MakeIdentity();
2000 A.matrix().setDouble(1, 1, 2.0);
2001 EXPECT_FALSE(A.IsIdentity());
2002
2003 A.MakeIdentity();
2004 A.matrix().setDouble(2, 1, 2.0);
2005 EXPECT_FALSE(A.IsIdentity());
2006
2007 A.MakeIdentity();
2008 A.matrix().setDouble(3, 1, 2.0);
2009 EXPECT_FALSE(A.IsIdentity());
2010
2011 A.MakeIdentity();
2012 A.matrix().setDouble(0, 2, 2.0);
2013 EXPECT_FALSE(A.IsIdentity());
2014
2015 A.MakeIdentity();
2016 A.matrix().setDouble(1, 2, 2.0);
2017 EXPECT_FALSE(A.IsIdentity());
2018
2019 A.MakeIdentity();
2020 A.matrix().setDouble(2, 2, 2.0);
2021 EXPECT_FALSE(A.IsIdentity());
2022
2023 A.MakeIdentity();
2024 A.matrix().setDouble(3, 2, 2.0);
2025 EXPECT_FALSE(A.IsIdentity());
2026
2027 A.MakeIdentity();
2028 A.matrix().setDouble(0, 3, 2.0);
2029 EXPECT_FALSE(A.IsIdentity());
2030
2031 A.MakeIdentity();
2032 A.matrix().setDouble(1, 3, 2.0);
2033 EXPECT_FALSE(A.IsIdentity());
2034
2035 A.MakeIdentity();
2036 A.matrix().setDouble(2, 3, 2.0);
2037 EXPECT_FALSE(A.IsIdentity());
2038
2039 A.MakeIdentity();
2040 A.matrix().setDouble(3, 3, 2.0);
2041 EXPECT_FALSE(A.IsIdentity());
2042 }
2043
2044 TEST(XFormTest, verifyIsIdentityOrTranslation) {
2045 Transform A;
2046
2047 InitializeTestMatrix(&A);
2048 EXPECT_FALSE(A.IsIdentityOrTranslation());
2049
2050 A.MakeIdentity();
2051 EXPECT_TRUE(A.IsIdentityOrTranslation());
2052
2053 // Modifying any non-translation components should cause
2054 // IsIdentityOrTranslation() to return false. NOTE: (0, 3), (1, 3), and
2055 // (2, 3) are the translation components, so modifying them should still
2056 // return true.
2057 A.MakeIdentity();
2058 A.matrix().setDouble(0, 0, 2.0);
2059 EXPECT_FALSE(A.IsIdentityOrTranslation());
2060
2061 A.MakeIdentity();
2062 A.matrix().setDouble(1, 0, 2.0);
2063 EXPECT_FALSE(A.IsIdentityOrTranslation());
2064
2065 A.MakeIdentity();
2066 A.matrix().setDouble(2, 0, 2.0);
2067 EXPECT_FALSE(A.IsIdentityOrTranslation());
2068
2069 A.MakeIdentity();
2070 A.matrix().setDouble(3, 0, 2.0);
2071 EXPECT_FALSE(A.IsIdentityOrTranslation());
2072
2073 A.MakeIdentity();
2074 A.matrix().setDouble(0, 1, 2.0);
2075 EXPECT_FALSE(A.IsIdentityOrTranslation());
2076
2077 A.MakeIdentity();
2078 A.matrix().setDouble(1, 1, 2.0);
2079 EXPECT_FALSE(A.IsIdentityOrTranslation());
2080
2081 A.MakeIdentity();
2082 A.matrix().setDouble(2, 1, 2.0);
2083 EXPECT_FALSE(A.IsIdentityOrTranslation());
2084
2085 A.MakeIdentity();
2086 A.matrix().setDouble(3, 1, 2.0);
2087 EXPECT_FALSE(A.IsIdentityOrTranslation());
2088
2089 A.MakeIdentity();
2090 A.matrix().setDouble(0, 2, 2.0);
2091 EXPECT_FALSE(A.IsIdentityOrTranslation());
2092
2093 A.MakeIdentity();
2094 A.matrix().setDouble(1, 2, 2.0);
2095 EXPECT_FALSE(A.IsIdentityOrTranslation());
2096
2097 A.MakeIdentity();
2098 A.matrix().setDouble(2, 2, 2.0);
2099 EXPECT_FALSE(A.IsIdentityOrTranslation());
2100
2101 A.MakeIdentity();
2102 A.matrix().setDouble(3, 2, 2.0);
2103 EXPECT_FALSE(A.IsIdentityOrTranslation());
2104
2105 // Note carefully - expecting true here.
2106 A.MakeIdentity();
2107 A.matrix().setDouble(0, 3, 2.0);
2108 EXPECT_TRUE(A.IsIdentityOrTranslation());
2109
2110 // Note carefully - expecting true here.
2111 A.MakeIdentity();
2112 A.matrix().setDouble(1, 3, 2.0);
2113 EXPECT_TRUE(A.IsIdentityOrTranslation());
2114
2115 // Note carefully - expecting true here.
2116 A.MakeIdentity();
2117 A.matrix().setDouble(2, 3, 2.0);
2118 EXPECT_TRUE(A.IsIdentityOrTranslation());
2119
2120 A.MakeIdentity();
2121 A.matrix().setDouble(3, 3, 2.0);
2122 EXPECT_FALSE(A.IsIdentityOrTranslation());
2123 }
2124
2125 TEST(XFormTest, verifyIsScaleOrTranslation) {
2126 Transform A;
2127
2128 InitializeTestMatrix(&A);
2129 EXPECT_FALSE(A.IsScaleOrTranslation());
2130
2131 A.MakeIdentity();
2132 EXPECT_TRUE(A.IsScaleOrTranslation());
2133
2134 // Modifying any non-scale or non-translation components should cause
2135 // IsScaleOrTranslation() to return false. (0, 0), (1, 1), (2, 2), (0, 3),
2136 // (1, 3), and (2, 3) are the scale and translation components, so
2137 // modifying them should still return true.
2138
2139 // Note carefully - expecting true here.
2140 A.MakeIdentity();
2141 A.matrix().setDouble(0, 0, 2.0);
2142 EXPECT_TRUE(A.IsScaleOrTranslation());
2143
2144 A.MakeIdentity();
2145 A.matrix().setDouble(1, 0, 2.0);
2146 EXPECT_FALSE(A.IsScaleOrTranslation());
2147
2148 A.MakeIdentity();
2149 A.matrix().setDouble(2, 0, 2.0);
2150 EXPECT_FALSE(A.IsScaleOrTranslation());
2151
2152 A.MakeIdentity();
2153 A.matrix().setDouble(3, 0, 2.0);
2154 EXPECT_FALSE(A.IsScaleOrTranslation());
2155
2156 A.MakeIdentity();
2157 A.matrix().setDouble(0, 1, 2.0);
2158 EXPECT_FALSE(A.IsScaleOrTranslation());
2159
2160 // Note carefully - expecting true here.
2161 A.MakeIdentity();
2162 A.matrix().setDouble(1, 1, 2.0);
2163 EXPECT_TRUE(A.IsScaleOrTranslation());
2164
2165 A.MakeIdentity();
2166 A.matrix().setDouble(2, 1, 2.0);
2167 EXPECT_FALSE(A.IsScaleOrTranslation());
2168
2169 A.MakeIdentity();
2170 A.matrix().setDouble(3, 1, 2.0);
2171 EXPECT_FALSE(A.IsScaleOrTranslation());
2172
2173 A.MakeIdentity();
2174 A.matrix().setDouble(0, 2, 2.0);
2175 EXPECT_FALSE(A.IsScaleOrTranslation());
2176
2177 A.MakeIdentity();
2178 A.matrix().setDouble(1, 2, 2.0);
2179 EXPECT_FALSE(A.IsScaleOrTranslation());
2180
2181 // Note carefully - expecting true here.
2182 A.MakeIdentity();
2183 A.matrix().setDouble(2, 2, 2.0);
2184 EXPECT_TRUE(A.IsScaleOrTranslation());
2185
2186 A.MakeIdentity();
2187 A.matrix().setDouble(3, 2, 2.0);
2188 EXPECT_FALSE(A.IsScaleOrTranslation());
2189
2190 // Note carefully - expecting true here.
2191 A.MakeIdentity();
2192 A.matrix().setDouble(0, 3, 2.0);
2193 EXPECT_TRUE(A.IsScaleOrTranslation());
2194
2195 // Note carefully - expecting true here.
2196 A.MakeIdentity();
2197 A.matrix().setDouble(1, 3, 2.0);
2198 EXPECT_TRUE(A.IsScaleOrTranslation());
2199
2200 // Note carefully - expecting true here.
2201 A.MakeIdentity();
2202 A.matrix().setDouble(2, 3, 2.0);
2203 EXPECT_TRUE(A.IsScaleOrTranslation());
2204
2205 A.MakeIdentity();
2206 A.matrix().setDouble(3, 3, 2.0);
2207 EXPECT_FALSE(A.IsScaleOrTranslation());
2208 }
2209
2210 TEST(XFormTest, verifyFlattenTo2d) {
2211 Transform A;
2212 InitializeTestMatrix(&A);
2213
2214 A.FlattenTo2d();
2215 EXPECT_ROW1_EQ(10.0, 14.0, 0.0, 22.0, A);
2216 EXPECT_ROW2_EQ(11.0, 15.0, 0.0, 23.0, A);
2217 EXPECT_ROW3_EQ(0.0, 0.0, 1.0, 0.0, A);
2218 EXPECT_ROW4_EQ(13.0, 17.0, 0.0, 25.0, A);
2219 }
2220
1243 } // namespace 2221 } // namespace
1244 2222
1245 } // namespace gfx 2223 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698