Browse Source

Function for negating a vector.

vectorfields
Vladimír Vondruš 16 years ago
parent
commit
4e2f56c78b
  1. 7
      src/Math/Test/VectorTest.cpp
  2. 1
      src/Math/Test/VectorTest.h
  3. 10
      src/Math/Vector.h

7
src/Math/Test/VectorTest.cpp

@ -125,4 +125,11 @@ void VectorTest::angle() {
QCOMPARE(Vector3::angle(a, b), 1.16251f); QCOMPARE(Vector3::angle(a, b), 1.16251f);
} }
void VectorTest::negative() {
float vec[] = { 1.0f, -3.0f, 5.0f, -10.0f };
float negative[] = { -1.0f, 3.0f, -5.0f, 10.0f };
QVERIFY(-Vector4(vec) == negative);
}
}}} }}}

1
src/Math/Test/VectorTest.h

@ -33,6 +33,7 @@ class VectorTest: public QObject {
void length(); void length();
void normalized(); void normalized();
void angle(); void angle();
void negative();
}; };
}}} }}}

10
src/Math/Vector.h

@ -148,6 +148,16 @@ template<class T, size_t size> class Vector {
return out; return out;
} }
/** @brief Negative vector */
Vector<T, size> operator-() const {
Vector<T, size> out;
for(size_t i = 0; i != size; ++i)
out.set(i, -at(i));
return out;
}
/** @brief Vector length */ /** @brief Vector length */
T length() const { T length() const {
T out(0); T out(0);

Loading…
Cancel
Save