Browse Source

Using explicit constructors for templated type in Vector.

E.g. T() instead of 0, T(1) instead of 1. Added just-to-be-sure unit
test.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
f2c37d9dd8
  1. 6
      src/Math/Test/Vector3Test.cpp
  2. 1
      src/Math/Test/Vector3Test.h
  3. 6
      src/Math/Vector3.h

6
src/Math/Test/Vector3Test.cpp

@ -41,6 +41,12 @@ void Vector3Test::cross() {
QVERIFY(Vector3::cross(a, b) == Vector3(-10, -3, 7));
}
void Vector3Test::axis() {
QVERIFY(Vector3::xAxis(5.0f) == Vector3(5.0f, 0.0f, 0.0f));
QVERIFY(Vector3::yAxis(6.0f) == Vector3(0.0f, 6.0f, 0.0f));
QVERIFY(Vector3::zAxis(7.0f) == Vector3(0.0f, 0.0f, 7.0f));
}
void Vector3Test::debug() {
ostringstream o;
Debug(&o) << Vector3(0.5f, 15.0f, 1.0f);

1
src/Math/Test/Vector3Test.h

@ -25,6 +25,7 @@ class Vector3Test: public QObject {
private slots:
void construct();
void cross();
void axis();
void debug();
};

6
src/Math/Vector3.h

@ -37,13 +37,13 @@ template<class T> class Vector3: public Vector<T, 3> {
}
/** @brief Vector in direction of X axis */
inline constexpr static Vector3<T> xAxis(T length = 1) { return Vector3<T>(length, 0, 0); }
inline constexpr static Vector3<T> xAxis(T length = T(1)) { return Vector3<T>(length, T(), T()); }
/** @brief Vector in direction of Y axis */
inline constexpr static Vector3<T> yAxis(T length = 1) { return Vector3<T>(0, length, 0); }
inline constexpr static Vector3<T> yAxis(T length = T(1)) { return Vector3<T>(T(), length, T()); }
/** @brief Vector in direction of Z axis */
inline constexpr static Vector3<T> zAxis(T length = 1) { return Vector3<T>(0, 0, length); }
inline constexpr static Vector3<T> zAxis(T length = T(1)) { return Vector3<T>(T(), T(), length); }
/** @brief Cross product */
constexpr static Vector3<T> cross(const Vector3<T>& a, const Vector3<T>& b) {

Loading…
Cancel
Save