Browse Source

core: add the unary minus operator to vectors.

legacy
Sam Hocevar sam 13 years ago
parent
commit
3213d5b7a5
2 changed files with 18 additions and 0 deletions
  1. +8
    -0
      src/matrix.h
  2. +10
    -0
      test/matrix.cpp

+ 8
- 0
src/matrix.h View File

@@ -103,6 +103,14 @@ namespace lol
return ret; \ return ret; \
} \ } \
\ \
inline Vec##elems<T> operator -() const \
{ \
Vec##elems<T> ret; \
for (int n = 0; n < elems; n++) \
ret[n] = -(*this)[n]; \
return ret; \
} \
\
inline T sqlen() const \ inline T sqlen() const \
{ \ { \
T acc = 0; \ T acc = 0; \


+ 10
- 0
test/matrix.cpp View File

@@ -27,6 +27,7 @@ class MatrixTest : public CppUnit::TestCase
CPPUNIT_TEST_SUITE(MatrixTest); CPPUNIT_TEST_SUITE(MatrixTest);
CPPUNIT_TEST(test_vec_eq); CPPUNIT_TEST(test_vec_eq);
CPPUNIT_TEST(test_vec_lt); CPPUNIT_TEST(test_vec_lt);
CPPUNIT_TEST(test_vec_unary);
CPPUNIT_TEST(test_mat_det); CPPUNIT_TEST(test_mat_det);
CPPUNIT_TEST(test_mat_mul); CPPUNIT_TEST(test_mat_mul);
CPPUNIT_TEST(test_mat_inv); CPPUNIT_TEST(test_mat_inv);
@@ -122,6 +123,15 @@ public:
CPPUNIT_ASSERT(a2 < f2); CPPUNIT_ASSERT(a2 < f2);
} }


void test_vec_unary()
{
vec2 a(1.0f, 3.0f);
vec2 b(-1.0f, -3.0f);

CPPUNIT_ASSERT(a == -b);
CPPUNIT_ASSERT(-a == b);
}

void test_mat_det() void test_mat_det()
{ {
float d1 = triangular.det(); float d1 = triangular.det();


Loading…
Cancel
Save