Browse Source

Math: various cleanup.

pull/87/head
Vladimír Vondruš 12 years ago
parent
commit
fdb8991d56
  1. 20
      src/Magnum/Math/Constants.h
  2. 1
      src/Magnum/Math/Geometry/Test/DistanceTest.cpp
  3. 6
      src/Magnum/Math/Test/ConstantsTest.cpp
  4. 13
      src/Magnum/Math/Test/Matrix4Test.cpp

20
src/Magnum/Math/Constants.h

@ -58,8 +58,8 @@ template<class T> struct Constants {
*/
static constexpr T tau();
static constexpr T sqrt2(); /**< @brief Square root of 2 */
static constexpr T sqrt3(); /**< @brief Square root of 3 */
static constexpr T sqrt2(); /**< @brief Square root of 2 */
static constexpr T sqrt3(); /**< @brief Square root of 3 */
#endif
};
@ -68,19 +68,19 @@ template<class T> struct Constants {
template<> struct Constants<Double> {
Constants() = delete;
static constexpr Double pi() { return 3.141592653589793; }
static constexpr Double tau() { return 6.283185307179586; }
static constexpr Double sqrt2() { return 1.414213562373095; }
static constexpr Double sqrt3() { return 1.732050807568877; }
static constexpr Double pi() { return 3.141592653589793; }
static constexpr Double tau() { return 6.283185307179586; }
static constexpr Double sqrt2() { return 1.414213562373095; }
static constexpr Double sqrt3() { return 1.732050807568877; }
};
#endif
template<> struct Constants<Float> {
Constants() = delete;
static constexpr Float pi() { return 3.141592654f; }
static constexpr Float tau() { return 6.283185307f; }
static constexpr Float sqrt2() { return 1.414213562f; }
static constexpr Float sqrt3() { return 1.732050808f; }
static constexpr Float pi() { return 3.141592654f; }
static constexpr Float tau() { return 6.283185307f; }
static constexpr Float sqrt2() { return 1.414213562f; }
static constexpr Float sqrt3() { return 1.732050808f; }
};
#endif

1
src/Magnum/Math/Geometry/Test/DistanceTest.cpp

@ -23,7 +23,6 @@
DEALINGS IN THE SOFTWARE.
*/
#include <limits>
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Math/Constants.h"

6
src/Magnum/Math/Test/ConstantsTest.cpp

@ -50,7 +50,8 @@ void ConstantsTest::constantsFloat() {
CORRADE_COMPARE(Math::pow<2>(b), 3.0f);
constexpr Float c = Constants<Float>::pi();
CORRADE_COMPARE(2.0f*c, Constants<Float>::tau());
constexpr Float e = Constants<Float>::tau();
CORRADE_COMPARE(2.0f*c, e);
}
void ConstantsTest::constantsDouble() {
@ -61,7 +62,8 @@ void ConstantsTest::constantsDouble() {
CORRADE_COMPARE(Math::pow<2>(b), 3.0);
constexpr Double c = Constants<Double>::pi();
CORRADE_COMPARE(2.0*c, Constants<Double>::tau());
constexpr Double e = Constants<Double>::tau();
CORRADE_COMPARE(2.0*c, e);
#else
CORRADE_SKIP("Double precision is not supported when targeting OpenGL ES.");
#endif

13
src/Magnum/Math/Test/Matrix4Test.cpp

@ -102,6 +102,7 @@ typedef Math::Matrix4<Float> Matrix4;
typedef Math::Matrix4<Int> Matrix4i;
typedef Math::Matrix<3, Float> Matrix3x3;
typedef Math::Vector3<Float> Vector3;
typedef Math::Constants<Float> Constants;
Matrix4Test::Matrix4Test() {
addTests({&Matrix4Test::construct,
@ -277,8 +278,8 @@ void Matrix4Test::rotationX() {
{0.0f, 0.90096887f, 0.43388374f, 0.0f},
{0.0f, -0.43388374f, 0.90096887f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants<Float>::pi()/7), Vector3::xAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationX(Rad(Math::Constants<Float>::pi()/7)), matrix);
CORRADE_COMPARE(Matrix4::rotation(Rad(Constants::pi()/7), Vector3::xAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationX(Rad(Constants::pi()/7)), matrix);
}
void Matrix4Test::rotationY() {
@ -286,8 +287,8 @@ void Matrix4Test::rotationY() {
{ 0.0f, 1.0f, 0.0f, 0.0f},
{0.43388374f, 0.0f, 0.90096887f, 0.0f},
{ 0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants<Float>::pi()/7), Vector3::yAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationY(Rad(Math::Constants<Float>::pi()/7)), matrix);
CORRADE_COMPARE(Matrix4::rotation(Rad(Constants::pi()/7), Vector3::yAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationY(Rad(Constants::pi()/7)), matrix);
}
void Matrix4Test::rotationZ() {
@ -295,8 +296,8 @@ void Matrix4Test::rotationZ() {
{-0.43388374f, 0.90096887f, 0.0f, 0.0f},
{ 0.0f, 0.0f, 1.0f, 0.0f},
{ 0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants<Float>::pi()/7), Vector3::zAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationZ(Rad(Math::Constants<Float>::pi()/7)), matrix);
CORRADE_COMPARE(Matrix4::rotation(Rad(Constants::pi()/7), Vector3::zAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationZ(Rad(Constants::pi()/7)), matrix);
}
void Matrix4Test::reflection() {

Loading…
Cancel
Save