Commits

Anonymous committed 62d6d8a

Improved matrix support.

Comments (0)

Files changed (17)

 CMakeFiles/
 Makefile
 \.cmake$
+\.a$
+tests/neglect_tests

neglect/cpplib/CMakeLists.txt

 	include/neglect/_vector2.hpp
 	include/neglect/_vector3.hpp
 	include/neglect/_vector4.hpp
+	include/neglect/math.hpp
 	include/neglect/matrix.hpp
 	include/neglect/matrix_io.hpp
 	include/neglect/unittest.hpp
 	include/neglect/path.hpp
 	include/neglect/ntpath.hpp
     include/neglect/posixpath.hpp
+    
+    include/neglect/_vector2_swizzle.inc
+    include/neglect/_vector3_swizzle.inc
+    include/neglect/_vector4_swizzle.inc
 	
 	include/neglect/boot.h
 )
 
+source_group("Generated Files" REGULAR_EXPRESSION "\\.inc$")
+
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
 add_library(neglect STATIC ${SOURCES} ${HEADERS})

neglect/cpplib/include/neglect/_vector2.hpp

     public:
         union {
             struct { T x, y; };
+            struct { T r, g; };
             struct { T s, t; };
         };
 
         {
             return math::sqrt(norm());
         }
+
+        // include the swizzling functions
+#       include <neglect/_vector2_swizzle.inc>
     };
 }
 

neglect/cpplib/include/neglect/_vector2_swizzle.inc

+// this file was automatically generated by
+// make_swizzle_includes.py on Mon Mar 29 22:19:33 2010.  DO NOT EDIT
+
+const vector<T, 2> &xy() const { return *this; }
+vector<T, 2> yx() const { return vector<T, 2>(y, x); }
+const vector<T, 2> &rg() const { return *this; }
+vector<T, 2> gr() const { return vector<T, 2>(g, r); }
+const vector<T, 2> &st() const { return *this; }
+vector<T, 2> ts() const { return vector<T, 2>(t, s); }

neglect/cpplib/include/neglect/_vector3.hpp

         {
             return math::sqrt(norm());
         }
+
+        // include the swizzling functions
+#       include <neglect/_vector3_swizzle.inc>
     };
 }
 

neglect/cpplib/include/neglect/_vector3_swizzle.inc

+// this file was automatically generated by
+// make_swizzle_includes.py on Mon Mar 29 22:19:33 2010.  DO NOT EDIT
+
+vector<T, 2> xy() const { return vector<T, 2>(x, y); }
+vector<T, 2> xz() const { return vector<T, 2>(x, z); }
+vector<T, 2> yx() const { return vector<T, 2>(y, x); }
+vector<T, 2> yz() const { return vector<T, 2>(y, z); }
+vector<T, 2> zx() const { return vector<T, 2>(z, x); }
+vector<T, 2> zy() const { return vector<T, 2>(z, y); }
+const vector<T, 3> &xyz() const { return *this; }
+vector<T, 3> xzy() const { return vector<T, 3>(x, z, y); }
+vector<T, 3> yxz() const { return vector<T, 3>(y, x, z); }
+vector<T, 3> yzx() const { return vector<T, 3>(y, z, x); }
+vector<T, 3> zxy() const { return vector<T, 3>(z, x, y); }
+vector<T, 3> zyx() const { return vector<T, 3>(z, y, x); }
+vector<T, 2> rg() const { return vector<T, 2>(r, g); }
+vector<T, 2> rb() const { return vector<T, 2>(r, b); }
+vector<T, 2> gr() const { return vector<T, 2>(g, r); }
+vector<T, 2> gb() const { return vector<T, 2>(g, b); }
+vector<T, 2> br() const { return vector<T, 2>(b, r); }
+vector<T, 2> bg() const { return vector<T, 2>(b, g); }
+const vector<T, 3> &rgb() const { return *this; }
+vector<T, 3> rbg() const { return vector<T, 3>(r, b, g); }
+vector<T, 3> grb() const { return vector<T, 3>(g, r, b); }
+vector<T, 3> gbr() const { return vector<T, 3>(g, b, r); }
+vector<T, 3> brg() const { return vector<T, 3>(b, r, g); }
+vector<T, 3> bgr() const { return vector<T, 3>(b, g, r); }
+vector<T, 2> st() const { return vector<T, 2>(s, t); }
+vector<T, 2> sp() const { return vector<T, 2>(s, p); }
+vector<T, 2> ts() const { return vector<T, 2>(t, s); }
+vector<T, 2> tp() const { return vector<T, 2>(t, p); }
+vector<T, 2> ps() const { return vector<T, 2>(p, s); }
+vector<T, 2> pt() const { return vector<T, 2>(p, t); }
+const vector<T, 3> &stp() const { return *this; }
+vector<T, 3> spt() const { return vector<T, 3>(s, p, t); }
+vector<T, 3> tsp() const { return vector<T, 3>(t, s, p); }
+vector<T, 3> tps() const { return vector<T, 3>(t, p, s); }
+vector<T, 3> pst() const { return vector<T, 3>(p, s, t); }
+vector<T, 3> pts() const { return vector<T, 3>(p, t, s); }

