From ab470ef4095e3cc8d2f2f3b1b501b6470e45e28d Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 11 Jun 2014 12:59:26 +0000 Subject: [PATCH] math: activate vector swizzling for lvalues. --- src/lol/math/vector.h | 214 ++++++++++++++++++++---------------------- test/unit/vector.cpp | 43 +++++++++ 2 files changed, 144 insertions(+), 113 deletions(-) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 9ebd4d8a..cac8e505 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -25,14 +25,6 @@ namespace lol { -/* Some compilers do not support const members in anonymous unions. So - * far, GCC (>= 4.6), CLang (3.0) and Visual Studio (>= 2010) appear to - * work properly. */ -#undef LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS -#if defined __GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) -# define LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS 1 -#endif - #define LOL_VECTOR_TYPEDEFS(tname, suffix) \ template struct tname; \ typedef tname f16##suffix; \ @@ -85,11 +77,19 @@ typedef imat4 int4x4; * use static_cast instead of reinterpret_cast because there is a stronger * guarantee (by the standard) that the address will stay the same across * casts. + * We need to implement an assignment operator _and_ override the default + * assignment operator. We try to pass arguments by value so that we don't + * have to care about overwriting ourselves (e.g. c.rgb = c.bgr). */ template struct XVec2 { - inline Vec2 operator =(Vec2 const &that); + inline XVec2& operator =(Vec2 that); + + inline XVec2& operator =(XVec2 const &that) + { + return *this = (Vec2)that; + } inline T& operator[](size_t n) { @@ -105,7 +105,12 @@ template struct XVec2 template struct XVec3 { - inline Vec3 operator =(Vec3 const &that); + inline XVec3& operator =(Vec3 that); + + inline XVec3& operator =(XVec3 const &that) + { + return *this = (Vec3)that; + } inline T& operator[](size_t n) { @@ -121,7 +126,12 @@ template struct XVec3 template struct XVec4 { - inline Vec4 operator =(Vec4 const &that); + inline XVec4& operator =(Vec4 that); + + inline XVec4& operator =(XVec4 const &that) + { + return *this = (Vec4)that; + } inline T& operator[](size_t n) { @@ -177,13 +187,10 @@ template struct BVec2 struct { T r, g; }; struct { T s, t; }; -#if LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS -# define const /* disabled */ -#endif #if !_DOXYGEN_SKIP_ME XVec2 const xx, rr, ss; - XVec2 const xy, rg, st; /* lvalue */ - XVec2 const yx, gr, ts; /* lvalue */ + XVec2 xy, rg, st; /* lvalue */ + XVec2 yx, gr, ts; /* lvalue */ XVec2 const yy, gg, tt; XVec3 const xxx, rrr, sss; @@ -211,9 +218,6 @@ template struct BVec2 XVec4 const yyxy, ggrg, ttst; XVec4 const yyyx, gggr, ttts; XVec4 const yyyy, gggg, tttt; -#endif -#if LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS -# undef const #endif }; }; @@ -344,18 +348,15 @@ template struct BVec3 struct { T r, g, b; }; struct { T s, t, p; }; -#if LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS -# define const /* disabled */ -#endif #if !_DOXYGEN_SKIP_ME XVec2 const xx, rr, ss; - XVec2 const xy, rg, st; /* lvalue */ - XVec2 const xz, rb, sp; /* lvalue */ - XVec2 const yx, gr, ts; /* lvalue */ + XVec2 xy, rg, st; /* lvalue */ + XVec2 xz, rb, sp; /* lvalue */ + XVec2 yx, gr, ts; /* lvalue */ XVec2 const yy, gg, tt; - XVec2 const yz, gb, tp; /* lvalue */ - XVec2 const zx, br, ps; /* lvalue */ - XVec2 const zy, bg, pt; /* lvalue */ + XVec2 yz, gb, tp; /* lvalue */ + XVec2 zx, br, ps; /* lvalue */ + XVec2 zy, bg, pt; /* lvalue */ XVec2 const zz, bb, pp; XVec3 const xxx, rrr, sss; @@ -363,23 +364,23 @@ template struct BVec3 XVec3 const xxz, rrb, ssp; XVec3 const xyx, rgr, sts; XVec3 const xyy, rgg, stt; - XVec3 const xyz, rgb, stp; /* lvalue */ + XVec3 xyz, rgb, stp; /* lvalue */ XVec3 const xzx, rbr, sps; - XVec3 const xzy, rbg, spt; /* lvalue */ + XVec3 xzy, rbg, spt; /* lvalue */ XVec3 const xzz, rbb, spp; XVec3 const yxx, grr, tss; XVec3 const yxy, grg, tst; - XVec3 const yxz, grb, tsp; /* lvalue */ + XVec3 yxz, grb, tsp; /* lvalue */ XVec3 const yyx, ggr, tts; XVec3 const yyy, ggg, ttt; XVec3 const yyz, ggb, ttp; - XVec3 const yzx, gbr, tps; /* lvalue */ + XVec3 yzx, gbr, tps; /* lvalue */ XVec3 const yzy, gbg, tpt; XVec3 const yzz, gbb, tpp; XVec3 const zxx, brr, pss; - XVec3 const zxy, brg, pst; /* lvalue */ + XVec3 zxy, brg, pst; /* lvalue */ XVec3 const zxz, brb, psp; - XVec3 const zyx, bgr, pts; /* lvalue */ + XVec3 zyx, bgr, pts; /* lvalue */ XVec3 const zyy, bgg, ptt; XVec3 const zyz, bgb, ptp; XVec3 const zzx, bbr, pps; @@ -467,9 +468,6 @@ template struct BVec3 XVec4 const zzzx, bbbr, ppps; XVec4 const zzzy, bbbg, pppt; XVec4 const zzzz, bbbb, pppp; -#endif -#if LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS -# undef const #endif }; }; @@ -549,25 +547,22 @@ template struct BVec4 struct { T r, g, b, a; }; struct { T s, t, p, q; }; -#if LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS -# define const /* disabled */ -#endif #if !_DOXYGEN_SKIP_ME XVec2 const xx, rr, ss; - XVec2 const xy, rg, st; /* lvalue */ - XVec2 const xz, rb, sp; /* lvalue */ - XVec2 const xw, ra, sq; /* lvalue */ - XVec2 const yx, gr, ts; /* lvalue */ + XVec2 xy, rg, st; /* lvalue */ + XVec2 xz, rb, sp; /* lvalue */ + XVec2 xw, ra, sq; /* lvalue */ + XVec2 yx, gr, ts; /* lvalue */ XVec2 const yy, gg, tt; - XVec2 const yz, gb, tp; /* lvalue */ - XVec2 const yw, ga, tq; /* lvalue */ - XVec2 const zx, br, ps; /* lvalue */ - XVec2 const zy, bg, pt; /* lvalue */ + XVec2 yz, gb, tp; /* lvalue */ + XVec2 yw, ga, tq; /* lvalue */ + XVec2 zx, br, ps; /* lvalue */ + XVec2 zy, bg, pt; /* lvalue */ XVec2 const zz, bb, pp; - XVec2 const zw, ba, pq; /* lvalue */ - XVec2 const wx, ar, qs; /* lvalue */ - XVec2 const wy, ag, qt; /* lvalue */ - XVec2 const wz, ab, qp; /* lvalue */ + XVec2 zw, ba, pq; /* lvalue */ + XVec2 wx, ar, qs; /* lvalue */ + XVec2 wy, ag, qt; /* lvalue */ + XVec2 wz, ab, qp; /* lvalue */ XVec2 const ww, aa, qq; XVec3 const xxx, rrr, sss; @@ -576,58 +571,58 @@ template struct BVec4 XVec3 const xxw, rra, ssq; XVec3 const xyx, rgr, sts; XVec3 const xyy, rgg, stt; - XVec3 const xyz, rgb, stp; /* lvalue */ - XVec3 const xyw, rga, stq; /* lvalue */ + XVec3 xyz, rgb, stp; /* lvalue */ + XVec3 xyw, rga, stq; /* lvalue */ XVec3 const xzx, rbr, sps; - XVec3 const xzy, rbg, spt; /* lvalue */ + XVec3 xzy, rbg, spt; /* lvalue */ XVec3 const xzz, rbb, spp; - XVec3 const xzw, rba, spq; /* lvalue */ + XVec3 xzw, rba, spq; /* lvalue */ XVec3 const xwx, rar, sqs; - XVec3 const xwy, rag, sqt; /* lvalue */ - XVec3 const xwz, rab, sqp; /* lvalue */ + XVec3 xwy, rag, sqt; /* lvalue */ + XVec3 xwz, rab, sqp; /* lvalue */ XVec3 const xww, raa, sqq; XVec3 const yxx, grr, tss; XVec3 const yxy, grg, tst; - XVec3 const yxz, grb, tsp; /* lvalue */ - XVec3 const yxw, gra, tsq; /* lvalue */ + XVec3 yxz, grb, tsp; /* lvalue */ + XVec3 yxw, gra, tsq; /* lvalue */ XVec3 const yyx, ggr, tts; XVec3 const yyy, ggg, ttt; XVec3 const yyz, ggb, ttp; XVec3 const yyw, gga, ttq; - XVec3 const yzx, gbr, tps; /* lvalue */ + XVec3 yzx, gbr, tps; /* lvalue */ XVec3 const yzy, gbg, tpt; XVec3 const yzz, gbb, tpp; - XVec3 const yzw, gba, tpq; /* lvalue */ - XVec3 const ywx, gar, tqs; /* lvalue */ + XVec3 yzw, gba, tpq; /* lvalue */ + XVec3 ywx, gar, tqs; /* lvalue */ XVec3 const ywy, gag, tqt; - XVec3 const ywz, gab, tqp; /* lvalue */ + XVec3 ywz, gab, tqp; /* lvalue */ XVec3 const yww, gaa, tqq; XVec3 const zxx, brr, pss; - XVec3 const zxy, brg, pst; /* lvalue */ + XVec3 zxy, brg, pst; /* lvalue */ XVec3 const zxz, brb, psp; - XVec3 const zxw, bra, psq; /* lvalue */ - XVec3 const zyx, bgr, pts; /* lvalue */ + XVec3 zxw, bra, psq; /* lvalue */ + XVec3 zyx, bgr, pts; /* lvalue */ XVec3 const zyy, bgg, ptt; XVec3 const zyz, bgb, ptp; - XVec3 const zyw, bga, ptq; /* lvalue */ + XVec3 zyw, bga, ptq; /* lvalue */ XVec3 const zzx, bbr, pps; XVec3 const zzy, bbg, ppt; XVec3 const zzz, bbb, ppp; XVec3 const zzw, bba, ppq; - XVec3 const zwx, bar, pqs; /* lvalue */ - XVec3 const zwy, bag, pqt; /* lvalue */ + XVec3 zwx, bar, pqs; /* lvalue */ + XVec3 zwy, bag, pqt; /* lvalue */ XVec3 const zwz, bab, pqp; XVec3 const zww, baa, pqq; XVec3 const wxx, arr, qss; - XVec3 const wxy, arg, qst; /* lvalue */ - XVec3 const wxz, arb, qsp; /* lvalue */ + XVec3 wxy, arg, qst; /* lvalue */ + XVec3 wxz, arb, qsp; /* lvalue */ XVec3 const wxw, ara, qsq; - XVec3 const wyx, agr, qts; /* lvalue */ + XVec3 wyx, agr, qts; /* lvalue */ XVec3 const wyy, agg, qtt; - XVec3 const wyz, agb, qtp; /* lvalue */ + XVec3 wyz, agb, qtp; /* lvalue */ XVec3 const wyw, aga, qtq; - XVec3 const wzx, abr, qps; /* lvalue */ - XVec3 const wzy, abg, qpt; /* lvalue */ + XVec3 wzx, abr, qps; /* lvalue */ + XVec3 wzy, abg, qpt; /* lvalue */ XVec3 const wzz, abb, qpp; XVec3 const wzw, aba, qpq; XVec3 const wwx, aar, qqs; @@ -662,10 +657,10 @@ template struct BVec4 XVec4 const xyzx, rgbr, stps; XVec4 const xyzy, rgbg, stpt; XVec4 const xyzz, rgbb, stpp; - XVec4 const xyzw, rgba, stpq; /* lvalue */ + XVec4 xyzw, rgba, stpq; /* lvalue */ XVec4 const xywx, rgar, stqs; XVec4 const xywy, rgag, stqt; - XVec4 const xywz, rgab, stqp; /* lvalue */ + XVec4 xywz, rgab, stqp; /* lvalue */ XVec4 const xyww, rgaa, stqq; XVec4 const xzxx, rbrr, spss; XVec4 const xzxy, rbrg, spst; @@ -674,13 +669,13 @@ template struct BVec4 XVec4 const xzyx, rbgr, spts; XVec4 const xzyy, rbgg, sptt; XVec4 const xzyz, rbgb, sptp; - XVec4 const xzyw, rbga, sptq; /* lvalue */ + XVec4 xzyw, rbga, sptq; /* lvalue */ XVec4 const xzzx, rbbr, spps; XVec4 const xzzy, rbbg, sppt; XVec4 const xzzz, rbbb, sppp; XVec4 const xzzw, rbba, sppq; XVec4 const xzwx, rbar, spqs; - XVec4 const xzwy, rbag, spqt; /* lvalue */ + XVec4 xzwy, rbag, spqt; /* lvalue */ XVec4 const xzwz, rbab, spqp; XVec4 const xzww, rbaa, spqq; XVec4 const xwxx, rarr, sqss; @@ -689,10 +684,10 @@ template struct BVec4 XVec4 const xwxw, rara, sqsq; XVec4 const xwyx, ragr, sqts; XVec4 const xwyy, ragg, sqtt; - XVec4 const xwyz, ragb, sqtp; /* lvalue */ + XVec4 xwyz, ragb, sqtp; /* lvalue */ XVec4 const xwyw, raga, sqtq; XVec4 const xwzx, rabr, sqps; - XVec4 const xwzy, rabg, sqpt; /* lvalue */ + XVec4 xwzy, rabg, sqpt; /* lvalue */ XVec4 const xwzz, rabb, sqpp; XVec4 const xwzw, raba, sqpq; XVec4 const xwwx, raar, sqqs; @@ -710,10 +705,10 @@ template struct BVec4 XVec4 const yxzx, grbr, tsps; XVec4 const yxzy, grbg, tspt; XVec4 const yxzz, grbb, tspp; - XVec4 const yxzw, grba, tspq; /* lvalue */ + XVec4 yxzw, grba, tspq; /* lvalue */ XVec4 const yxwx, grar, tsqs; XVec4 const yxwy, grag, tsqt; - XVec4 const yxwz, grab, tsqp; /* lvalue */ + XVec4 yxwz, grab, tsqp; /* lvalue */ XVec4 const yxww, graa, tsqq; XVec4 const yyxx, ggrr, ttss; XVec4 const yyxy, ggrg, ttst; @@ -734,7 +729,7 @@ template struct BVec4 XVec4 const yzxx, gbrr, tpss; XVec4 const yzxy, gbrg, tpst; XVec4 const yzxz, gbrb, tpsp; - XVec4 const yzxw, gbra, tpsq; /* lvalue */ + XVec4 yzxw, gbra, tpsq; /* lvalue */ XVec4 const yzyx, gbgr, tpts; XVec4 const yzyy, gbgg, tptt; XVec4 const yzyz, gbgb, tptp; @@ -743,19 +738,19 @@ template struct BVec4 XVec4 const yzzy, gbbg, tppt; XVec4 const yzzz, gbbb, tppp; XVec4 const yzzw, gbba, tppq; - XVec4 const yzwx, gbar, tpqs; /* lvalue */ + XVec4 yzwx, gbar, tpqs; /* lvalue */ XVec4 const yzwy, gbag, tpqt; XVec4 const yzwz, gbab, tpqp; XVec4 const yzww, gbaa, tpqq; XVec4 const ywxx, garr, tqss; XVec4 const ywxy, garg, tqst; - XVec4 const ywxz, garb, tqsp; /* lvalue */ + XVec4 ywxz, garb, tqsp; /* lvalue */ XVec4 const ywxw, gara, tqsq; XVec4 const ywyx, gagr, tqts; XVec4 const ywyy, gagg, tqtt; XVec4 const ywyz, gagb, tqtp; XVec4 const ywyw, gaga, tqtq; - XVec4 const ywzx, gabr, tqps; /* lvalue */ + XVec4 ywzx, gabr, tqps; /* lvalue */ XVec4 const ywzy, gabg, tqpt; XVec4 const ywzz, gabb, tqpp; XVec4 const ywzw, gaba, tqpq; @@ -770,19 +765,19 @@ template struct BVec4 XVec4 const zxyx, brgr, psts; XVec4 const zxyy, brgg, pstt; XVec4 const zxyz, brgb, pstp; - XVec4 const zxyw, brga, pstq; /* lvalue */ + XVec4 zxyw, brga, pstq; /* lvalue */ XVec4 const zxzx, brbr, psps; XVec4 const zxzy, brbg, pspt; XVec4 const zxzz, brbb, pspp; XVec4 const zxzw, brba, pspq; XVec4 const zxwx, brar, psqs; - XVec4 const zxwy, brag, psqt; /* lvalue */ + XVec4 zxwy, brag, psqt; /* lvalue */ XVec4 const zxwz, brab, psqp; XVec4 const zxww, braa, psqq; XVec4 const zyxx, bgrr, ptss; XVec4 const zyxy, bgrg, ptst; XVec4 const zyxz, bgrb, ptsp; - XVec4 const zyxw, bgra, ptsq; /* lvalue */ + XVec4 zyxw, bgra, ptsq; /* lvalue */ XVec4 const zyyx, bggr, ptts; XVec4 const zyyy, bggg, pttt; XVec4 const zyyz, bggb, pttp; @@ -791,7 +786,7 @@ template struct BVec4 XVec4 const zyzy, bgbg, ptpt; XVec4 const zyzz, bgbb, ptpp; XVec4 const zyzw, bgba, ptpq; - XVec4 const zywx, bgar, ptqs; /* lvalue */ + XVec4 zywx, bgar, ptqs; /* lvalue */ XVec4 const zywy, bgag, ptqt; XVec4 const zywz, bgab, ptqp; XVec4 const zyww, bgaa, ptqq; @@ -812,10 +807,10 @@ template struct BVec4 XVec4 const zzwz, bbab, ppqp; XVec4 const zzww, bbaa, ppqq; XVec4 const zwxx, barr, pqss; - XVec4 const zwxy, barg, pqst; /* lvalue */ + XVec4 zwxy, barg, pqst; /* lvalue */ XVec4 const zwxz, barb, pqsp; XVec4 const zwxw, bara, pqsq; - XVec4 const zwyx, bagr, pqts; /* lvalue */ + XVec4 zwyx, bagr, pqts; /* lvalue */ XVec4 const zwyy, bagg, pqtt; XVec4 const zwyz, bagb, pqtp; XVec4 const zwyw, baga, pqtq; @@ -833,10 +828,10 @@ template struct BVec4 XVec4 const wxxw, arra, qssq; XVec4 const wxyx, argr, qsts; XVec4 const wxyy, argg, qstt; - XVec4 const wxyz, argb, qstp; /* lvalue */ + XVec4 wxyz, argb, qstp; /* lvalue */ XVec4 const wxyw, arga, qstq; XVec4 const wxzx, arbr, qsps; - XVec4 const wxzy, arbg, qspt; /* lvalue */ + XVec4 wxzy, arbg, qspt; /* lvalue */ XVec4 const wxzz, arbb, qspp; XVec4 const wxzw, arba, qspq; XVec4 const wxwx, arar, qsqs; @@ -845,13 +840,13 @@ template struct BVec4 XVec4 const wxww, araa, qsqq; XVec4 const wyxx, agrr, qtss; XVec4 const wyxy, agrg, qtst; - XVec4 const wyxz, agrb, qtsp; /* lvalue */ + XVec4 wyxz, agrb, qtsp; /* lvalue */ XVec4 const wyxw, agra, qtsq; XVec4 const wyyx, aggr, qtts; XVec4 const wyyy, aggg, qttt; XVec4 const wyyz, aggb, qttp; XVec4 const wyyw, agga, qttq; - XVec4 const wyzx, agbr, qtps; /* lvalue */ + XVec4 wyzx, agbr, qtps; /* lvalue */ XVec4 const wyzy, agbg, qtpt; XVec4 const wyzz, agbb, qtpp; XVec4 const wyzw, agba, qtpq; @@ -860,10 +855,10 @@ template struct BVec4 XVec4 const wywz, agab, qtqp; XVec4 const wyww, agaa, qtqq; XVec4 const wzxx, abrr, qpss; - XVec4 const wzxy, abrg, qpst; /* lvalue */ + XVec4 wzxy, abrg, qpst; /* lvalue */ XVec4 const wzxz, abrb, qpsp; XVec4 const wzxw, abra, qpsq; - XVec4 const wzyx, abgr, qpts; /* lvalue */ + XVec4 wzyx, abgr, qpts; /* lvalue */ XVec4 const wzyy, abgg, qptt; XVec4 const wzyz, abgb, qptp; XVec4 const wzyw, abga, qptq; @@ -891,9 +886,6 @@ template struct BVec4 XVec4 const wwwy, aaag, qqqt; XVec4 const wwwz, aaab, qqqp; XVec4 const wwww, aaaa, qqqq; -#endif -#if LOL_NO_CONST_MEMBERS_IN_ANONYMOUS_UNIONS -# undef const #endif }; }; @@ -1555,33 +1547,29 @@ inline Quat Quat::operator *(Quat const &val) const /* * Magic vector swizzling (part 2/2) - * Unfortunately these assignment operators cannot be used for now, because - * we would also need to override the default copy assignment operator, and - * in C++98 unions cannot contain such objects. This is why all the swizzling - * magic objects are marked 'const' even those that could be lvalues. */ template -inline Vec2 XVec2::operator =(Vec2 const &that) +inline XVec2& XVec2::operator =(Vec2 that) { for (int i = 0; i < 2; i++) - *this[i] = that[i]; + (*this)[i] = that[i]; return *this; } template -inline Vec3 XVec3::operator =(Vec3 const &that) +inline XVec3& XVec3::operator =(Vec3 that) { for (int i = 0; i < 3; i++) - *this[i] = that[i]; + (*this)[i] = that[i]; return *this; } template -inline Vec4 XVec4::operator =(Vec4 const &that) +inline XVec4& XVec4::operator =(Vec4 that) { for (int i = 0; i < 4; i++) - *this[i] = that[i]; + (*this)[i] = that[i]; return *this; } diff --git a/test/unit/vector.cpp b/test/unit/vector.cpp index 81ae20ca..027c0143 100644 --- a/test/unit/vector.cpp +++ b/test/unit/vector.cpp @@ -96,6 +96,49 @@ LOLUNIT_FIXTURE(VectorTest) LOLUNIT_ASSERT_LESS(a2, f2); } + LOLUNIT_TEST(VectorSwizzle) + { + vec3 a(1.0f, 2.0f, 3.0f); + vec3 b(4.0f, 5.0f, 6.0f); + vec3 c; + + c = a; + c.x = b.y; + LOLUNIT_ASSERT_EQUAL(c.x, 5.0f); + LOLUNIT_ASSERT_EQUAL(c.y, 2.0f); + LOLUNIT_ASSERT_EQUAL(c.z, 3.0f); + + c = a; + c.xy = b.yz; + LOLUNIT_ASSERT_EQUAL(c.x, 5.0f); + LOLUNIT_ASSERT_EQUAL(c.y, 6.0f); + LOLUNIT_ASSERT_EQUAL(c.z, 3.0f); + + c = a; + c.xy = b.zz; + LOLUNIT_ASSERT_EQUAL(c.x, 6.0f); + LOLUNIT_ASSERT_EQUAL(c.y, 6.0f); + LOLUNIT_ASSERT_EQUAL(c.z, 3.0f); + + c = a; + c.xz = b.xy; + LOLUNIT_ASSERT_EQUAL(c.x, 4.0f); + LOLUNIT_ASSERT_EQUAL(c.y, 2.0f); + LOLUNIT_ASSERT_EQUAL(c.z, 5.0f); + + c = a; + c.xz = b.xz; + LOLUNIT_ASSERT_EQUAL(c.x, 4.0f); + LOLUNIT_ASSERT_EQUAL(c.y, 2.0f); + LOLUNIT_ASSERT_EQUAL(c.z, 6.0f); + + c = a; + c.xz = c.zy = b.yx; + LOLUNIT_ASSERT_EQUAL(c.x, 5.0f); + LOLUNIT_ASSERT_EQUAL(c.y, 4.0f); + LOLUNIT_ASSERT_EQUAL(c.z, 4.0f); + } + LOLUNIT_TEST(VectorUnaryMinus) { vec2 a(1.0f, 3.0f);