Skip to content

Commit

Permalink
Fix compilation in VC++ due to a stupid #define NEAR, which seems to …
Browse files Browse the repository at this point in the history
…be required - worked around that by renaming math::near to math::isNear.

Silence C++17 deprecation warnings in Eigen library, and a few more number conversion warnings.
  • Loading branch information
codereader committed Apr 10, 2021
1 parent 5305d62 commit b086264
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libs/math/AABB.h
Expand Up @@ -223,7 +223,7 @@ inline const Vector3& AABB::getExtents() const

inline float AABB::getRadius() const
{
return extents.getLength(); // Pythagorean length of extents vector
return static_cast<float>(extents.getLength()); // Pythagorean length of extents vector
}

inline bool AABB::contains(const AABB& other) const
Expand Down
11 changes: 11 additions & 0 deletions libs/math/Matrix4.h
Expand Up @@ -8,6 +8,13 @@
#include "math/pi.h"

#undef Success // get rid of fuckwit X.h macro

// Silence C++17 deprecation warnings from Eigen\src\Core\util\Meta.h(373), will be unsilenced at the bottom of this file
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#endif

#include <Eigen/Geometry>

class Quaternion;
Expand Down Expand Up @@ -583,3 +590,7 @@ inline std::ostream& operator<<(std::ostream& st, const Matrix4& m)
st << m[3] << " " << m[7] << " " << m[11] << " " << m[15] << "]";
return st;
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif
2 changes: 1 addition & 1 deletion libs/math/Vector3.h
Expand Up @@ -400,7 +400,7 @@ namespace math

/// Epsilon equality test for BasicVector3
template <typename T>
bool near(const BasicVector3<T>& v1, const BasicVector3<T>& v2, double epsilon)
inline bool isNear(const BasicVector3<T>& v1, const BasicVector3<T>& v2, double epsilon)
{
BasicVector3<T> diff = v1 - v2;
return std::abs(diff.x()) < epsilon && std::abs(diff.y()) < epsilon
Expand Down
2 changes: 1 addition & 1 deletion libs/math/Vector4.h
Expand Up @@ -353,7 +353,7 @@ namespace math

/// Epsilon equality test for BasicVector4
template <typename T>
bool near(const BasicVector4<T>& v1, const BasicVector4<T>& v2, double epsilon)
inline bool isNear(const BasicVector4<T>& v1, const BasicVector4<T>& v2, double epsilon)
{
BasicVector4<T> diff = v1 - v2;
return std::abs(diff.x()) < epsilon && std::abs(diff.y()) < epsilon
Expand Down
2 changes: 1 addition & 1 deletion libs/selection/BestPoint.h
Expand Up @@ -123,7 +123,7 @@ inline void BestPoint(std::size_t count, Vector4 clipped[9], SelectionIntersecti
point.z() = 0;
auto distance = point.getLengthSquared();

best.assignIfCloser(SelectionIntersection(static_cast<float>(depth), distance));
best.assignIfCloser(SelectionIntersection(static_cast<float>(depth), static_cast<float>(distance)));
}
}
else if (count > 2)
Expand Down
2 changes: 1 addition & 1 deletion test/Models.cpp
Expand Up @@ -150,7 +150,7 @@ TEST_F(AseImportTest, TriangleWindingCW)
const auto& b = vertices[indices[1]].vertex;
const auto& c = vertices[indices[2]].vertex;

auto normal = (b - a).crossProduct(c - b).getNormalised();
auto normal = (b - a).cross(c - b).getNormalised();

// We know the triangle in the ASE file is facing upwards,
// For CW order, the cross-product will point in the opposite direction
Expand Down
8 changes: 4 additions & 4 deletions test/math/Matrix4.cpp
Expand Up @@ -536,10 +536,10 @@ TEST(MatrixTest, GetInverseScale)
Matrix4 invSc = getInverseScale(m);

// Result should be a diagonal matrix containing only a scale
EXPECT_TRUE(math::near(invSc.xCol(), Vector4(1.0 / 3, 0, 0, 0), 1E-6));
EXPECT_TRUE(math::near(invSc.yCol(), Vector4(0, 1.0 / 2.5, 0, 0), 1E-6));
EXPECT_TRUE(math::near(invSc.zCol(), Vector4(0, 0, 1.0 / 8.2, 0), 1E-6));
EXPECT_TRUE(math::near(invSc.tCol(), Vector4(0, 0, 0, 1), 1E-6));
EXPECT_TRUE(math::isNear(invSc.xCol(), Vector4(1.0 / 3, 0, 0, 0), 1E-6));
EXPECT_TRUE(math::isNear(invSc.yCol(), Vector4(0, 1.0 / 2.5, 0, 0), 1E-6));
EXPECT_TRUE(math::isNear(invSc.zCol(), Vector4(0, 0, 1.0 / 8.2, 0), 1E-6));
EXPECT_TRUE(math::isNear(invSc.tCol(), Vector4(0, 0, 0, 1), 1E-6));
}

}
2 changes: 1 addition & 1 deletion test/math/Vector.cpp
Expand Up @@ -96,7 +96,7 @@ TEST(MathTest, NormaliseVector3)
Vector3 vN = v.getNormalised();

// getNormalised should return correct result and not change the original
EXPECT_TRUE(math::near(vN, v * 1.0/v.getLength(), 10E-6));
EXPECT_TRUE(math::isNear(vN, v * 1.0/v.getLength(), 10E-6));
EXPECT_NE(vN, v);

// Normalise in place gives same result
Expand Down

0 comments on commit b086264

Please sign in to comment.