Browse Source

math: add dot() for quaternions, plus the relevant unit test.

legacy
Sam Hocevar sam 12 years ago
parent
commit
f2c269cb1e
2 changed files with 13 additions and 5 deletions
  1. +5
    -5
      src/lol/math/vector.h
  2. +8
    -0
      test/unit/quat.cpp

+ 5
- 5
src/lol/math/vector.h View File

@@ -1217,10 +1217,7 @@ static inline Quat<T> operator /(Quat<T> x, Quat<T> 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<t1> const &a, tname<t2> const &b) \
@@ -1231,6 +1228,9 @@ static inline Quat<T> operator /(Quat<T> x, Quat<T> 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<tf> cross(tname<t1> const &a, tname<t2> 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


+ 8
- 0
test/unit/quat.cpp View File

@@ -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);


Loading…
Cancel
Save