@ -125,4 +125,11 @@ void VectorTest::angle() {
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);
}}}
@ -33,6 +33,7 @@ class VectorTest: public QObject {
void length();
void normalized();
void angle();
void negative();
};
@ -148,6 +148,16 @@ template<class T, size_t size> class Vector {
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));
/** @brief Vector length */
T length() const {
T out(0);