Browse Source

Fixed awesome bug in Vector3 constructor.

Updated unit test to make sure it won't happen again.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
1f2aa86be3
  1. 4
      src/Math/Test/Vector2Test.cpp
  2. 1
      src/Math/Test/Vector2Test.h
  3. 5
      src/Math/Test/Vector3Test.cpp
  4. 1
      src/Math/Test/Vector3Test.h
  5. 2
      src/Math/Test/Vector4Test.cpp
  6. 2
      src/Math/Vector3.h

4
src/Math/Test/Vector2Test.cpp

@ -29,6 +29,10 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector2<float> Vector2; typedef Math::Vector2<float> Vector2;
void Vector2Test::construct() {
QVERIFY((Vector2(1, 2) == Vector<float, 2>(1.0f, 2.0f)));
}
void Vector2Test::debug() { void Vector2Test::debug() {
ostringstream o; ostringstream o;
Debug(&o) << Vector2(0.5f, 15.0f); Debug(&o) << Vector2(0.5f, 15.0f);

1
src/Math/Test/Vector2Test.h

@ -23,6 +23,7 @@ class Vector2Test: public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:
void construct();
void debug(); void debug();
}; };

5
src/Math/Test/Vector3Test.cpp

@ -29,6 +29,11 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector3<float> Vector3; typedef Math::Vector3<float> Vector3;
void Vector3Test::construct() {
QVERIFY((Vector3(1, 2, 3) == Vector<float, 3>(1.0f, 2.0f, 3.0f)));
QVERIFY((Vector3(Vector<float, 2>(1.0f, 2.0f), 3) == Vector<float, 3>(1.0f, 2.0f, 3.0f)));
}
void Vector3Test::cross() { void Vector3Test::cross() {
Vector3 a(1, -1, 1); Vector3 a(1, -1, 1);
Vector3 b(4, 3, 7); Vector3 b(4, 3, 7);

1
src/Math/Test/Vector3Test.h

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

2
src/Math/Test/Vector4Test.cpp

@ -32,6 +32,8 @@ typedef Math::Vector3<float> Vector3;
void Vector4Test::construct() { void Vector4Test::construct() {
QVERIFY(Vector4() == Vector4(0.0f, 0.0f, 0.0f, 1.0f)); QVERIFY(Vector4() == Vector4(0.0f, 0.0f, 0.0f, 1.0f));
QVERIFY((Vector4(1, 2, 3, 4) == Vector<float, 4>(1.0f, 2.0f, 3.0f, 4.0f)));
QVERIFY((Vector4(Vector<float, 3>(1.0f, 2.0f, 3.0f), 4) == Vector<float, 4>(1.0f, 2.0f, 3.0f, 4.0f)));
} }
void Vector4Test::threeComponent() { void Vector4Test::threeComponent() {

2
src/Math/Vector3.h

@ -64,7 +64,7 @@ template<class T> class Vector3: public Vector<T, 3> {
* @param other Two component vector * @param other Two component vector
* @param z Z / B value * @param z Z / B value
*/ */
inline Vector3(const Vector<T, 2>& other, T z = T(0)): Vector<T, 3>(other[0], other[1], other[2]) {} inline Vector3(const Vector<T, 2>& other, T z = T(0)): Vector<T, 3>(other[0], other[1], z) {}
inline T x() const { return Vector<T, 3>::at(0); } /**< @brief X component */ inline T x() const { return Vector<T, 3>::at(0); } /**< @brief X component */
inline T y() const { return Vector<T, 3>::at(1); } /**< @brief Y component */ inline T y() const { return Vector<T, 3>::at(1); } /**< @brief Y component */

Loading…
Cancel
Save