that it never happens again, and unit tests in case it happens again.undefined
| @@ -78,7 +78,7 @@ static inline typename std::enable_if<SWIZZLE1 != FULL_SWIZZLE || SWIZZLE2 != FU | |||||
| \ | \ | ||||
| template<typename T, int N, int SWIZZLE> \ | template<typename T, int N, int SWIZZLE> \ | ||||
| inline typename std::enable_if<SWIZZLE != FULL_SWIZZLE,vec_t<T,N>>::type \ | inline typename std::enable_if<SWIZZLE != FULL_SWIZZLE,vec_t<T,N>>::type \ | ||||
| operator op(vec_t<T,N,SWIZZLE> a, T const &b) \ | |||||
| operator op(vec_t<T,N,SWIZZLE> const &a, T const &b) \ | |||||
| { \ | { \ | ||||
| return vec_t<T,N>(a) op b; \ | return vec_t<T,N>(a) op b; \ | ||||
| } | } | ||||
| @@ -81,6 +81,13 @@ struct vec_t | |||||
| int i = (SWIZZLE >> (4 * (N - 1 - n))) & 3; | int i = (SWIZZLE >> (4 * (N - 1 - n))) & 3; | ||||
| return static_cast<T const*>(static_cast<void const *>(this))[i]; | return static_cast<T const*>(static_cast<void const *>(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<T, N, SWIZZLE> const &); | |||||
| ~vec_t(); | |||||
| }; | }; | ||||
| /* The generic “vec_t” type, which is a fixed-size vector with no | /* The generic “vec_t” type, which is a fixed-size vector with no | ||||
| @@ -141,6 +141,36 @@ LOLUNIT_FIXTURE(VectorTest) | |||||
| #endif | #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) | LOLUNIT_TEST(VectorUnaryMinus) | ||||
| { | { | ||||
| vec2 a(1.0f, 3.0f); | vec2 a(1.0f, 3.0f); | ||||