neglect/cpplib/include/neglect/_vector4.hpp

         {
             return math::sqrt(norm());
         }
+
+        // include the swizzling functions
+#       include <neglect/_vector4_swizzle.inc>
     };
 }
 

neglect/cpplib/include/neglect/_vector4_swizzle.inc

+// this file was automatically generated by
+// make_swizzle_includes.py on Mon Mar 29 22:19:33 2010.  DO NOT EDIT
+
+vector<T, 2> xy() const { return vector<T, 2>(x, y); }
+vector<T, 2> xz() const { return vector<T, 2>(x, z); }
+vector<T, 2> xw() const { return vector<T, 2>(x, w); }
+vector<T, 2> yx() const { return vector<T, 2>(y, x); }
+vector<T, 2> yz() const { return vector<T, 2>(y, z); }
+vector<T, 2> yw() const { return vector<T, 2>(y, w); }
+vector<T, 2> zx() const { return vector<T, 2>(z, x); }
+vector<T, 2> zy() const { return vector<T, 2>(z, y); }
+vector<T, 2> zw() const { return vector<T, 2>(z, w); }
+vector<T, 2> wx() const { return vector<T, 2>(w, x); }
+vector<T, 2> wy() const { return vector<T, 2>(w, y); }
+vector<T, 2> wz() const { return vector<T, 2>(w, z); }
+vector<T, 3> xyz() const { return vector<T, 3>(x, y, z); }
+vector<T, 3> xyw() const { return vector<T, 3>(x, y, w); }
+vector<T, 3> xzy() const { return vector<T, 3>(x, z, y); }
+vector<T, 3> xzw() const { return vector<T, 3>(x, z, w); }
+vector<T, 3> xwy() const { return vector<T, 3>(x, w, y); }
+vector<T, 3> xwz() const { return vector<T, 3>(x, w, z); }
+vector<T, 3> yxz() const { return vector<T, 3>(y, x, z); }
+vector<T, 3> yxw() const { return vector<T, 3>(y, x, w); }
+vector<T, 3> yzx() const { return vector<T, 3>(y, z, x); }
+vector<T, 3> yzw() const { return vector<T, 3>(y, z, w); }
+vector<T, 3> ywx() const { return vector<T, 3>(y, w, x); }
+vector<T, 3> ywz() const { return vector<T, 3>(y, w, z); }
+vector<T, 3> zxy() const { return vector<T, 3>(z, x, y); }
+vector<T, 3> zxw() const { return vector<T, 3>(z, x, w); }
+vector<T, 3> zyx() const { return vector<T, 3>(z, y, x); }
+vector<T, 3> zyw() const { return vector<T, 3>(z, y, w); }
+vector<T, 3> zwx() const { return vector<T, 3>(z, w, x); }
+vector<T, 3> zwy() const { return vector<T, 3>(z, w, y); }
+vector<T, 3> wxy() const { return vector<T, 3>(w, x, y); }
+vector<T, 3> wxz() const { return vector<T, 3>(w, x, z); }
+vector<T, 3> wyx() const { return vector<T, 3>(w, y, x); }
+vector<T, 3> wyz() const { return vector<T, 3>(w, y, z); }
+vector<T, 3> wzx() const { return vector<T, 3>(w, z, x); }
+vector<T, 3> wzy() const { return vector<T, 3>(w, z, y); }
+const vector<T, 4> &xyzw() const { return *this; }
+vector<T, 4> xywz() const { return vector<T, 4>(x, y, w, z); }
+vector<T, 4> xzyw() const { return vector<T, 4>(x, z, y, w); }
+vector<T, 4> xzwy() const { return vector<T, 4>(x, z, w, y); }
+vector<T, 4> xwyz() const { return vector<T, 4>(x, w, y, z); }
+vector<T, 4> xwzy() const { return vector<T, 4>(x, w, z, y); }
+vector<T, 4> yxzw() const { return vector<T, 4>(y, x, z, w); }
+vector<T, 4> yxwz() const { return vector<T, 4>(y, x, w, z); }
+vector<T, 4> yzxw() const { return vector<T, 4>(y, z, x, w); }
+vector<T, 4> yzwx() const { return vector<T, 4>(y, z, w, x); }
+vector<T, 4> ywxz() const { return vector<T, 4>(y, w, x, z); }
+vector<T, 4> ywzx() const { return vector<T, 4>(y, w, z, x); }
+vector<T, 4> zxyw() const { return vector<T, 4>(z, x, y, w); }
+vector<T, 4> zxwy() const { return vector<T, 4>(z, x, w, y); }
+vector<T, 4> zyxw() const { return vector<T, 4>(z, y, x, w); }
+vector<T, 4> zywx() const { return vector<T, 4>(z, y, w, x); }
+vector<T, 4> zwxy() const { return vector<T, 4>(z, w, x, y); }
+vector<T, 4> zwyx() const { return vector<T, 4>(z, w, y, x); }
+vector<T, 4> wxyz() const { return vector<T, 4>(w, x, y, z); }
+vector<T, 4> wxzy() const { return vector<T, 4>(w, x, z, y); }
+vector<T, 4> wyxz() const { return vector<T, 4>(w, y, x, z); }
+vector<T, 4> wyzx() const { return vector<T, 4>(w, y, z, x); }
+vector<T, 4> wzxy() const { return vector<T, 4>(w, z, x, y); }
+vector<T, 4> wzyx() const { return vector<T, 4>(w, z, y, x); }
+vector<T, 2> rg() const { return vector<T, 2>(r, g); }
+vector<T, 2> rb() const { return vector<T, 2>(r, b); }
+vector<T, 2> ra() const { return vector<T, 2>(r, a); }
+vector<T, 2> gr() const { return vector<T, 2>(g, r); }
+vector<T, 2> gb() const { return vector<T, 2>(g, b); }
+vector<T, 2> ga() const { return vector<T, 2>(g, a); }
+vector<T, 2> br() const { return vector<T, 2>(b, r); }
+vector<T, 2> bg() const { return vector<T, 2>(b, g); }
+vector<T, 2> ba() const { return vector<T, 2>(b, a); }
+vector<T, 2> ar() const { return vector<T, 2>(a, r); }
+vector<T, 2> ag() const { return vector<T, 2>(a, g); }
+vector<T, 2> ab() const { return vector<T, 2>(a, b); }
+vector<T, 3> rgb() const { return vector<T, 3>(r, g, b); }
+vector<T, 3> rga() const { return vector<T, 3>(r, g, a); }
+vector<T, 3> rbg() const { return vector<T, 3>(r, b, g); }
+vector<T, 3> rba() const { return vector<T, 3>(r, b, a); }
+vector<T, 3> rag() const { return vector<T, 3>(r, a, g); }
+vector<T, 3> rab() const { return vector<T, 3>(r, a, b); }
+vector<T, 3> grb() const { return vector<T, 3>(g, r, b); }
+vector<T, 3> gra() const { return vector<T, 3>(g, r, a); }
+vector<T, 3> gbr() const { return vector<T, 3>(g, b, r); }
+vector<T, 3> gba() const { return vector<T, 3>(g, b, a); }
+vector<T, 3> gar() const { return vector<T, 3>(g, a, r); }
+vector<T, 3> gab() const { return vector<T, 3>(g, a, b); }
+vector<T, 3> brg() const { return vector<T, 3>(b, r, g); }
+vector<T, 3> bra() const { return vector<T, 3>(b, r, a); }
+vector<T, 3> bgr() const { return vector<T, 3>(b, g, r); }
+vector<T, 3> bga() const { return vector<T, 3>(b, g, a); }
+vector<T, 3> bar() const { return vector<T, 3>(b, a, r); }
+vector<T, 3> bag() const { return vector<T, 3>(b, a, g); }
+vector<T, 3> arg() const { return vector<T, 3>(a, r, g); }
+vector<T, 3> arb() const { return vector<T, 3>(a, r, b); }
+vector<T, 3> agr() const { return vector<T, 3>(a, g, r); }
+vector<T, 3> agb() const { return vector<T, 3>(a, g, b); }
+vector<T, 3> abr() const { return vector<T, 3>(a, b, r); }
+vector<T, 3> abg() const { return vector<T, 3>(a, b, g); }
+const vector<T, 4> &rgba() const { return *this; }
+vector<T, 4> rgab() const { return vector<T, 4>(r, g, a, b); }
+vector<T, 4> rbga() const { return vector<T, 4>(r, b, g, a); }
+vector<T, 4> rbag() const { return vector<T, 4>(r, b, a, g); }
+vector<T, 4> ragb() const { return vector<T, 4>(r, a, g, b); }
+vector<T, 4> rabg() const { return vector<T, 4>(r, a, b, g); }
+vector<T, 4> grba() const { return vector<T, 4>(g, r, b, a); }
+vector<T, 4> grab() const { return vector<T, 4>(g, r, a, b); }
+vector<T, 4> gbra() const { return vector<T, 4>(g, b, r, a); }
+vector<T, 4> gbar() const { return vector<T, 4>(g, b, a, r); }
+vector<T, 4> garb() const { return vector<T, 4>(g, a, r, b); }
+vector<T, 4> gabr() const { return vector<T, 4>(g, a, b, r); }
+vector<T, 4> brga() const { return vector<T, 4>(b, r, g, a); }
+vector<T, 4> brag() const { return vector<T, 4>(b, r, a, g); }
+vector<T, 4> bgra() const { return vector<T, 4>(b, g, r, a); }
+vector<T, 4> bgar() const { return vector<T, 4>(b, g, a, r); }
+vector<T, 4> barg() const { return vector<T, 4>(b, a, r, g); }
+vector<T, 4> bagr() const { return vector<T, 4>(b, a, g, r); }
+vector<T, 4> argb() const { return vector<T, 4>(a, r, g, b); }
+vector<T, 4> arbg() const { return vector<T, 4>(a, r, b, g); }
+vector<T, 4> agrb() const { return vector<T, 4>(a, g, r, b); }
+vector<T, 4> agbr() const { return vector<T, 4>(a, g, b, r); }
+vector<T, 4> abrg() const { return vector<T, 4>(a, b, r, g); }
+vector<T, 4> abgr() const { return vector<T, 4>(a, b, g, r); }
+vector<T, 2> st() const { return vector<T, 2>(s, t); }
+vector<T, 2> sp() const { return vector<T, 2>(s, p); }
+vector<T, 2> sq() const { return vector<T, 2>(s, q); }
+vector<T, 2> ts() const { return vector<T, 2>(t, s); }
+vector<T, 2> tp() const { return vector<T, 2>(t, p); }
+vector<T, 2> tq() const { return vector<T, 2>(t, q); }
+vector<T, 2> ps() const { return vector<T, 2>(p, s); }
+vector<T, 2> pt() const { return vector<T, 2>(p, t); }
+vector<T, 2> pq() const { return vector<T, 2>(p, q); }
+vector<T, 2> qs() const { return vector<T, 2>(q, s); }
+vector<T, 2> qt() const { return vector<T, 2>(q, t); }
+vector<T, 2> qp() const { return vector<T, 2>(q, p); }
+vector<T, 3> stp() const { return vector<T, 3>(s, t, p); }
+vector<T, 3> stq() const { return vector<T, 3>(s, t, q); }
+vector<T, 3> spt() const { return vector<T, 3>(s, p, t); }
+vector<T, 3> spq() const { return vector<T, 3>(s, p, q); }
+vector<T, 3> sqt() const { return vector<T, 3>(s, q, t); }
+vector<T, 3> sqp() const { return vector<T, 3>(s, q, p); }
+vector<T, 3> tsp() const { return vector<T, 3>(t, s, p); }
+vector<T, 3> tsq() const { return vector<T, 3>(t, s, q); }
+vector<T, 3> tps() const { return vector<T, 3>(t, p, s); }
+vector<T, 3> tpq() const { return vector<T, 3>(t, p, q); }
+vector<T, 3> tqs() const { return vector<T, 3>(t, q, s); }
+vector<T, 3> tqp() const { return vector<T, 3>(t, q, p); }
+vector<T, 3> pst() const { return vector<T, 3>(p, s, t); }
+vector<T, 3> psq() const { return vector<T, 3>(p, s, q); }
+vector<T, 3> pts() const { return vector<T, 3>(p, t, s); }
+vector<T, 3> ptq() const { return vector<T, 3>(p, t, q); }
+vector<T, 3> pqs() const { return vector<T, 3>(p, q, s); }
+vector<T, 3> pqt() const { return vector<T, 3>(p, q, t); }
+vector<T, 3> qst() const { return vector<T, 3>(q, s, t); }
+vector<T, 3> qsp() const { return vector<T, 3>(q, s, p); }
+vector<T, 3> qts() const { return vector<T, 3>(q, t, s); }
+vector<T, 3> qtp() const { return vector<T, 3>(q, t, p); }
+vector<T, 3> qps() const { return vector<T, 3>(q, p, s); }
+vector<T, 3> qpt() const { return vector<T, 3>(q, p, t); }
+const vector<T, 4> &stpq() const { return *this; }
+vector<T, 4> stqp() const { return vector<T, 4>(s, t, q, p); }
+vector<T, 4> sptq() const { return vector<T, 4>(s, p, t, q); }
+vector<T, 4> spqt() const { return vector<T, 4>(s, p, q, t); }
+vector<T, 4> sqtp() const { return vector<T, 4>(s, q, t, p); }
+vector<T, 4> sqpt() const { return vector<T, 4>(s, q, p, t); }
+vector<T, 4> tspq() const { return vector<T, 4>(t, s, p, q); }
+vector<T, 4> tsqp() const { return vector<T, 4>(t, s, q, p); }
+vector<T, 4> tpsq() const { return vector<T, 4>(t, p, s, q); }
+vector<T, 4> tpqs() const { return vector<T, 4>(t, p, q, s); }
+vector<T, 4> tqsp() const { return vector<T, 4>(t, q, s, p); }
+vector<T, 4> tqps() const { return vector<T, 4>(t, q, p, s); }
+vector<T, 4> pstq() const { return vector<T, 4>(p, s, t, q); }
+vector<T, 4> psqt() const { return vector<T, 4>(p, s, q, t); }
+vector<T, 4> ptsq() const { return vector<T, 4>(p, t, s, q); }
+vector<T, 4> ptqs() const { return vector<T, 4>(p, t, q, s); }
+vector<T, 4> pqst() const { return vector<T, 4>(p, q, s, t); }
+vector<T, 4> pqts() const { return vector<T, 4>(p, q, t, s); }
+vector<T, 4> qstp() const { return vector<T, 4>(q, s, t, p); }
+vector<T, 4> qspt() const { return vector<T, 4>(q, s, p, t); }
+vector<T, 4> qtsp() const { return vector<T, 4>(q, t, s, p); }
+vector<T, 4> qtps() const { return vector<T, 4>(q, t, p, s); }
+vector<T, 4> qpst() const { return vector<T, 4>(q, p, s, t); }
+vector<T, 4> qpts() const { return vector<T, 4>(q, p, t, s); }

