diff --git a/libraries/animation/src/ElbowConstraint.cpp b/libraries/animation/src/ElbowConstraint.cpp index 8c7fec7b6f..a6b2210644 100644 --- a/libraries/animation/src/ElbowConstraint.cpp +++ b/libraries/animation/src/ElbowConstraint.cpp @@ -67,7 +67,7 @@ bool ElbowConstraint::apply(glm::quat& rotation) const { // update rotation const float MIN_SWING_REAL_PART = 0.99999f; - if (twistWasClamped || fabsf(swingRotation.w < MIN_SWING_REAL_PART)) { + if (twistWasClamped || fabsf(swingRotation.w) < MIN_SWING_REAL_PART) { if (twistWasClamped) { twistRotation = glm::angleAxis(clampedTwistAngle, _axis); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c352b55515..1593b649a0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ foreach(DIR ${TEST_SUBDIRS}) endif() endforeach() -file(GLOB SHARED_TEST_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") +file(GLOB SHARED_TEST_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h " "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") add_custom_target("test-extensions" SOURCES "${SHARED_TEST_HEADER_FILES}") @@ -34,4 +34,4 @@ add_custom_target("all-tests" set_target_properties("all-tests" PROPERTIES FOLDER "hidden/test-targets") set_target_properties("all-tests" PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE) \ No newline at end of file + EXCLUDE_FROM_ALL TRUE) diff --git a/tests/GLMTestUtils.h b/tests/GLMTestUtils.h new file mode 100644 index 0000000000..f353255cc1 --- /dev/null +++ b/tests/GLMTestUtils.h @@ -0,0 +1,66 @@ +// +// GLMTestUtils.h +// tests/physics/src +// +// Created by Seiji Emery on 6/22/15 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_GLMTestUtils_h +#define hifi_GLMTestUtils_h + +#include +#include +#include + +// Implements functionality in QTestExtensions.h for glm types + +// Computes the error value between two quaternions (using glm::dot) +float getErrorDifference(const glm::quat& a, const glm::quat& b) { + return fabsf(glm::dot(a, b)) - 1.0f; +} + +inline float getErrorDifference(const glm::vec3& a, const glm::vec3& b) { + return glm::distance(a, b); +} + +inline float getErrorDifference(const glm::mat4& a, const glm::mat4& b) { + float maxDiff = 0; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + float diff = fabs(a[i][j] - b[i][j]); + maxDiff = std::max(diff, maxDiff); + } + } + return maxDiff; +} + +inline QTextStream& operator<<(QTextStream& stream, const glm::vec3& v) { + return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }"; +} + +QTextStream& operator<<(QTextStream& stream, const glm::quat& q) { + return stream << "glm::quat { " << q.x << ", " << q.y << ", " << q.z << ", " << q.w << " }"; +} + +inline QTextStream& operator<< (QTextStream& stream, const glm::mat4& matrix) { + stream << "[\n\t\t"; + stream.setFieldWidth(15); + for (int r = 0; r < 4; ++r) { + for (int c = 0; c < 4; ++c) { + stream << matrix[c][r]; + } + stream << "\n\t\t"; + } + stream.setFieldWidth(0); + stream << "]\n\t"; // hacky as hell, but this should work... + return stream; +} + +#define QCOMPARE_QUATS(rotationA, rotationB, angle) \ + QVERIFY(fabsf(1.0f - fabsf(glm::dot(rotationA, rotationB))) < 2.0f * sinf(angle)) + +#endif diff --git a/tests/QTestExtensions.h b/tests/QTestExtensions.h index c034e9c290..16e51b41ee 100644 --- a/tests/QTestExtensions.h +++ b/tests/QTestExtensions.h @@ -15,6 +15,8 @@ #include #include +#include "GLMTestUtils.h" + // Implements several extensions to QtTest. // // Problems with QtTest: @@ -35,6 +37,10 @@ // +float getErrorDifference(const float& a, const float& b) { + return fabsf(a - b); +} + // Generates a QCOMPARE-style failure message that can be passed to QTest::qFail. // // Formatting looks like this: @@ -279,3 +285,20 @@ bool compareData (const char* data, const char* expectedData, size_t length) { #define COMPARE_DATA(actual, expected, length) \ QCOMPARE_WITH_EXPR((ByteData ( actual, length )), (ByteData ( expected, length )), compareData(actual, expected, length)) + + +// Produces a relative error test for float usable QCOMPARE_WITH_LAMBDA. +inline auto errorTest (float actual, float expected, float acceptableRelativeError) +-> std::function { + return [actual, expected, acceptableRelativeError] () { + if (fabsf(expected) <= acceptableRelativeError) { + return fabsf(actual - expected) < fabsf(acceptableRelativeError); + } + return fabsf((actual - expected) / expected) < fabsf(acceptableRelativeError); + }; +} + +#define QCOMPARE_WITH_RELATIVE_ERROR(actual, expected, relativeError) \ + QCOMPARE_WITH_LAMBDA(actual, expected, errorTest(actual, expected, relativeError)) + + diff --git a/tests/animation/src/RotationConstraintTests.cpp b/tests/animation/src/RotationConstraintTests.cpp index 2cdb44ee8f..4aac875f2a 100644 --- a/tests/animation/src/RotationConstraintTests.cpp +++ b/tests/animation/src/RotationConstraintTests.cpp @@ -16,34 +16,8 @@ #include #include -// HACK -- these helper functions need to be defined BEFORE including magic inside QTestExtensions.h -// TODO: fix QTestExtensions so we don't need to do this in every test. - -// Computes the error value between two quaternions (using glm::dot) -float getErrorDifference(const glm::quat& a, const glm::quat& b) { - return fabsf(glm::dot(a, b)) - 1.0f; -} - -QTextStream& operator<<(QTextStream& stream, const glm::quat& q) { - return stream << "glm::quat { " << q.x << ", " << q.y << ", " << q.z << ", " << q.w << " }"; -} - -// Produces a relative error test for float usable QCOMPARE_WITH_LAMBDA. -inline auto errorTest (float actual, float expected, float acceptableRelativeError) --> std::function { - return [actual, expected, acceptableRelativeError] () { - if (fabsf(expected) <= acceptableRelativeError) { - return fabsf(actual - expected) < fabsf(acceptableRelativeError); - } - return fabsf((actual - expected) / expected) < fabsf(acceptableRelativeError); - }; -} - #include "../QTestExtensions.h" -#define QCOMPARE_WITH_RELATIVE_ERROR(actual, expected, relativeError) \ - QCOMPARE_WITH_LAMBDA(actual, expected, errorTest(actual, expected, relativeError)) - QTEST_MAIN(RotationConstraintTests) diff --git a/tests/physics/src/BulletTestUtils.h b/tests/physics/src/BulletTestUtils.h index 01a4fd5973..9166f80ba1 100644 --- a/tests/physics/src/BulletTestUtils.h +++ b/tests/physics/src/BulletTestUtils.h @@ -23,10 +23,6 @@ // (used by QCOMPARE_WITH_RELATIVE_ERROR via QCOMPARE_WITH_LAMBDA) // (this is only used by btMatrix3x3 in MeshMassPropertiesTests.cpp, so it's only defined for the Mat3 type) -// Return the error between values a and b; used to implement QCOMPARE_WITH_ABS_ERROR -inline btScalar getErrorDifference(const btScalar& a, const btScalar& b) { - return fabs(a - b); -} // Return the error between values a and b; used to implement QCOMPARE_WITH_ABS_ERROR inline btScalar getErrorDifference(const btVector3& a, const btVector3& b) { return (a - b).length(); diff --git a/tests/physics/src/BulletUtilTests.cpp b/tests/physics/src/BulletUtilTests.cpp index 181d22327e..132d655274 100644 --- a/tests/physics/src/BulletUtilTests.cpp +++ b/tests/physics/src/BulletUtilTests.cpp @@ -17,7 +17,6 @@ #include // Add additional qtest functionality (the include order is important!) -#include "GlmTestUtils.h" #include "../QTestExtensions.h" // Constants diff --git a/tests/physics/src/GlmTestUtils.h b/tests/physics/src/GlmTestUtils.h deleted file mode 100644 index 20bc14d5e0..0000000000 --- a/tests/physics/src/GlmTestUtils.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// GlmTestUtils.h -// tests/physics/src -// -// Created by Seiji Emery on 6/22/15 -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_GlmTestUtils_h -#define hifi_GlmTestUtils_h - -#include -#include - -// Implements functionality in QTestExtensions.h for glm types - -inline float getErrorDifference(const glm::vec3& a, const glm::vec3& b) { - return glm::distance(a, b); -} -inline QTextStream& operator<<(QTextStream& stream, const glm::vec3& v) { - return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }"; -} - -#endif diff --git a/tests/physics/src/MeshMassPropertiesTests.cpp b/tests/physics/src/MeshMassPropertiesTests.cpp index e88bcae1b7..825721641f 100644 --- a/tests/physics/src/MeshMassPropertiesTests.cpp +++ b/tests/physics/src/MeshMassPropertiesTests.cpp @@ -16,7 +16,6 @@ // Add additional qtest functionality (the include order is important!) #include "BulletTestUtils.h" -#include "GlmTestUtils.h" #include "../QTestExtensions.h" const btScalar acceptableRelativeError(1.0e-5f); diff --git a/tests/shared/src/AngularConstraintTests.cpp b/tests/shared/src/AngularConstraintTests.cpp index 4dcf3d7296..a711bac709 100644 --- a/tests/shared/src/AngularConstraintTests.cpp +++ b/tests/shared/src/AngularConstraintTests.cpp @@ -9,22 +9,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "AngularConstraintTests.h" + #include #include #include #include -#include "AngularConstraintTests.h" #include "../QTestExtensions.h" -// Computes the error value between two quaternions (using glm::dot) -float getErrorDifference(const glm::quat& a, const glm::quat& b) { - return fabsf(glm::dot(a, b) - 1.0f); -} -QTextStream& operator<<(QTextStream& stream, const glm::quat& q) { - return stream << "glm::quat { " << q.x << ", " << q.y << ", " << q.z << ", " << q.w << " }"; -} QTEST_MAIN(AngularConstraintTests) diff --git a/tests/shared/src/GeometryUtilTests.cpp b/tests/shared/src/GeometryUtilTests.cpp index 44a540b478..eaf1e7cd8a 100644 --- a/tests/shared/src/GeometryUtilTests.cpp +++ b/tests/shared/src/GeometryUtilTests.cpp @@ -22,13 +22,6 @@ QTEST_MAIN(GeometryUtilTests) -float getErrorDifference(const float& a, const float& b) { - return fabsf(a - b); -} - -float getErrorDifference(const glm::vec3& a, const glm::vec3& b) { - return glm::distance(a, b); -} void GeometryUtilTests::testLocalRayRectangleIntersection() { glm::vec3 xAxis(1.0f, 0.0f, 0.0f); diff --git a/tests/shared/src/MovingMinMaxAvgTests.cpp b/tests/shared/src/MovingMinMaxAvgTests.cpp index 48c3c59058..f3ba3239ee 100644 --- a/tests/shared/src/MovingMinMaxAvgTests.cpp +++ b/tests/shared/src/MovingMinMaxAvgTests.cpp @@ -13,7 +13,12 @@ #include +#include #include +#include + +#include "../QTestExtensions.h" + QTEST_MAIN(MovingMinMaxAvgTests) diff --git a/tests/shared/src/MovingMinMaxAvgTests.h b/tests/shared/src/MovingMinMaxAvgTests.h index c64b087c15..1922bd207a 100644 --- a/tests/shared/src/MovingMinMaxAvgTests.h +++ b/tests/shared/src/MovingMinMaxAvgTests.h @@ -14,15 +14,6 @@ #include -inline float getErrorDifference(float a, float b) { - return fabsf(a - b); -} - -#include "../QTestExtensions.h" - -#include "MovingMinMaxAvg.h" -#include "SharedUtil.h" - class MovingMinMaxAvgTests : public QObject { private slots: diff --git a/tests/shared/src/TransformTests.cpp b/tests/shared/src/TransformTests.cpp index be22914b9d..b936d45555 100644 --- a/tests/shared/src/TransformTests.cpp +++ b/tests/shared/src/TransformTests.cpp @@ -10,10 +10,13 @@ #include "TransformTests.h" +#include +#include + +#include #include -#include "SharedLogging.h" -#include <../QTestExtensions.h> +#include "../QTestExtensions.h" using namespace glm; diff --git a/tests/shared/src/TransformTests.h b/tests/shared/src/TransformTests.h index a4d9b2a6c0..06cdbcd3cb 100644 --- a/tests/shared/src/TransformTests.h +++ b/tests/shared/src/TransformTests.h @@ -12,33 +12,6 @@ #define hifi_TransformTests_h #include -#include -#include - -inline float getErrorDifference(const glm::mat4& a, const glm::mat4& b) { - float maxDiff = 0; - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { - float diff = fabs(a[i][j] - b[i][j]); - maxDiff = std::max(diff, maxDiff); - } - } - return maxDiff; -} - -inline QTextStream& operator<< (QTextStream& stream, const glm::mat4& matrix) { - stream << "[\n\t\t"; - stream.setFieldWidth(15); - for (int r = 0; r < 4; ++r) { - for (int c = 0; c < 4; ++c) { - stream << matrix[c][r]; - } - stream << "\n\t\t"; - } - stream.setFieldWidth(0); - stream << "]\n\t"; // hacky as hell, but this should work... - return stream; -} class TransformTests : public QObject { Q_OBJECT