浏览代码

Updating vector to use my vector project, instead of duplicating it.

Samuel Jaffe 9 年之前
父节点
当前提交
0fed4d9547
共有 9 个文件被更改,包括 12 次插入548 次删除
  1. 3 0
      .gitmodules
  2. 1 1
      engine/events.hpp
  3. 1 1
      engine/game_dispatch.hpp
  4. 1 1
      engine/scene.hpp
  5. 4 100
      math/math.xcodeproj/project.pbxproj
  6. 1 1
      math/shape.hpp
  7. 1 0
      math/vector
  8. 0 284
      math/vector.hpp
  9. 0 160
      math/vector.t.h

+ 3 - 0
.gitmodules

@@ -8,3 +8,6 @@
 	path = include/expect
 	url = freenas:utility/expect
 	branch = master
+[submodule "math/vector"]
+	path = math/vector
+	url = freenas:utility/vector

+ 1 - 1
engine/events.hpp

@@ -9,7 +9,7 @@
 
 #include "engine_fwd.hpp"
 #include "math/math_fwd.hpp"
-#include "math/vector.hpp"
+#include "math/vector/vector.hpp"
 
 namespace engine {
   namespace key {

+ 1 - 1
engine/game_dispatch.hpp

@@ -15,7 +15,7 @@
 #include "engine_fwd.hpp"
 #include "events.hpp"
 #include "math/math_fwd.hpp"
-#include "math/vector.hpp"
+#include "math/vector/vector.hpp"
 
 namespace engine {
   class game_dispatch {

+ 1 - 1
engine/scene.hpp

@@ -11,7 +11,7 @@
 
 #include "engine_fwd.hpp"
 #include "math/math_fwd.hpp"
-#include "math/vector.hpp"
+#include "math/vector/vector.hpp"
 #include "util/identity.hpp"
 
 namespace engine {  

+ 4 - 100
math/math.xcodeproj/project.pbxproj

@@ -7,11 +7,10 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		CD3786271CF9F67B00BE89B2 /* vector.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD3786261CF9F67B00BE89B2 /* vector.hpp */; };
+		CD0E42491D9B3673002FFED1 /* vector.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD0E42481D9B3673002FFED1 /* vector.hpp */; };
 		CD37862D1CFA121C00BE89B2 /* matrix.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD37862C1CFA121C00BE89B2 /* matrix.hpp */; };
 		CD3AC71E1D2C0AF8002B4BB0 /* shape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3AC71C1D2C0AF8002B4BB0 /* shape.cpp */; };
 		CD3AC71F1D2C0AF8002B4BB0 /* shape.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD3AC71D1D2C0AF8002B4BB0 /* shape.hpp */; };
-		CD3C80881D6645C600ACC795 /* vector_tc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3C80871D6645C600ACC795 /* vector_tc.cpp */; };
 		CD3C808A1D66469400ACC795 /* math_fwd.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD3AC6FA1D2C0558002B4BB0 /* math_fwd.hpp */; };
 		CD3C809A1D6654C200ACC795 /* matrix_tc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3C80981D6654C200ACC795 /* matrix_tc.cpp */; };
 		CD3C809F1D675AB100ACC795 /* angle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3C809D1D675AB100ACC795 /* angle.cpp */; };