neglect/cpplib/include/neglect/math.hpp

     // but this gives the possibility to replace them later with more
     // optimized functions
     namespace math {
-        using std::sqrt;
+        static const double e  = 2.7182818284590452354;
+        static const double pi = 3.14159265358979323846;
+        static const double sqrt2 = 1.41421356237309504880;
+
+        template <typename T> T sqrt(T x) { return ::std::sqrt(x); }
+        template <typename T> T cos(T x) { return ::std::cos(x); }
+        template <typename T> T cosh(T x) { return ::std::cosh(x); }
+        template <typename T> T sin(T x) { return ::std::sin(x); }
+        template <typename T> T sinh(T x) { return ::std::sinh(x); }
+        template <typename T> T tan(T x) { return ::std::tan(x); }
+        template <typename T> T tanh(T x) { return ::std::tanh(x); }
+        template <typename T> T exp(T x) { return ::std::exp(x); }
+        template <typename T> T log(T x) { return ::std::log(x); }
+        template <typename T> T log10(T x) { return ::std::log10(x); }
+        template <typename T> T pow(T x) { return ::std::pow(x); }
+
+        template <typename T>
+        T deg_to_rad(T degrees)
+        {
+            return degrees * pi / 180.0f;
+        }
+
+        template <typename T>
+        T rad_to_deg(T radians)
+        {
+            return radians * 180.0f / pi;
+        }
     }
 }
 

