5 #include "gtest/gtest.h"
15 TEST(MatrixTest, Multiply) {
25 11.0, 21.0, 0.0, 1.0)));
31 EXPECT_TRUE(
x.Equals(y));
34 TEST(MatrixTest, NotEquals) {
36 Matrix y =
x.Translate({1, 0, 0});
37 EXPECT_FALSE(
x.Equals(y));
40 TEST(MatrixTest, HasPerspective2D) {
41 EXPECT_FALSE(
Matrix().HasPerspective2D());
43 auto test = [](
int index,
bool expect) {
46 matrix.
m[index] = 0.5f;
51 test( 0,
false); test( 1,
false); test( 2,
false); test( 3,
true);
52 test( 4,
false); test( 5,
false); test( 6,
false); test( 7,
true);
53 test( 8,
false); test( 9,
false); test(10,
false); test(11,
false);
54 test(12,
false); test(13,
false); test(14,
false); test(15,
true);
58 TEST(MatrixTest, HasPerspective) {
59 EXPECT_FALSE(
Matrix().HasPerspective());
61 auto test = [](
int index,
bool expect) {
64 matrix.
m[index] = 0.5f;
69 test( 0,
false); test( 1,
false); test( 2,
false); test( 3,
true);
70 test( 4,
false); test( 5,
false); test( 6,
false); test( 7,
true);
71 test( 8,
false); test( 9,
false); test(10,
false); test(11,
true);
72 test(12,
false); test(13,
false); test(14,
false); test(15,
true);
76 TEST(MatrixTest, HasTranslation) {
80 EXPECT_FALSE(
Matrix().HasTranslation());
83 TEST(MatrixTest, IsTranslationOnly) {
90 EXPECT_TRUE(
Matrix().IsTranslationOnly());
91 EXPECT_TRUE(
Matrix().IsTranslationScaleOnly());
94 TEST(MatrixTest, IsTranslationScaleOnly) {
101 EXPECT_TRUE(
Matrix().IsTranslationOnly());
102 EXPECT_TRUE(
Matrix().IsTranslationScaleOnly());
105 TEST(MatrixTest, IsInvertibleGetDeterminant) {
106 EXPECT_TRUE(
Matrix().IsInvertible());
107 EXPECT_NE(
Matrix().GetDeterminant(), 0.0f);
133 EXPECT_TRUE(
Matrix().IsFinite());
146 for (
int i = 0; i < 16; i++) {
150 matrix.
m[i] = std::numeric_limits<Scalar>::infinity();
157 matrix.
m[i] = -std::numeric_limits<Scalar>::infinity();
164 matrix.
m[i] = -std::numeric_limits<Scalar>::quiet_NaN();
170 TEST(MatrixTest, IsAligned2D) {
171 EXPECT_TRUE(
Matrix().IsAligned2D());
174 auto test = [](
int index,
bool expect) {
177 matrix.
m[index] = 0.5f;
178 EXPECT_EQ(matrix.
IsAligned2D(), expect) <<
"index: " << index;
182 test( 0,
true); test( 1,
false); test( 2,
true); test( 3,
false);
183 test( 4,
false); test( 5,
true); test( 6,
true); test( 7,
false);
184 test( 8,
true); test( 9,
true); test(10,
true); test(11,
true);
185 test(12,
true); test(13,
true); test(14,
true); test(15,
false);
189 for (
int i = -1000; i < 1000; i++) {
196 for (
int i = -1000; i < 1000; i++) {
204 EXPECT_TRUE(
Matrix().IsAligned());
217 ASSERT_FALSE(result);
221 auto test = [](
int index,
bool expect) {
224 matrix.
m[index] = 0.5f;
225 EXPECT_EQ(matrix.
IsAligned(), expect) <<
"index: " << index;
229 test( 0,
true); test( 1,
false); test( 2,
false); test( 3,
false);
230 test( 4,
false); test( 5,
true); test( 6,
false); test( 7,
false);
231 test( 8,
false); test( 9,
false); test(10,
true); test(11,
false);
232 test(12,
true); test(13,
true); test(14,
true); test(15,
false);
236 for (
int i = -1000; i < 1000; i++) {
243 for (
int i = -1000; i < 1000; i++) {
250 TEST(MatrixTest, TransformHomogenous) {
253 2.0f, 3.0f, 5.0f, 7.0f,
254 11.0f, 13.0f, 17.0f, 19.0f,
255 23.0f, 29.0f, 31.0f, 37.0f,
256 41.0f, 43.0f, 47.0f, 53.0f
263 TEST(MatrixTest, GetMaxBasisXYNegativeScale) {
274 TEST(MatrixTest, GetMaxBasisXYWithLargeAndSmallScalingFactor) {
282 TEST(MatrixTest, GetMaxBasisXYWithLargeAndSmallScalingFactorNonScaleTranslate) {
289 TEST(MatrixTest, TranslateWithPerspective) {
293 0.0, 2.0, 0.0, 30.0);
296 0.0, 1.0, 0.0, 220.0,
298 0.0, 2.0, 0.0, 430.0)));
301 TEST(MatrixTest, MakeScaleTranslate) {
319 6.0, 5.0, 111.0, 7.0,
inline ::testing::AssertionResult MatrixNear(impeller::Matrix a, impeller::Matrix b)
TEST(AllocationSizeTest, CanCreateTypedAllocations)
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr Matrix Translate(const Vector3 &t) const
constexpr bool IsAligned(Scalar tolerance=0) const
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
static Matrix MakeRotationY(Radians r)
constexpr bool HasPerspective2D() const
static constexpr Matrix MakeRow(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
constexpr Vector3 TransformHomogenous(const Point &v) const
static constexpr Matrix MakeTranslateScale(const Vector3 &s, const Vector3 &t)
static Matrix MakeRotationZ(Radians r)
constexpr bool HasPerspective() const
static constexpr Matrix MakeScale(const Vector3 &s)
constexpr bool IsAligned2D(Scalar tolerance=0) const
Scalar GetMaxBasisLengthXY() const
static Matrix MakeRotationX(Radians r)