From 1713602077498598f44331ddcf54b6a04f14c6ca Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 11 Jun 2014 13:25:43 +0000 Subject: [PATCH] math: revert the lvalue vector swizzles because VS2012 lags behind. --- src/lol/math/vector.h | 162 +++++++++++++++++++++++------------------- test/unit/vector.cpp | 2 + 2 files changed, 90 insertions(+), 74 deletions(-) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index cac8e505..1d25166e 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -80,16 +80,20 @@ typedef imat4 int4x4; * 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). + * However, Visual Studio 2012 doesn't support unrestricted unions, so + * fuck it. */ template struct XVec2 { inline XVec2& operator =(Vec2 that); +#if 0 inline XVec2& operator =(XVec2 const &that) { return *this = (Vec2)that; } +#endif inline T& operator[](size_t n) { @@ -107,10 +111,12 @@ template struct XVec3 { inline XVec3& operator =(Vec3 that); +#if 0 inline XVec3& operator =(XVec3 const &that) { return *this = (Vec3)that; } +#endif inline T& operator[](size_t n) { @@ -128,10 +134,12 @@ template struct XVec4 { inline XVec4& operator =(Vec4 that); +#if 0 inline XVec4& operator =(XVec4 const &that) { return *this = (Vec4)that; } +#endif inline T& operator[](size_t n) { @@ -188,9 +196,10 @@ template struct BVec2 struct { T s, t; }; #if !_DOXYGEN_SKIP_ME +#define _____ const XVec2 const xx, rr, ss; - XVec2 xy, rg, st; /* lvalue */ - XVec2 yx, gr, ts; /* lvalue */ + XVec2 _____ xy, rg, st; /* lvalue */ + XVec2 _____ yx, gr, ts; /* lvalue */ XVec2 const yy, gg, tt; XVec3 const xxx, rrr, sss; @@ -218,6 +227,7 @@ template struct BVec2 XVec4 const yyxy, ggrg, ttst; XVec4 const yyyx, gggr, ttts; XVec4 const yyyy, gggg, tttt; +#undef _____ #endif }; }; @@ -349,14 +359,15 @@ template struct BVec3 struct { T s, t, p; }; #if !_DOXYGEN_SKIP_ME +#define _____ const XVec2 const xx, rr, ss; - XVec2 xy, rg, st; /* lvalue */ - XVec2 xz, rb, sp; /* lvalue */ - XVec2 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 yz, gb, tp; /* lvalue */ - XVec2 zx, br, ps; /* lvalue */ - XVec2 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; @@ -364,23 +375,23 @@ template struct BVec3 XVec3 const xxz, rrb, ssp; XVec3 const xyx, rgr, sts; XVec3 const xyy, rgg, stt; - XVec3 xyz, rgb, stp; /* lvalue */ + XVec3 _____ xyz, rgb, stp; /* lvalue */ XVec3 const xzx, rbr, sps; - XVec3 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 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 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 zxy, brg, pst; /* lvalue */ + XVec3 _____ zxy, brg, pst; /* lvalue */ XVec3 const zxz, brb, psp; - XVec3 zyx, bgr, pts; /* lvalue */ + XVec3 _____ zyx, bgr, pts; /* lvalue */ XVec3 const zyy, bgg, ptt; XVec3 const zyz, bgb, ptp; XVec3 const zzx, bbr, pps; @@ -468,6 +479,7 @@ template struct BVec3 XVec4 const zzzx, bbbr, ppps; XVec4 const zzzy, bbbg, pppt; XVec4 const zzzz, bbbb, pppp; +#undef _____ #endif }; }; @@ -548,21 +560,22 @@ template struct BVec4 struct { T s, t, p, q; }; #if !_DOXYGEN_SKIP_ME +#define _____ const XVec2 const xx, rr, ss; - XVec2 xy, rg, st; /* lvalue */ - XVec2 xz, rb, sp; /* lvalue */ - XVec2 xw, ra, sq; /* lvalue */ - XVec2 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 yz, gb, tp; /* lvalue */ - XVec2 yw, ga, tq; /* lvalue */ - XVec2 zx, br, ps; /* lvalue */ - XVec2 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 zw, ba, pq; /* lvalue */ - XVec2 wx, ar, qs; /* lvalue */ - XVec2 wy, ag, qt; /* lvalue */ - XVec2 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; @@ -571,58 +584,58 @@ template struct BVec4 XVec3 const xxw, rra, ssq; XVec3 const xyx, rgr, sts; XVec3 const xyy, rgg, stt; - XVec3 xyz, rgb, stp; /* lvalue */ - XVec3 xyw, rga, stq; /* lvalue */ + XVec3 _____ xyz, rgb, stp; /* lvalue */ + XVec3 _____ xyw, rga, stq; /* lvalue */ XVec3 const xzx, rbr, sps; - XVec3 xzy, rbg, spt; /* lvalue */ + XVec3 _____ xzy, rbg, spt; /* lvalue */ XVec3 const xzz, rbb, spp; - XVec3 xzw, rba, spq; /* lvalue */ + XVec3 _____ xzw, rba, spq; /* lvalue */ XVec3 const xwx, rar, sqs; - XVec3 xwy, rag, sqt; /* lvalue */ - XVec3 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 yxz, grb, tsp; /* lvalue */ - XVec3 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 yzx, gbr, tps; /* lvalue */ + XVec3 _____ yzx, gbr, tps; /* lvalue */ XVec3 const yzy, gbg, tpt; XVec3 const yzz, gbb, tpp; - XVec3 yzw, gba, tpq; /* lvalue */ - XVec3 ywx, gar, tqs; /* lvalue */ + XVec3 _____ yzw, gba, tpq; /* lvalue */ + XVec3 _____ ywx, gar, tqs; /* lvalue */ XVec3 const ywy, gag, tqt; - XVec3 ywz, gab, tqp; /* lvalue */ + XVec3 _____ ywz, gab, tqp; /* lvalue */ XVec3 const yww, gaa, tqq; XVec3 const zxx, brr, pss; - XVec3 zxy, brg, pst; /* lvalue */ + XVec3 _____ zxy, brg, pst; /* lvalue */ XVec3 const zxz, brb, psp; - XVec3 zxw, bra, psq; /* lvalue */ - XVec3 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 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 zwx, bar, pqs; /* lvalue */ - XVec3 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 wxy, arg, qst; /* lvalue */ - XVec3 wxz, arb, qsp; /* lvalue */ + XVec3 _____ wxy, arg, qst; /* lvalue */ + XVec3 _____ wxz, arb, qsp; /* lvalue */ XVec3 const wxw, ara, qsq; - XVec3 wyx, agr, qts; /* lvalue */ + XVec3 _____ wyx, agr, qts; /* lvalue */ XVec3 const wyy, agg, qtt; - XVec3 wyz, agb, qtp; /* lvalue */ + XVec3 _____ wyz, agb, qtp; /* lvalue */ XVec3 const wyw, aga, qtq; - XVec3 wzx, abr, qps; /* lvalue */ - XVec3 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; @@ -657,10 +670,10 @@ template struct BVec4 XVec4 const xyzx, rgbr, stps; XVec4 const xyzy, rgbg, stpt; XVec4 const xyzz, rgbb, stpp; - XVec4 xyzw, rgba, stpq; /* lvalue */ + XVec4 _____ xyzw, rgba, stpq; /* lvalue */ XVec4 const xywx, rgar, stqs; XVec4 const xywy, rgag, stqt; - XVec4 xywz, rgab, stqp; /* lvalue */ + XVec4 _____ xywz, rgab, stqp; /* lvalue */ XVec4 const xyww, rgaa, stqq; XVec4 const xzxx, rbrr, spss; XVec4 const xzxy, rbrg, spst; @@ -669,13 +682,13 @@ template struct BVec4 XVec4 const xzyx, rbgr, spts; XVec4 const xzyy, rbgg, sptt; XVec4 const xzyz, rbgb, sptp; - XVec4 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 xzwy, rbag, spqt; /* lvalue */ + XVec4 _____ xzwy, rbag, spqt; /* lvalue */ XVec4 const xzwz, rbab, spqp; XVec4 const xzww, rbaa, spqq; XVec4 const xwxx, rarr, sqss; @@ -684,10 +697,10 @@ template struct BVec4 XVec4 const xwxw, rara, sqsq; XVec4 const xwyx, ragr, sqts; XVec4 const xwyy, ragg, sqtt; - XVec4 xwyz, ragb, sqtp; /* lvalue */ + XVec4 _____ xwyz, ragb, sqtp; /* lvalue */ XVec4 const xwyw, raga, sqtq; XVec4 const xwzx, rabr, sqps; - XVec4 xwzy, rabg, sqpt; /* lvalue */ + XVec4 _____ xwzy, rabg, sqpt; /* lvalue */ XVec4 const xwzz, rabb, sqpp; XVec4 const xwzw, raba, sqpq; XVec4 const xwwx, raar, sqqs; @@ -705,10 +718,10 @@ template struct BVec4 XVec4 const yxzx, grbr, tsps; XVec4 const yxzy, grbg, tspt; XVec4 const yxzz, grbb, tspp; - XVec4 yxzw, grba, tspq; /* lvalue */ + XVec4 _____ yxzw, grba, tspq; /* lvalue */ XVec4 const yxwx, grar, tsqs; XVec4 const yxwy, grag, tsqt; - XVec4 yxwz, grab, tsqp; /* lvalue */ + XVec4 _____ yxwz, grab, tsqp; /* lvalue */ XVec4 const yxww, graa, tsqq; XVec4 const yyxx, ggrr, ttss; XVec4 const yyxy, ggrg, ttst; @@ -729,7 +742,7 @@ template struct BVec4 XVec4 const yzxx, gbrr, tpss; XVec4 const yzxy, gbrg, tpst; XVec4 const yzxz, gbrb, tpsp; - XVec4 yzxw, gbra, tpsq; /* lvalue */ + XVec4 _____ yzxw, gbra, tpsq; /* lvalue */ XVec4 const yzyx, gbgr, tpts; XVec4 const yzyy, gbgg, tptt; XVec4 const yzyz, gbgb, tptp; @@ -738,19 +751,19 @@ template struct BVec4 XVec4 const yzzy, gbbg, tppt; XVec4 const yzzz, gbbb, tppp; XVec4 const yzzw, gbba, tppq; - XVec4 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 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 ywzx, gabr, tqps; /* lvalue */ + XVec4 _____ ywzx, gabr, tqps; /* lvalue */ XVec4 const ywzy, gabg, tqpt; XVec4 const ywzz, gabb, tqpp; XVec4 const ywzw, gaba, tqpq; @@ -765,19 +778,19 @@ template struct BVec4 XVec4 const zxyx, brgr, psts; XVec4 const zxyy, brgg, pstt; XVec4 const zxyz, brgb, pstp; - XVec4 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 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 zyxw, bgra, ptsq; /* lvalue */ + XVec4 _____ zyxw, bgra, ptsq; /* lvalue */ XVec4 const zyyx, bggr, ptts; XVec4 const zyyy, bggg, pttt; XVec4 const zyyz, bggb, pttp; @@ -786,7 +799,7 @@ template struct BVec4 XVec4 const zyzy, bgbg, ptpt; XVec4 const zyzz, bgbb, ptpp; XVec4 const zyzw, bgba, ptpq; - XVec4 zywx, bgar, ptqs; /* lvalue */ + XVec4 _____ zywx, bgar, ptqs; /* lvalue */ XVec4 const zywy, bgag, ptqt; XVec4 const zywz, bgab, ptqp; XVec4 const zyww, bgaa, ptqq; @@ -807,10 +820,10 @@ template struct BVec4 XVec4 const zzwz, bbab, ppqp; XVec4 const zzww, bbaa, ppqq; XVec4 const zwxx, barr, pqss; - XVec4 zwxy, barg, pqst; /* lvalue */ + XVec4 _____ zwxy, barg, pqst; /* lvalue */ XVec4 const zwxz, barb, pqsp; XVec4 const zwxw, bara, pqsq; - XVec4 zwyx, bagr, pqts; /* lvalue */ + XVec4 _____ zwyx, bagr, pqts; /* lvalue */ XVec4 const zwyy, bagg, pqtt; XVec4 const zwyz, bagb, pqtp; XVec4 const zwyw, baga, pqtq; @@ -828,10 +841,10 @@ template struct BVec4 XVec4 const wxxw, arra, qssq; XVec4 const wxyx, argr, qsts; XVec4 const wxyy, argg, qstt; - XVec4 wxyz, argb, qstp; /* lvalue */ + XVec4 _____ wxyz, argb, qstp; /* lvalue */ XVec4 const wxyw, arga, qstq; XVec4 const wxzx, arbr, qsps; - XVec4 wxzy, arbg, qspt; /* lvalue */ + XVec4 _____ wxzy, arbg, qspt; /* lvalue */ XVec4 const wxzz, arbb, qspp; XVec4 const wxzw, arba, qspq; XVec4 const wxwx, arar, qsqs; @@ -840,13 +853,13 @@ template struct BVec4 XVec4 const wxww, araa, qsqq; XVec4 const wyxx, agrr, qtss; XVec4 const wyxy, agrg, qtst; - XVec4 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 wyzx, agbr, qtps; /* lvalue */ + XVec4 _____ wyzx, agbr, qtps; /* lvalue */ XVec4 const wyzy, agbg, qtpt; XVec4 const wyzz, agbb, qtpp; XVec4 const wyzw, agba, qtpq; @@ -855,10 +868,10 @@ template struct BVec4 XVec4 const wywz, agab, qtqp; XVec4 const wyww, agaa, qtqq; XVec4 const wzxx, abrr, qpss; - XVec4 wzxy, abrg, qpst; /* lvalue */ + XVec4 _____ wzxy, abrg, qpst; /* lvalue */ XVec4 const wzxz, abrb, qpsp; XVec4 const wzxw, abra, qpsq; - XVec4 wzyx, abgr, qpts; /* lvalue */ + XVec4 _____ wzyx, abgr, qpts; /* lvalue */ XVec4 const wzyy, abgg, qptt; XVec4 const wzyz, abgb, qptp; XVec4 const wzyw, abga, qptq; @@ -886,6 +899,7 @@ template struct BVec4 XVec4 const wwwy, aaag, qqqt; XVec4 const wwwz, aaab, qqqp; XVec4 const wwww, aaaa, qqqq; +#undef _____ #endif }; }; diff --git a/test/unit/vector.cpp b/test/unit/vector.cpp index 027c0143..049de88c 100644 --- a/test/unit/vector.cpp +++ b/test/unit/vector.cpp @@ -108,6 +108,7 @@ LOLUNIT_FIXTURE(VectorTest) LOLUNIT_ASSERT_EQUAL(c.y, 2.0f); LOLUNIT_ASSERT_EQUAL(c.z, 3.0f); +#if 0 /* Visual Studio doesn't support these yet. */ c = a; c.xy = b.yz; LOLUNIT_ASSERT_EQUAL(c.x, 5.0f); @@ -137,6 +138,7 @@ LOLUNIT_FIXTURE(VectorTest) LOLUNIT_ASSERT_EQUAL(c.x, 5.0f); LOLUNIT_ASSERT_EQUAL(c.y, 4.0f); LOLUNIT_ASSERT_EQUAL(c.z, 4.0f); +#endif } LOLUNIT_TEST(VectorUnaryMinus)