neglect/cpplib/include/neglect/matrix.hpp

 
 namespace neglect {
 
+    /* matrices are stored column major and columns are represented
+       as vectors.  Because of that it's currently not possible to
+       create matrices with a height != 2, 3 or 4. */
+
     template <typename T, size_t Width, size_t Height>
     class matrix {
     public:
             return &m_cols[0].x;
         }
 
-        T &operator()(size_t column, size_t row)
+        T &operator()(size_t row, size_t column)
         {
             return m_cols[column][row];
         }
 
-        const T &operator()(size_t column, size_t row) const
+        const T &operator()(size_t row, size_t column) const
         {
             return m_cols[column][row];
         }
 
-        neglect::vector<T, Width> &operator[](size_t row)
+        neglect::vector<T, Height> &operator[](size_t row)
         {
             return m_cols[row];
         }
 
-        const neglect::vector<T, Width> &operator[](size_t row) const
+        const neglect::vector<T, Height> &operator[](size_t row) const
         {
             return m_cols[row];
         }
                 return false;
         return true;
     }
+
+    // matrix mathematic functions
+
+    template <typename T, size_t Width, size_t Height>
+    matrix<T, Height, Width> transpose(const matrix<T, Width, Height> &mat)
+    {
+        matrix<T, Height, Width> rv;
+        for (size_t i = 0; i < Width; i++)
+            for (size_t j = 0; j < Height; j++)
+                rv[j][i] = mat[i][j];
+        return rv;
+    }
+
+    // matrix factory functions
+
+    /* creates a scale matrix */
+    template <typename T>
+    matrix<T, 4, 4> scale_matrix(T sx, T zy, T sz)
+    {
+        matrix<T, 4, 4> m;
+        m[0][0] = sx;
+        m[1][1] = sy;
+        m[2][2] = sz;
+        m[3][3] = T(1);
+        return m;
+    }
+
+    /* creates a translation matrix */
+    template <typename T>
+    matrix<T, 4, 4> translation_matrix(T tx, T ty, T tz)
+    {
+        matrix<T, 4, 4> m;
+        m.set_identity();
+        vector<T, 4> &last = m[3];
+        last[0] = tx;
+        last[1] = ty;
+        last[2] = tz;
+        return m;
+    }
+
+    /* creates a rotation matrix */
+    template <typename T>
+    matrix<T, 4, 4> rotation_matrix(T angle, T x, T y, T z)
+    {
+        T rad_angle = math::deg_to_rad(angle);
+        T sin = math::sin(rad_angle), cos = math::cos(rad_angle);
+        T length = math::sqrt(x * x + y * y + z * z);
+        x /= length;
+        y /= length;
+        z /= length;
+        T sx = sin * x, sy = sin * y, sz = sin * z;
+        T ic = T(1) - cos;
+
+        matrix<T, 4, 4> m;
+        m[0] = vector<T, 4>(ic * x * x + c,
+                            ic * x * y + sz,
+                            ic * x * z - sy,
+                            T());
+        m[1] = vector<T, 4>(ic * x * y - sz,
+                            ic * y * y + c,
+                            ic * y * z + sz,
+                            T());
+        m[2] = vector<T, 4>(ic * x * z + sy,
+                            ic * y * z - sz,
+                            ic * z * z + c,
+                            T());
+        m[3][3] = T(1);
+        return m;
+    }
 }
 
 #endif