@@ -23,15 +22,6 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXCopyFilesBuildPhase section */
-		CD3C807E1D6645AB00ACC795 /* CopyFiles */ = {
-			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
-			dstPath = /usr/share/man/man1/;
-			dstSubfolderSpec = 0;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 1;
-		};
 		CD3C808F1D6654A400ACC795 /* CopyFiles */ = {
 			isa = PBXCopyFilesBuildPhase;
 			buildActionMask = 2147483647;
@@ -44,15 +34,12 @@
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
+		CD0E42481D9B3673002FFED1 /* vector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = vector.hpp; path = vector/vector.hpp; sourceTree = "<group>"; };
 		CD3786181CF9F61100BE89B2 /* libmath.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libmath.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
-		CD3786261CF9F67B00BE89B2 /* vector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = vector.hpp; sourceTree = "<group>"; };
 		CD37862C1CFA121C00BE89B2 /* matrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = matrix.hpp; sourceTree = "<group>"; };
 		CD3AC6FA1D2C0558002B4BB0 /* math_fwd.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = math_fwd.hpp; sourceTree = "<group>"; };
 		CD3AC71C1D2C0AF8002B4BB0 /* shape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shape.cpp; sourceTree = "<group>"; };
 		CD3AC71D1D2C0AF8002B4BB0 /* shape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = shape.hpp; sourceTree = "<group>"; };
-		CD3C807A1D66440A00ACC795 /* vector.t.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = vector.t.h; sourceTree = "<group>"; };
-		CD3C80801D6645AB00ACC795 /* vector_tc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = vector_tc; sourceTree = BUILT_PRODUCTS_DIR; };
-		CD3C80871D6645C600ACC795 /* vector_tc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = vector_tc.cpp; sourceTree = "<group>"; };
 		CD3C80911D6654A400ACC795 /* matrix_tc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = matrix_tc; sourceTree = BUILT_PRODUCTS_DIR; };
 		CD3C80981D6654C200ACC795 /* matrix_tc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = matrix_tc.cpp; sourceTree = "<group>"; };
 		CD3C80991D6654C200ACC795 /* matrix.t.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = matrix.t.h; sourceTree = "<group>"; };
@@ -71,13 +58,6 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		CD3C807D1D6645AB00ACC795 /* Frameworks */ = {
-			isa = PBXFrameworksBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
 		CD3C808E1D6654A400ACC795 /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
@@ -102,7 +82,6 @@
 			isa = PBXGroup;
 			children = (
 				CD3786181CF9F61100BE89B2 /* libmath.dylib */,
-				CD3C80801D6645AB00ACC795 /* vector_tc */,
 				CD3C80911D6654A400ACC795 /* matrix_tc */,
 			);
 			name = Products;
@@ -111,7 +90,7 @@
 		CD3786321CFA304800BE89B2 /* src */ = {
 			isa = PBXGroup;
 			children = (
-				CD3786261CF9F67B00BE89B2 /* vector.hpp */,
+				CD0E42481D9B3673002FFED1 /* vector.hpp */,
 				CD3AC6FA1D2C0558002B4BB0 /* math_fwd.hpp */,
 				CD37862C1CFA121C00BE89B2 /* matrix.hpp */,
 				CD3C80B81D6884D700ACC795 /* matrix_helpers.hpp */,
@@ -128,9 +107,7 @@
 		CD3C80791D66440200ACC795 /* test */ = {
 			isa = PBXGroup;
 			children = (
-				CD3C807A1D66440A00ACC795 /* vector.t.h */,
 				CD3C80991D6654C200ACC795 /* matrix.t.h */,
-				CD3C80871D6645C600ACC795 /* vector_tc.cpp */,
 				CD3C80981D6654C200ACC795 /* matrix_tc.cpp */,
 			);
 			name = test;
@@ -143,10 +120,10 @@
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				CD3786271CF9F67B00BE89B2 /* vector.hpp in Headers */,
 				CD3AC71F1D2C0AF8002B4BB0 /* shape.hpp in Headers */,
 				CD37862D1CFA121C00BE89B2 /* matrix.hpp in Headers */,
 				CD3C80A01D675AB100ACC795 /* angle.hpp in Headers */,
+				CD0E42491D9B3673002FFED1 /* vector.hpp in Headers */,
 				CD3C808A1D66469400ACC795 /* math_fwd.hpp in Headers */,
 				CD3C80BD1D68902300ACC795 /* common.hpp in Headers */,
 				CD3C80B91D6884D700ACC795 /* matrix_helpers.hpp in Headers */,
@@ -173,24 +150,6 @@
 			productReference = CD3786181CF9F61100BE89B2 /* libmath.dylib */;
 			productType = "com.apple.product-type.library.dynamic";
 		};
-		CD3C807F1D6645AB00ACC795 /* vector_tc */ = {
-			isa = PBXNativeTarget;
-			buildConfigurationList = CD3C80841D6645AB00ACC795 /* Build configuration list for PBXNativeTarget "vector_tc" */;
-			buildPhases = (
-				CD3C80891D6645ED00ACC795 /* ShellScript */,
-				CD3C807C1D6645AB00ACC795 /* Sources */,
-				CD3C807D1D6645AB00ACC795 /* Frameworks */,
-				CD3C807E1D6645AB00ACC795 /* CopyFiles */,
-			);
-			buildRules = (
-			);
-			dependencies = (
-			);
-			name = vector_tc;
-			productName = vector_tc;
-			productReference = CD3C80801D6645AB00ACC795 /* vector_tc */;
-			productType = "com.apple.product-type.tool";
-		};
 		CD3C80901D6654A400ACC795 /* matrix_tc */ = {
 			isa = PBXNativeTarget;
 			buildConfigurationList = CD3C80951D6654A400ACC795 /* Build configuration list for PBXNativeTarget "matrix_tc" */;
@@ -221,9 +180,6 @@
 					CD3786171CF9F61100BE89B2 = {
 						CreatedOnToolsVersion = 7.2.1;
 					};
-					CD3C807F1D6645AB00ACC795 = {
-						CreatedOnToolsVersion = 7.2.1;
-					};
 					CD3C80901D6654A400ACC795 = {
 						CreatedOnToolsVersion = 7.2.1;
 					};
@@ -242,27 +198,12 @@
 			projectRoot = "";
 			targets = (
 				CD3786171CF9F61100BE89B2 /* math */,
-				CD3C807F1D6645AB00ACC795 /* vector_tc */,
 				CD3C80901D6654A400ACC795 /* matrix_tc */,
 			);
 		};
 /* End PBXProject section */
 
 /* Begin PBXShellScriptBuildPhase section */
-		CD3C80891D6645ED00ACC795 /* ShellScript */ = {
-			isa = PBXShellScriptBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			inputPaths = (
-				"$(SRCROOT)/vector.t.h",
-			);
-			outputPaths = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "cxxtestgen --error-printer -o vector_tc.cpp vector.t.h";
-		};
 		CD3C809B1D66556900ACC795 /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
 			buildActionMask = 2147483647;
@@ -290,14 +231,6 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		CD3C807C1D6645AB00ACC795 /* Sources */ = {
-			isa = PBXSourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-				CD3C80881D6645C600ACC795 /* vector_tc.cpp in Sources */,
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
 		CD3C808D1D6654A400ACC795 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
@@ -416,26 +349,6 @@
 			};
 			name = Release;
 		};
-		CD3C80851D6645AB00ACC795 /* Debug */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				HEADER_SEARCH_PATHS = /usr/local/include;
-				PRODUCT_NAME = "$(TARGET_NAME)";
-				USER_HEADER_SEARCH_PATHS = ..;
-			};
-			name = Debug;
-		};
-		CD3C80861D6645AB00ACC795 /* Release */ = {
-			isa = XCBuildConfiguration;
-			buildSettings = {
-				GCC_GENERATE_TEST_COVERAGE_FILES = YES;
-				GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
-				HEADER_SEARCH_PATHS = /usr/local/include;
-				PRODUCT_NAME = "$(TARGET_NAME)";
-				USER_HEADER_SEARCH_PATHS = ..;
-			};
-			name = Release;
-		};
 		CD3C80961D6654A400ACC795 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
@@ -479,15 +392,6 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
-		CD3C80841D6645AB00ACC795 /* Build configuration list for PBXNativeTarget "vector_tc" */ = {
-			isa = XCConfigurationList;
-			buildConfigurations = (
-				CD3C80851D6645AB00ACC795 /* Debug */,
-				CD3C80861D6645AB00ACC795 /* Release */,
-			);
-			defaultConfigurationIsVisible = 0;
-			defaultConfigurationName = Release;
-		};
 		CD3C80951D6654A400ACC795 /* Build configuration list for PBXNativeTarget "matrix_tc" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (

+ 1 - 1
math/shape.hpp

@@ -7,7 +7,7 @@
 
 #pragma once
 
-#include "vector.hpp"
+#include "vector/vector.hpp"
 #include "math_fwd.hpp"
 
 namespace math {

+ 1 - 0
math/vector

@@ -0,0 +1 @@
+Subproject commit 2d5980e8d10bcd91f706906d78785ff734f6ac26

+ 0 - 284
math/vector.hpp

@@ -1,284 +0,0 @@
-//
-//  vector.hpp
-//  vector
-//
-//  Created by Sam Jaffe on 8/15/16.
-//
-
-#pragma once
-
-#include <cassert>
-#include <cmath>
-#include <cstddef>
-
-#include <array>
-#include <initializer_list>
-#include <stdexcept>
-#include <type_traits>
-
-#include "expect/expect.hpp"
-
-namespace math { namespace vector {
-#define VECTOR_ENABLE_IF_LT_N(index, expr) \
-template <bool _ = true> \
-typename std::enable_if<std::size_t(index) < N && _, expr>::type
-  
-#define VECTOR_ENABLE_IF_EQ_N(index, t, n) \
-template <bool _ = true> \
-typename std::enable_if<std::size_t(index) == N && _, vector<t, n> >::type
-
-#define VECTOR_ENABLE_IF_EQ_T(_type, t, n) \
-typename std::enable_if<std::is_same<_type, t>::value, vector<t, n> >::type
-  
-#define VECTOR_DISABLE_IF_VECTOR(_type, t, n) \
-typename std::enable_if<!is_vector<_type>::value, vector<t, n> >::type
-
-#define VECTOR_ACCESS_FN(name, i) \
-VECTOR_ENABLE_IF_LT_N(i, value_type const &) name() const { return _data[i]; } \
-VECTOR_ENABLE_IF_LT_N(i, value_type &) name() { return _data[i]; }
-
-#define VECTOR_FOR_EACH_RANGE(var, end) for (std::size_t var = 0; var < end; ++var)
-#define VECTOR_FOR_EACH(var) VECTOR_FOR_EACH_RANGE(var, N)
-  
-  struct {} fill;
-  using fill_t = decltype(fill);
-  
-  template <typename T>
-  struct is_vector { static const constexpr bool value = false; };
-  
-  template <typename T, std::size_t N>
-  class vector;
-  template <typename T, std::size_t N>
-  struct is_vector<vector<T, N>> { static const constexpr bool value = true; };
-  
-  template <typename T, std::size_t N>
-  class vector {
-  public:
-    using value_type = T;
-  private:
-    using mag_t = decltype(std::sqrt(std::declval<T>()));
-    template <typename M>
-    using mul_t = decltype(std::declval<T>()*std::declval<M>());
-    template <typename M>
-    using div_t = decltype(std::declval<T>()/std::declval<M>());
-  public:
-    
-    // Constructors
-    vector() = default;
-    
-    vector(std::initializer_list<T> && init) {
-      expects(init.size() == N, "initializer size mismatch");
-      std::size_t idx = 0;
-      for ( auto it = init.begin(), end = init.end(); it != end && idx < N; ++it, ++idx ) {
-        _data[idx] = *it;
-      }
-    }
-    
-    vector(std::array<T, N> const & init) {
-      VECTOR_FOR_EACH(i) { _data[i] = init[i]; }
-    }
-    
-    vector(vector const & other) {
-      *this = other;
-    }
-    
-    vector(vector && other) {
-      *this = std::move(other);
-    }
-    
-    // Conversion
-    template <typename T2, std::size_t N2>
-    explicit vector(vector<T2, N2> const & other) {
-      VECTOR_FOR_EACH_RANGE(i, std::min(N, N2)) {
-        _data[i] = static_cast<T>(other[i]);
-      }
-    }
-    
-    vector(T const & v, fill_t) {
-      VECTOR_FOR_EACH(i) { _data[i] = v; }
-    }
-    
-    // Assignment
-    vector& operator=(vector const & other) {
-      VECTOR_FOR_EACH(i) { _data[i] = other[i]; }
-      return *this;
-    }
-    
-    vector& operator=(vector && other) {
-      VECTOR_FOR_EACH(i) { _data[i] = std::move(other._data[i]); }
-      return *this;
-    }
-    
-    // Named Accessors
-    // - Numeric Vector Accessors
-    VECTOR_ACCESS_FN(x, 0)
-    VECTOR_ACCESS_FN(y, 1)
-    VECTOR_ACCESS_FN(z, 2)
-    VECTOR_ACCESS_FN(w, 3)
-    
-    // - Color Vector Accessors
-    VECTOR_ACCESS_FN(r, 0)
-    VECTOR_ACCESS_FN(g, 1)
-    VECTOR_ACCESS_FN(b, 2)
-    VECTOR_ACCESS_FN(a, 3)
-    
-    // Unnamed Accessors
-    value_type const & operator[](std::size_t idx) const {
-      return _data[idx];
-    }
-    
-    value_type & operator[](std::size_t idx) {
-      return _data[idx];
-    }
-    
-    value_type const & at(std::size_t idx) const {
-      expects(idx < N, std::out_of_range, "index out of range");
-      return _data[idx];
-    }
-    
-    value_type & at(std::size_t idx) {
-      expects(idx < N, std::out_of_range, "index out of range");
-      return _data[idx];
-    }
-    
-    // Mathematical Operations
-    vector& operator+=(vector const & other) {
-      VECTOR_FOR_EACH(i) { _data[i] += other[i]; }
-      return *this;
-    }
-    
-    vector operator+(vector const & other) const {
-      return vector{*this} += other;
-    }
-
-    vector& operator-=(vector const & other) {
-      VECTOR_FOR_EACH(i) { _data[i] -= other[i]; }
-      return *this;
-    }
-    
-    vector operator-(vector const & other) const {
-      return vector{*this} -= other;
-    }
-
-    vector operator-() const {
-      return vector{} -= *this;
-    }
-
-    template <typename M>
-    VECTOR_ENABLE_IF_EQ_T(mul_t<M>, T, N)& operator*=(M c) {
-      VECTOR_FOR_EACH(i) { _data[i] *= c; }
-      return *this;
-    }
-    
-    template <typename M>
-    VECTOR_DISABLE_IF_VECTOR(M, mul_t<M>, N) operator*(M c) const {
-      return vector<mul_t<M>, N>{*this} *= c;
-    }
-    
-    template <typename M>
-    friend VECTOR_DISABLE_IF_VECTOR(M, mul_t<M>, N) operator*(M c, vector<T, N> const & v) {
-      return v * c;
-    }
-    
-    template <typename M>
-    VECTOR_ENABLE_IF_EQ_T(mul_t<M>, T, N)& operator*=(vector<M, N> c) {
-      return vector<mul_t<M>, N>{*this} *= c;
-    }
-    
-    template <typename M>
-    vector<mul_t<M>, N> operator*(vector<M, N> const & other) const {
-      return vector<mul_t<M>, N>{*this} *= other;
-    }
-    
-    template <typename M>
-    VECTOR_ENABLE_IF_EQ_T(div_t<M>, T, N)& operator/=(M c) {
-      expects(c != 0, std::domain_error, "divide by zero");
-      VECTOR_FOR_EACH(i) { _data[i] /= c; }
-      return *this;
-    }
-    
-    template <typename M>
-    VECTOR_DISABLE_IF_VECTOR(M, div_t<M>, N) operator/(M c) const {
-      return vector<div_t<M>, N>{*this} /= c;
-    }
-    
-    template <typename M>
-    VECTOR_ENABLE_IF_EQ_T(div_t<M>, T, N)& operator/=(vector<M, N> c) {
-      VECTOR_FOR_EACH(i) { expects(c[i] != 0, std::domain_error, "divide by zero"); }
-      VECTOR_FOR_EACH(i) { _data[i] /= c[i]; }
-      return *this;
-    }
-    
-    template <typename M>
-    vector<div_t<M>, N> operator/(vector<M, N> const & other) const {
-      return vector<div_t<M>, N>{*this} /= other;
-    }
-    
-    // Vector Operations
-    value_type dot(vector const & other) const {
-      value_type accum{};
-      VECTOR_FOR_EACH(i) { accum += at(i) * other.at(i); }
-      return accum;
-    }
-    
-    mag_t magnitude() const {
-      return std::sqrt(dot(*this));
-    }
-    
-    vector<mag_t, N> unit() const {
-      return *this / magnitude();
-    }
-    
-    VECTOR_ENABLE_IF_EQ_N(3, T, N) cross(vector const & other) const {
-      return {
-        y()*other.z() - z()*other.y(),
-        z()*other.x() - x()*other.z(),
-        x()*other.y() - y()*other.x()
-      };
-    }
-
-    VECTOR_ENABLE_IF_EQ_N(2, T, 3) cross(vector const & other) const {
-      return { 0, 0, x()*other.y() - y()*other.x() };
-    }
-    
-    vector<mag_t, N> projection(vector const & other) const {
-      vector<mag_t, N> b_p = other.unit();
-      return b_p * vector<mag_t, N>{*this}.dot(b_p);
-    }
-    
-  private:
-    value_type _data[N] = {value_type()};
-  };
-  
-  template <typename T, std::size_t N>
-  vector<T, N> abs(vector<T, N> const & self) {
-    vector<T, N> tmp(self);
-    using std::abs;
-    VECTOR_FOR_EACH(i) { tmp[i] = abs(tmp[i]); }
-    return tmp;
-  }
-
-  template <typename T, std::size_t N>
-  int compare(vector<T, N> const & lhs, vector<T, N> const & rhs) {
-    VECTOR_FOR_EACH(i) {
-      if (lhs[i] < rhs[i]) return -1;
-      else if (lhs[i] > rhs[i]) return 1;
-    }
-    return 0;
-  }
-
-  template <typename T, std::size_t N>
-  bool operator==(vector<T, N> const & lhs, vector<T, N> const & rhs) { return compare(lhs, rhs) == 0; }
-  template <typename T, std::size_t N>
-  bool operator!=(vector<T, N> const & lhs, vector<T, N> const & rhs) { return compare(lhs, rhs) != 0; }
-  template <typename T, std::size_t N>
-  bool operator< (vector<T, N> const & lhs, vector<T, N> const & rhs) { return compare(lhs, rhs) <  0; }
-  template <typename T, std::size_t N>
-  bool operator<=(vector<T, N> const & lhs, vector<T, N> const & rhs) { return compare(lhs, rhs) <= 0; }
-  template <typename T, std::size_t N>
-  bool operator> (vector<T, N> const & lhs, vector<T, N> const & rhs) { return compare(lhs, rhs) >  0; }
-  template <typename T, std::size_t N>
-  bool operator>=(vector<T, N> const & lhs, vector<T, N> const & rhs) { return compare(lhs, rhs) >= 0; }
-} }
-
-using math::vector::abs;

+ 0 - 160
math/vector.t.h

@@ -1,160 +0,0 @@
-#include <cxxtest/TestSuite.h>
-
-#include "vector.hpp"
-
-class vector_TestSuite : public CxxTest::TestSuite {
-public:
-  using vec2i = math::vector::vector<int, 2>;
-  using vec3  = math::vector::vector<double, 3>;
-  using vec3i = math::vector::vector<int, 3>;
-  using vec4i = math::vector::vector<int, 4>;
-
-  void test_vector_badsize_throws() const {
-    TS_ASSERT_THROWS((vec2i{1}), std::logic_error);
-    TS_ASSERT_THROWS((vec2i{1,1,1}), std::logic_error);
-  }
-  
-  void test_vector_equals() const {
-    TS_ASSERT_EQUALS(iota3i(), (vec3i{1, 2, 3}));
-  }
-  
-  void test_vector_notequals() const {
-    TS_ASSERT_DIFFERS(iota3i(), (vec3i{0, 2, 3}));
-  }
-  
-  void test_vector_elems() const {
-    math::vector::vector<int, 3> viota = iota3i();
-    TS_ASSERT_EQUALS(viota[0], 1);
-    TS_ASSERT_EQUALS(viota[1], 2);
-    TS_ASSERT_EQUALS(viota[2], 3);
-  }
-  
-  void test_vector_oob() const {
-    TS_ASSERT_THROWS((iota<int, 3>()).at(3), std::out_of_range);
-  }
-  
-  void test_default_zero() const {
-    TS_ASSERT_EQUALS(vec3i(), (vec3i{0,0,0}));
-  }
-  
-  void test_extends_with_zero() const {
-    TS_ASSERT_EQUALS(vec4i(iota3i()), (vec4i{1,2,3,0}));
-  }
-  
-  void test_vec2_cross() const {
-    TS_ASSERT_EQUALS((vec2i{1,1}.cross(vec2i{-1,1})), (vec3i{0,0,2}));
-  }
-  
-  void test_vec3_cross() const {
-    TS_ASSERT_EQUALS((vec3i{1,1,2}.cross(vec3i{-1,1,1})), (vec3i{-1,-3,2}));
-  }
-  
-  void test_vector_addition_vector() const {
-    TS_ASSERT_EQUALS((vec2i{1,0} + vec2i{0,1}), (vec2i{1,1}))
-  }
-  
-  void test_vector_subtraction_vector() const {
-    TS_ASSERT_EQUALS((vec2i{1,0} - vec2i{0,1}), (vec2i{1,-1}))
-  }
-  
-  void test_vector_multiplication_vector() const {
-    TS_ASSERT_EQUALS((vec2i{1,0}*(vec2i{2,1})), (vec2i{2,0}))
-  }
-  
-  void test_vector_divides_vector() const {
-    TS_ASSERT_EQUALS((vec2i{6,4}/(vec2i{2,1})), (vec2i{3,4}))
-  }
-  
-  void test_divide_by_zero_fails() const {
-    TS_ASSERT_THROWS(vec3{} / 0, std::domain_error);
-    TS_ASSERT_THROWS((vec3{1.0, 1.0, 1.0}/(vec3{1.0, 0.5, 0.0})), std::domain_error);
-  }
-  
-//  void test_vector_addition_value() const {
-//    TS_ASSERT_EQUALS((vec2i{1,0} + 1), (vec2i{2,1}))
-//  }
-//  
-//  void test_vector_subtraction_value() const {
-//    TS_ASSERT_EQUALS((vec2i{1,0} - 1), (vec2i{0,-1}))
-//  }
-  
-  void test_vector_multiplication_value() const {
-    TS_ASSERT_EQUALS((vec2i{1,0} * 3), (vec2i{3,0}))
-  }
-  
-  void test_vector_divides_value() const {
-    TS_ASSERT_EQUALS((vec2i{6,4} / 2), (vec2i{3,2}))
-  }
-  
-//  void test_value_addition_vector() const {
-//    TS_ASSERT_EQUALS(1+iota2i(), (vec2i{2,3}));
-//  }
-//  
-//  void test_value_subtraction_vector() const {
-//    TS_ASSERT_EQUALS(4-iota2i(), (vec2i{3,2}));
-//  }
-  
-  void test_value_multiplication_vector() const {
-    TS_ASSERT_EQUALS(2*iota2i(), (vec2i{2,4}));
-  }
-  
-//  void test_value_divides_vector() const {
-//    TS_ASSERT_EQUALS(4/iota2i(), (vec2i{4,2}));
-//  }
-  
-  void test_length_of_vector() const {
-//    TS_ASSERT_EQUALS(iota3i().lengthSquared(), 14);
-    TS_ASSERT_DELTA(iota3i().magnitude(), std::sqrt(14), 0.00001);
-  }
-  
-  void test_distance_of_vector() const {
-//    TS_ASSERT_EQUALS((iota3i().distanceSquared(vec3i{3, 1, -1})), 21);
-    TS_ASSERT_DELTA((iota3i() - vec3i{3, 1, -1}).magnitude(), std::sqrt(21), 0.00001);
-  }
-  
-  void test_projection_of_vector() const {
-    TS_ASSERT_DELTA((iota3i().projection(vec3i{3, 1, -1})).magnitude(), std::sqrt(4.0/11.0), 0.00001);
-  }
-  
-  void test_dot_product() const {
-    TS_ASSERT_EQUALS((iota3i().dot(vec3i{3, 0, -1})), 0);
-  }
-  
-  void test_unit_vector() const {
-    double sq = std::sqrt(14);
-    vec3 epsilon{0.00001, math::vector::fill};
-    TS_ASSERT_DELTA(iota3i().unit(), (vec3{1/sq, 2/sq, 3/sq}), epsilon);
-  }
-  
-  void test_type_shift() const {
-    TS_ASSERT_EQUALS((vec3i(vec3{1.0, 2.3, 3.9})), iota3i());
-  }
-  
-  void test_swap() const {
-    using std::swap;
-    vec2i a{1, 2}; const vec2i ac = a;
-    vec2i b{5, 7}; const vec2i bc = b;
-    swap(a, b);
-    TS_ASSERT_EQUALS(a, bc);
-    TS_ASSERT_EQUALS(b, ac);
-  }
-  
-  void test_negate_vector() const {
-    TS_ASSERT_EQUALS(-iota3i(), (vec3i{-1,-2,-3}));
-  }
-  
-  void test_absolute_value() const {
-    TS_ASSERT_EQUALS(iota3i(), abs(-iota3i()));
-  }
-  
-private:
-  
-  template <typename T, size_t N> math::vector::vector<T, N> iota() const {
-    math::vector::vector<T, N> rval;
-    for (size_t i = 0; i < N; ++i) rval[i] = static_cast<T>(i+1);
-    return rval;
-  }
-  
-  vec2i iota2i() const { return iota<int, 2>(); }
-  vec3i iota3i() const { return iota<int, 3>(); }
-};