From f2c269cb1efa981185d6dc00bcc434950265e8a9 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 23 Aug 2012 14:05:03 +0000 Subject: [PATCH] math: add dot() for quaternions, plus the relevant unit test. --- src/lol/math/vector.h | 10 +++++----- test/unit/quat.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index fbd31277..25f7d017 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1217,10 +1217,7 @@ static inline Quat operator /(Quat x, Quat const &y) DECLARE_SCALAR_VECTOR_COERCE_OP(tname, *, tprefix, t1, t2, tf) \ \ DECLARE_VECTOR_VECTOR_BOOLOP(tname, ==, ==, true, tprefix, t1, t2) \ - DECLARE_VECTOR_VECTOR_BOOLOP(tname, !=, ==, false, tprefix, t1, t2) - -#define DECLARE_BINARY_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \ - DECLARE_SCALAR_VECTOR_COERCE_OP(tname, /, tprefix, t1, t2, tf) \ + DECLARE_VECTOR_VECTOR_BOOLOP(tname, !=, ==, false, tprefix, t1, t2) \ \ tprefix \ inline tf dot(tname const &a, tname const &b) \ @@ -1231,6 +1228,9 @@ static inline Quat operator /(Quat x, Quat const &y) return ret; \ } +#define DECLARE_BINARY_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \ + DECLARE_SCALAR_VECTOR_COERCE_OP(tname, /, tprefix, t1, t2, tf) + #define DECLARE_VEC_3_COERCE_OPS(tname, tprefix, t1, t2, tf) \ tprefix \ inline tname cross(tname const &a, tname const &b) \ @@ -1354,7 +1354,7 @@ DECLARE_ALL_VECTOR_OPS(uint64_t) #endif /* Hack for compilation speedups: we can hide some of our global methods in - * namespaces. We therefore want "long_double" to be a one-symbol type */ + * namespaces. We therefore want "long_double" to be a single-word name */ typedef long double long_double; /* Apply the same coercion rules as in the C++ standard. However, instead diff --git a/test/unit/quat.cpp b/test/unit/quat.cpp index 7bd9fecb..8353943f 100644 --- a/test/unit/quat.cpp +++ b/test/unit/quat.cpp @@ -79,6 +79,14 @@ LOLUNIT_FIXTURE(QuaternionTest) LOLUNIT_ASSERT_EQUAL(norm(a * d), norm(a) * norm(d)); } + LOLUNIT_TEST(Dot) + { + quat a(-1.f, 2.f, -3.f, 4.f); + quat b(8.f, 7.f, 6.f, 5.f); + + LOLUNIT_ASSERT_EQUAL(dot(a, b), 8.f); + } + LOLUNIT_TEST(Base) { quat one(1.f, 0.f, 0.f, 0.f);