neglect/cpplib/include/neglect/matrix_io.hpp

         for (size_t row = 0; row < Height; row++) {
             if (row)
                 lhs << "," << std::endl << " ";
-            lhs << "[";
             for (size_t column = 0; column < Width; column++) {
                 if (column)
                     lhs << ", ";
                 lhs << rhs[column][row];
             }
-            lhs << "]";
         }
         return lhs << "]";
     }

neglect/cpplib/include/neglect/vector.hpp

     }
 }
 
-// the actual vector implementations
 #include <neglect/_vector2.hpp>
 #include <neglect/_vector3.hpp>
 #include <neglect/_vector4.hpp>

neglect/cpplib/libneglect.a

Binary file removed.

neglect/scripts/make_swizzle_includes.py

+import os
+import time
+from itertools import permutations
+
+vec_sets = {
+    2:  ["xy", "rg", "st"],
+    3:  ["xyz", "rgb", "stp"],
+    4:  ["xyzw", "rgba", "stpq"]
+}
+
+
+def swizzle_permutations(sets):
+    for x in xrange(2, len(set) + 1):
+        for p in permutations(set, x):
+            yield x, p
+
+
+os.chdir((os.path.dirname(__file__) or '.') + '/../cpplib/include/neglect')
+
+for vector_size, sets in vec_sets.iteritems():
+    with open('_vector%d_swizzle.inc' % vector_size, 'w') as f:
+        f.write('// this file was automatically generated by\n'
+                '// %s on %s.  DO NOT EDIT\n\n' %
+                (os.path.basename(__file__), time.ctime()))
+        for set in sets:
+            for result_size, elms in swizzle_permutations(set):
+                name = ''.join(elms)
+                if name == set:
+                    f.write('const vector<T, %d> &%s() const { return *this; }\n' % (
+                        result_size,
+                        name
+                    ))
+                else:
+                    f.write('vector<T, %d> %s() const { return vector<T, %d>(%s); }\n' % (
+                        result_size,
+                        name,
+                        result_size,
+                        ', '.join(elms)
+                    ))

