diff --git a/src/Magnum/Math/Geometry/Test/IntersectionTest.cpp b/src/Magnum/Math/Geometry/Test/IntersectionTest.cpp index c85cc49dd..6c3948f24 100644 --- a/src/Magnum/Math/Geometry/Test/IntersectionTest.cpp +++ b/src/Magnum/Math/Geometry/Test/IntersectionTest.cpp @@ -23,7 +23,6 @@ DEALINGS IN THE SOFTWARE. */ -#include #include #include "Magnum/Math/Geometry/Intersection.h" @@ -40,6 +39,7 @@ class IntersectionTest: public Corrade::TestSuite::Tester { typedef Math::Vector2 Vector2; typedef Math::Vector3 Vector3; +typedef Math::Constants Constants; IntersectionTest::IntersectionTest() { addTests({&IntersectionTest::planeLine, @@ -60,11 +60,11 @@ void IntersectionTest::planeLine() { /* Line lies on the plane */ CORRADE_COMPARE(Intersection::planeLine(planePosition, planeNormal, - {1.0f, 0.5f, 0.5f}, {-1.0f, 0.5f, 0.0f}), std::numeric_limits::quiet_NaN()); + {1.0f, 0.5f, 0.5f}, {-1.0f, 0.5f, 0.0f}), Constants::nan()); /* Line is parallel to the plane */ CORRADE_COMPARE(Intersection::planeLine(planePosition, planeNormal, - {1.0f, 0.0f, 1.0f}, {-1.0f, 0.0f, 0.0f}), -std::numeric_limits::infinity()); + {1.0f, 0.0f, 1.0f}, {-1.0f, 0.0f, 0.0f}), -Constants::inf()); } void IntersectionTest::lineLine() { @@ -86,17 +86,16 @@ void IntersectionTest::lineLine() { /* Collinear lines */ const auto tu = Intersection::lineSegmentLineSegment(p, r, {0.0f, 1.0f}, {-1.0f, -2.0f}); - CORRADE_COMPARE(tu.first, -std::numeric_limits::quiet_NaN()); - CORRADE_COMPARE(tu.second, -std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(tu.first, -Constants::nan()); + CORRADE_COMPARE(tu.second, -Constants::nan()); CORRADE_COMPARE(Intersection::lineSegmentLine(p, r, - {0.0f, 1.0f}, {-1.0f, -2.0f}), -std::numeric_limits::quiet_NaN()); + {0.0f, 1.0f}, {-1.0f, -2.0f}), -Constants::nan()); /* Parallel lines */ CORRADE_COMPARE(Intersection::lineSegmentLineSegment(p, r, - {0.0f, 0.0f}, {1.0f, 2.0f}), std::make_pair(std::numeric_limits::infinity(), - std::numeric_limits::infinity())); + {0.0f, 0.0f}, {1.0f, 2.0f}), std::make_pair(Constants::inf(), Constants::inf())); CORRADE_COMPARE(Intersection::lineSegmentLine(p, r, - {0.0f, 0.0f}, {1.0f, 2.0f}), std::numeric_limits::infinity()); + {0.0f, 0.0f}, {1.0f, 2.0f}), Constants::inf()); } }}}} diff --git a/src/Magnum/Math/Test/FunctionsTest.cpp b/src/Magnum/Math/Test/FunctionsTest.cpp index 87211fd34..9c318ea1b 100644 --- a/src/Magnum/Math/Test/FunctionsTest.cpp +++ b/src/Magnum/Math/Test/FunctionsTest.cpp @@ -161,19 +161,17 @@ void FunctionsTest::clamp() { } void FunctionsTest::nanPropagation() { - constexpr const Float NaN = std::numeric_limits::quiet_NaN(); + CORRADE_COMPARE(Math::min(Constants::nan(), 5.0f), Constants::nan()); + CORRADE_COMPARE(Math::min(Vector2{Constants::nan(), 6.0f}, Vector2{5.0f})[0], Constants::nan()); + CORRADE_COMPARE(Math::min(Vector2{Constants::nan(), 6.0f}, Vector2{5.0f})[1], 5.0f); - CORRADE_COMPARE(Math::min(NaN, 5.0f), NaN); - CORRADE_COMPARE(Math::min(Vector2{NaN, 6.0f}, Vector2{5.0f})[0], NaN); - CORRADE_COMPARE(Math::min(Vector2{NaN, 6.0f}, Vector2{5.0f})[1], 5.0f); + CORRADE_COMPARE(Math::max(Constants::nan(), 5.0f), Constants::nan()); + CORRADE_COMPARE(Math::max(Vector2{Constants::nan(), 4.0f}, Vector2{5.0f})[0], Constants::nan()); + CORRADE_COMPARE(Math::max(Vector2{Constants::nan(), 4.0f}, Vector2{5.0f})[1], 5.0f); - CORRADE_COMPARE(Math::max(NaN, 5.0f), NaN); - CORRADE_COMPARE(Math::max(Vector2{NaN, 4.0f}, Vector2{5.0f})[0], NaN); - CORRADE_COMPARE(Math::max(Vector2{NaN, 4.0f}, Vector2{5.0f})[1], 5.0f); - - CORRADE_COMPARE(Math::clamp(NaN, 2.0f, 6.0f), NaN); - CORRADE_COMPARE(Math::clamp(Vector2{NaN, 1.0f}, 2.0f, 6.0f)[0], NaN); - CORRADE_COMPARE(Math::clamp(Vector2{NaN, 1.0f}, 2.0f, 6.0f)[1], 2.0f); + CORRADE_COMPARE(Math::clamp(Constants::nan(), 2.0f, 6.0f), Constants::nan()); + CORRADE_COMPARE(Math::clamp(Vector2{Constants::nan(), 1.0f}, 2.0f, 6.0f)[0], Constants::nan()); + CORRADE_COMPARE(Math::clamp(Vector2{Constants::nan(), 1.0f}, 2.0f, 6.0f)[1], 2.0f); } void FunctionsTest::sign() { diff --git a/src/Magnum/Math/Test/TypeTraitsTest.cpp b/src/Magnum/Math/Test/TypeTraitsTest.cpp index bd0bcde71..a43864658 100644 --- a/src/Magnum/Math/Test/TypeTraitsTest.cpp +++ b/src/Magnum/Math/Test/TypeTraitsTest.cpp @@ -23,10 +23,10 @@ DEALINGS IN THE SOFTWARE. */ -#include #include #include "Magnum/Math/TypeTraits.h" +#include "Magnum/Math/Constants.h" namespace Magnum { namespace Math { namespace Test { @@ -118,8 +118,8 @@ void TypeTraitsTest::equalsFloatingPointInfinity() { } template void TypeTraitsTest::_equalsFloatingPointInfinity() { - CORRADE_VERIFY(TypeTraits::equals(std::numeric_limits::infinity(), - std::numeric_limits::infinity())); + CORRADE_VERIFY(TypeTraits::equals(Constants::inf(), + Constants::inf())); } void TypeTraitsTest::equalsFloatingPointNaN() { @@ -130,8 +130,8 @@ void TypeTraitsTest::equalsFloatingPointNaN() { } template void TypeTraitsTest::_equalsFloatingPointNaN() { - CORRADE_VERIFY(!TypeTraits::equals(std::numeric_limits::quiet_NaN(), - std::numeric_limits::quiet_NaN())); + CORRADE_VERIFY(!TypeTraits::equals(Constants::nan(), + Constants::nan())); } }}} diff --git a/src/Magnum/Primitives/Capsule.cpp b/src/Magnum/Primitives/Capsule.cpp index dc6271d18..06e78b8b7 100644 --- a/src/Magnum/Primitives/Capsule.cpp +++ b/src/Magnum/Primitives/Capsule.cpp @@ -40,7 +40,7 @@ Trade::MeshData2D Capsule2D::wireframe(UnsignedInt hemisphereRings, UnsignedInt std::vector positions; positions.reserve(hemisphereRings*4+2+(cylinderRings-1)*2); - const Rad angleIncrement(Constants::pi()/(2.0f*hemisphereRings)); + const Rad angleIncrement(Constants::piHalf()/hemisphereRings); const Float cylinderIncrement = 2.0f*halfLength/cylinderRings; /* Bottom cap vertex */ @@ -99,13 +99,13 @@ Trade::MeshData3D Capsule3D::solid(UnsignedInt hemisphereRings, UnsignedInt cyli Float height = 2.0f+2.0f*halfLength; Float hemisphereTextureCoordsVIncrement = 1.0f/(hemisphereRings*height); - Rad hemisphereRingAngleIncrement(Constants::pi()/(2*hemisphereRings)); + Rad hemisphereRingAngleIncrement(Constants::piHalf()/hemisphereRings); /* Bottom cap vertex */ capsule.capVertex(-height/2, -1.0f, 0.0f); /* Rings of bottom hemisphere */ - capsule.hemisphereVertexRings(hemisphereRings-1, -halfLength, -Rad(Constants::pi())/2+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); + capsule.hemisphereVertexRings(hemisphereRings-1, -halfLength, -Rad(Constants::piHalf())+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); /* Rings of cylinder */ capsule.cylinderVertexRings(cylinderRings+1, -halfLength, 2.0f*halfLength/cylinderRings, 1.0f/height, 2.0f*halfLength/(cylinderRings*height)); diff --git a/src/Magnum/Primitives/Implementation/WireframeSpheroid.cpp b/src/Magnum/Primitives/Implementation/WireframeSpheroid.cpp index 269049158..e755e697b 100644 --- a/src/Magnum/Primitives/Implementation/WireframeSpheroid.cpp +++ b/src/Magnum/Primitives/Implementation/WireframeSpheroid.cpp @@ -45,7 +45,7 @@ void WireframeSpheroid::bottomHemisphere(const Float endY, const UnsignedInt rin _indices.insert(_indices.end(), {0, i+1}); /* Hemisphere vertices and indices */ - const Rad ringAngleIncrement(Constants::pi()/(2*rings)); + const Rad ringAngleIncrement(Constants::piHalf()/rings); for(UnsignedInt j = 0; j != rings-1; ++j) { const Rad angle = Float(j+1)*ringAngleIncrement; @@ -66,7 +66,7 @@ void WireframeSpheroid::topHemisphere(const Float startY, const UnsignedInt ring _indices.insert(_indices.end(), {UnsignedInt(_positions.size())-4*_segments+i, UnsignedInt(_positions.size())+i}); /* Hemisphere vertices and indices */ - const Rad ringAngleIncrement(Constants::pi()/(2*rings)); + const Rad ringAngleIncrement(Constants::piHalf()/rings); for(UnsignedInt j = 0; j != rings-1; ++j) { const Rad angle = Float(j+1)*ringAngleIncrement; @@ -90,10 +90,10 @@ void WireframeSpheroid::topHemisphere(const Float startY, const UnsignedInt ring void WireframeSpheroid::ring(const Float y) { /* Ring vertices and indices */ - const Rad segmentAngleIncrement(Constants::pi()/(2*_segments)); + const Rad segmentAngleIncrement(Constants::piHalf()/_segments); for(UnsignedInt j = 0; j != _segments; ++j) { for(UnsignedInt i = 0; i != 4; ++i) { - const Rad segmentAngle = Rad(Float(i)*Constants::pi()/2) + Float(j)*segmentAngleIncrement; + const Rad segmentAngle = Rad(Float(i)*Constants::piHalf()) + Float(j)*segmentAngleIncrement; if(j != 0) _indices.insert(_indices.end(), {UnsignedInt(_positions.size()-4), UnsignedInt(_positions.size())}); _positions.emplace_back(Math::sin(segmentAngle), y, Math::cos(segmentAngle)); } diff --git a/src/Magnum/Primitives/UVSphere.cpp b/src/Magnum/Primitives/UVSphere.cpp index 996cca089..43f15a4e5 100644 --- a/src/Magnum/Primitives/UVSphere.cpp +++ b/src/Magnum/Primitives/UVSphere.cpp @@ -47,7 +47,7 @@ Trade::MeshData3D UVSphere::solid(UnsignedInt rings, UnsignedInt segments, Textu sphere.capVertex(-1.0f, -1.0f, 0.0f); /* Vertex rings */ - sphere.hemisphereVertexRings(rings-1, 0.0f, -Rad(Constants::pi())/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); + sphere.hemisphereVertexRings(rings-1, 0.0f, -Rad(Constants::piHalf())+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); /* Top cap vertex */ sphere.capVertex(1.0f, 1.0f, 1.0f); diff --git a/src/Magnum/SceneGraph/Animable.hpp b/src/Magnum/SceneGraph/Animable.hpp index e23bb40cf..8ba4f0d57 100644 --- a/src/Magnum/SceneGraph/Animable.hpp +++ b/src/Magnum/SceneGraph/Animable.hpp @@ -30,12 +30,13 @@ */ #include "Magnum/Timeline.h" +#include "Magnum/Math/Constants.h" #include "Magnum/SceneGraph/AnimableGroup.h" #include "Magnum/SceneGraph/Animable.h" namespace Magnum { namespace SceneGraph { -template Animable::Animable(AbstractObject& object, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(0.0f), startTime(std::numeric_limits::infinity()), pauseTime(-std::numeric_limits::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} +template Animable::Animable(AbstractObject& object, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(0.0f), startTime(Constants::inf()), pauseTime(-Constants::inf()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} template Animable::~Animable() {} diff --git a/src/Magnum/Shapes/Plane.cpp b/src/Magnum/Shapes/Plane.cpp index 665a5e2ae..5e731de4f 100644 --- a/src/Magnum/Shapes/Plane.cpp +++ b/src/Magnum/Shapes/Plane.cpp @@ -25,8 +25,6 @@ #include "Plane.h" -#include - #include "Magnum/Math/Matrix4.h" #include "Magnum/Math/Geometry/Intersection.h" #include "Magnum/Shapes/LineSegment.h" @@ -45,7 +43,7 @@ Plane Plane::transformed(const Matrix4& matrix) const { bool Plane::operator%(const Line3D& other) const { Float t = Intersection::planeLine(_position, _normal, other.a(), other.b()-other.a()); - return t != t || (t != std::numeric_limits::infinity() && t != -std::numeric_limits::infinity()); + return t != t || (t != Constants::inf() && t != -Constants::inf()); } bool Plane::operator%(const LineSegment3D& other) const {