Skip to content

Commit

Permalink
Remove unused Quaternion::createForMatrix()
Browse files Browse the repository at this point in the history
This method was only used in a single test (which has now been changed to use
createForY() instead, although for some reason this requires a negated angle).
  • Loading branch information
Matthew Mott committed Mar 22, 2021
1 parent 044920c commit 8d489b1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 67 deletions.
2 changes: 1 addition & 1 deletion libs/math/CMakeLists.txt
@@ -1,2 +1,2 @@
add_library(math
AABB.cpp Frustum.cpp Matrix4.cpp Plane3.cpp Quaternion.cpp)
AABB.cpp Frustum.cpp Matrix4.cpp Plane3.cpp)
55 changes: 0 additions & 55 deletions libs/math/Quaternion.cpp

This file was deleted.

5 changes: 0 additions & 5 deletions libs/math/Quaternion.h
Expand Up @@ -61,11 +61,6 @@ class Quaternion :
static Quaternion createForY(double angle);
static Quaternion createForZ(double angle);

/**
* Retrieves the quaternion from the given matrix.
*/
static Quaternion createForMatrix(const Matrix4& matrix4);

/**
* Returns this quaternion multiplied by the other one.
*/
Expand Down
21 changes: 17 additions & 4 deletions test/Brush.cpp
Expand Up @@ -10,6 +10,15 @@
namespace test
{

// Fuzzy equality assertion for Plane3
void expectNear(const Plane3& p1, const Plane3& p2, double epsilon)
{
EXPECT_NEAR(p1.normal().x(), p2.normal().x(), epsilon);
EXPECT_NEAR(p1.normal().y(), p2.normal().y(), epsilon);
EXPECT_NEAR(p1.normal().z(), p2.normal().z(), epsilon);
EXPECT_NEAR(p1.dist(), p2.dist(), epsilon);
}

class BrushTest: public RadiantTest
{
protected:
Expand Down Expand Up @@ -115,14 +124,18 @@ TEST_F(BrushTest, FacePlaneRotateWithMatrix)
Plane3 orig = face.getPlane3();

// Transform the plane with a rotation matrix
Matrix4 rot = Matrix4::getRotation(Vector3(0, 1, 0), 2);
const double ANGLE = 2.0;
Matrix4 rot = Matrix4::getRotation(Vector3(0, 1, 0), ANGLE);

Node_getTransformable(_brushNode)->setRotation(Quaternion::createForMatrix(rot));
Node_getTransformable(_brushNode)->setRotation(
Quaternion::createForY(-ANGLE)
);
Node_getTransformable(_brushNode)->freezeTransform();

double EPSILON = 0.001;
EXPECT_NE(face.getPlane3(), orig);
EXPECT_EQ(face.getPlane3(), orig.transformed(rot));
EXPECT_NEAR(face.getPlane3().normal().getLength(), 1, 0.001);
expectNear(face.getPlane3(), orig.transformed(rot), EPSILON);
EXPECT_NEAR(face.getPlane3().normal().getLength(), 1, EPSILON);

return true;
}
Expand Down
2 changes: 0 additions & 2 deletions test/math/Quaternion.cpp
Expand Up @@ -40,8 +40,6 @@ TEST(MathTest, QuaternionForZRotation)

expectNear(zRot, Quaternion(0, 0, sin(angle.asRadians() / 2),
cos(angle.asRadians() / 2)));
expectNear(zRot,
Quaternion::createForMatrix(Matrix4::getRotationAboutZ(angle)));
}

TEST(MathTest, QuaternionMultiplication)
Expand Down

0 comments on commit 8d489b1

Please sign in to comment.