neglect/tests/neglect_tests

Binary file removed.

neglect/tests/src/test_matrix.cpp

 
         for (int i = 0; i < 4; i++)
             for (int j = 0; j < 4; j++)
-                NUT_CHECK_EQUAL(m3[i][j], m3(i, j));
+                NUT_CHECK_EQUAL(m3[i][j], m3(j, i));
+    }
+
+    NUT_TESTCASE(dimensions)
+    {
+        NUT_CHECK_EQUAL(mat4::columns, 4);
+        NUT_CHECK_EQUAL(mat4::rows, 4);
+        NUT_CHECK_EQUAL(mat4::dimensions, 16);
+    }
+
+    NUT_TESTCASE(matrix_functions)
+    {
+        matrix<float, 3, 2> mat;
+        mat[0][1] = 1.0f;
+        mat[2][0] = 3.0f;
+        matrix<float, 2, 3> mat_t = transpose(mat);
+        NUT_CHECK_EQUAL(mat_t[1][0], 1.0f);
+        NUT_CHECK_EQUAL(mat_t[0][2], 3.0f);
+        NUT_CHECK_EQUAL(mat_t[0][0], 0.0f);
     }
 }

neglect/tests/src/test_vectors.cpp

 
         NUT_CHECK_EQUAL(v1.x, 1.0f);
         NUT_CHECK_EQUAL(v1.s, 1.0f);
+        NUT_CHECK_EQUAL(v1.r, 1.0f);
         NUT_CHECK_EQUAL(v1.y, 3.0f);
         NUT_CHECK_EQUAL(v1.t, 3.0f);
+        NUT_CHECK_EQUAL(v1.g, 3.0f);
     }
 
     NUT_TESTCASE(basic_math)
         NUT_CHECK_EQUAL(vf4, vi4);
         NUT_CHECK_NOT_EQUAL(vf4, vi4b);
     }
+
+    NUT_TESTCASE(swizzling)
+    {
+        vec3 v(1.0f, 2.0f, 3.0f);
+        NUT_CHECK_EQUAL(v.zx(), vec2(3.0f, 1.0f));
+        NUT_CHECK_EQUAL(v.zyx(), vec3(3.0f, 2.0f, 1.0f));
+        NUT_CHECK_EQUAL(v.xyz(), v);
+        NUT_CHECK_EQUAL(&v.xyz(), &v); // special case
+    }
 }