Skip to content

Commit

Permalink
Matrix4 column reference accessors removed
Browse files Browse the repository at this point in the history
No usage of reinterpret_cast remains in Matrix4.h
  • Loading branch information
Matthew Mott committed Oct 1, 2021
1 parent 4829807 commit de305d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
18 changes: 2 additions & 16 deletions libs/math/Matrix4.h
Expand Up @@ -136,8 +136,7 @@ class alignas(16) Matrix4
}

/**
* \brief
* Construct a matrix containing the given elements.
* \brief Construct a matrix containing the given elements.
*
* The elements are specified column-wise, starting with the left-most
* column.
Expand All @@ -148,8 +147,7 @@ class alignas(16) Matrix4
double tx, double ty, double tz, double tw);

/**
* \brief
* Construct a matrix containing the given elements.
* \brief Construct a matrix containing the given elements.
*
* The elements are specified row-wise, starting with the top row.
*/
Expand Down Expand Up @@ -211,26 +209,14 @@ class alignas(16) Matrix4
* Return columns of the matrix as vectors.
* \{
*/
Vector3& xCol3Ref()
{
return reinterpret_cast<Vector3&>(xx());
}
Vector3 xCol3() const
{
return Vector3(_transform.matrix().col(0).head(3));
}
Vector3& yCol3Ref()
{
return reinterpret_cast<Vector3&>(yx());
}
Vector3 yCol3() const
{
return Vector3(_transform.matrix().col(1).head(3));
}
Vector3& zCol3Ref()
{
return reinterpret_cast<Vector3&>(zx());
}
Vector3 zCol3() const
{
return Vector3(_transform.matrix().col(2).head(3));
Expand Down
17 changes: 7 additions & 10 deletions test/math/Matrix4.cpp
Expand Up @@ -126,16 +126,6 @@ TEST(MatrixTest, AccessMatrixColumnVectors)
EXPECT_EQ(m.zCol3(), Vector3(8, 7, 10));
EXPECT_EQ(m.tCol(), Vector4(-5, 13, 14, 3));
EXPECT_EQ(m.translation(), Vector3(-5, 13, 14));

// Write column values
m.xCol3Ref() = Vector3(0.1, 0.2, 0.3);
m.yCol3Ref() = Vector3(0.5, 0.6, 0.7);
m.zCol3Ref() = Vector3(0.9, 1.0, 1.1);
m.setTranslation({1.3, 1.4, 1.5});
EXPECT_EQ(m, Matrix4::byColumns(0.1, 0.2, 0.3, 26,
0.5, 0.6, 0.7, -100,
0.9, 1.0, 1.1, 0.5,
1.3, 1.4, 1.5, 3));
}

TEST(MatrixTest, SetMatrixColumnVectors)
Expand Down Expand Up @@ -165,6 +155,13 @@ TEST(MatrixTest, SetMatrixColumnVectors)
-5, 14, 150, 678,
9, 600, 0.5, 2,
75, 0, 1, -9));

// Set translation column
m.setTranslation({-0.8, -6, 27});
EXPECT_EQ(m, Matrix4::byRows(5, 27, -100, -0.8,
-5, 14, 150, -6,
9, 600, 0.5, 27,
75, 0, 1, -9));
}

TEST(MatrixTest, MatrixRawArrayData)
Expand Down

0 comments on commit de305d6

Please sign in to comment.