diff --git a/src/lol/math/ops.h b/src/lol/math/ops.h index 72f2379b..066bfbd2 100644 --- a/src/lol/math/ops.h +++ b/src/lol/math/ops.h @@ -78,7 +78,7 @@ static inline typename std::enable_if \ inline typename std::enable_if>::type \ - operator op(vec_t a, T const &b) \ + operator op(vec_t const &a, T const &b) \ { \ return vec_t(a) op b; \ } diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 18ec8259..284c711c 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -81,6 +81,13 @@ struct vec_t int i = (SWIZZLE >> (4 * (N - 1 - n))) & 3; return static_cast(static_cast(this))[i]; } + +private: + /* Disable all default constructors and destructors; this object + * is only intended to exist as part of a union. */ + vec_t(); + vec_t(vec_t const &); + ~vec_t(); }; /* The generic “vec_t” type, which is a fixed-size vector with no diff --git a/test/unit/vector.cpp b/test/unit/vector.cpp index 722352ce..8380d8ad 100644 --- a/test/unit/vector.cpp +++ b/test/unit/vector.cpp @@ -141,6 +141,36 @@ LOLUNIT_FIXTURE(VectorTest) #endif } + LOLUNIT_TEST(VectorSwizzleMul) + { + ivec3 a(1, 2, 3); + + ivec3 b = a * 2; + LOLUNIT_ASSERT_EQUAL(b.x, 2); + LOLUNIT_ASSERT_EQUAL(b.y, 4); + LOLUNIT_ASSERT_EQUAL(b.z, 6); + + ivec3 c = (ivec3)a.zyx * 2; + LOLUNIT_ASSERT_EQUAL(c.x, 6); + LOLUNIT_ASSERT_EQUAL(c.y, 4); + LOLUNIT_ASSERT_EQUAL(c.z, 2); + + ivec3 d = 2 * (ivec3)a.zyx; + LOLUNIT_ASSERT_EQUAL(d.x, 6); + LOLUNIT_ASSERT_EQUAL(d.y, 4); + LOLUNIT_ASSERT_EQUAL(d.z, 2); + + ivec3 e = a.zyx * 2; + LOLUNIT_ASSERT_EQUAL(e.x, 6); + LOLUNIT_ASSERT_EQUAL(e.y, 4); + LOLUNIT_ASSERT_EQUAL(e.z, 2); + + ivec3 f = 2 * a.zyx; + LOLUNIT_ASSERT_EQUAL(f.x, 6); + LOLUNIT_ASSERT_EQUAL(f.y, 4); + LOLUNIT_ASSERT_EQUAL(f.z, 2); + } + LOLUNIT_TEST(VectorUnaryMinus) { vec2 a(1.0f, 3.0f);