OSDN Git Service

matrix testing
authortomohiro yasutomo <o_ggy@users.sourceforge.jp>
Wed, 18 Aug 2010 20:25:28 +0000 (13:25 -0700)
committertomohiro yasutomo <o_ggy@users.sourceforge.jp>
Wed, 18 Aug 2010 20:25:28 +0000 (13:25 -0700)
50 files changed:
TODO.txt
bin/numeric
include/mof/base/mofdef.hpp [deleted file]
include/mof/base/tstring.hpp [deleted file]
include/mof/math/basic_matrix.hpp [deleted file]
include/mof/math/basic_vector.hpp [deleted file]
include/mof/math/matrix.hpp [deleted file]
include/mof/math/matrix2.hpp [deleted file]
include/mof/math/matrix3.hpp [deleted file]
include/mof/math/vector.hpp [deleted file]
include/mof/math/vector2.hpp [deleted file]
include/mof/math/vector3.hpp [deleted file]
include/mof/util/foreach.hpp [deleted file]
include/mof/util/multimedia_timer.hpp [deleted file]
sample/CMakeLists.txt
sample/build_unix/CMakeFiles/CMakeDirectoryInformation.cmake
sample/build_unix/numeric/CMakeFiles/CMakeDirectoryInformation.cmake
sample/build_unix/numeric/CMakeFiles/numeric.dir/CXX.includecache
sample/build_unix/numeric/CMakeFiles/numeric.dir/depend.internal
sample/build_unix/numeric/CMakeFiles/numeric.dir/depend.make
sample/build_unix/numeric/CMakeFiles/numeric.dir/flags.make
sample/numeric/.main.cpp.swp [new file with mode: 0644]
sample/numeric/main.cpp
src/build_unix/Testing/Temporary/LastTest.log
src/build_unix/Testing/Temporary/LastTestsFailed.log
src/build_unix/mof/math/CMakeFiles/matrix2_test.dir/CXX.includecache
src/build_unix/mof/math/CMakeFiles/matrix2_test.dir/depend.internal
src/build_unix/mof/math/CMakeFiles/matrix2_test.dir/depend.make
src/build_unix/mof/math/CMakeFiles/matrix3_test.dir/CXX.includecache
src/build_unix/mof/math/CMakeFiles/matrix3_test.dir/depend.internal
src/build_unix/mof/math/CMakeFiles/matrix3_test.dir/depend.make
src/build_unix/mof/math/CMakeFiles/vector2_test.dir/CXX.includecache
src/build_unix/mof/math/CMakeFiles/vector2_test.dir/depend.internal
src/build_unix/mof/math/CMakeFiles/vector2_test.dir/depend.make
src/build_unix/mof/math/CMakeFiles/vector3_test.dir/CXX.includecache
src/build_unix/mof/math/CMakeFiles/vector3_test.dir/depend.internal
src/build_unix/mof/math/CMakeFiles/vector3_test.dir/depend.make
src/mof/math/basic_matrix.hpp
src/mof/math/basic_vector.hpp
src/mof/math/matrix2.hpp
src/mof/math/matrix3.hpp
src/mof/math/test/matrix2_test.cpp
src/mof/math/test/matrix3_test.cpp
src/mof/math/test/testbin/matrix2_test
src/mof/math/test/testbin/matrix3_test
src/mof/math/test/testbin/vector2_test
src/mof/math/test/testbin/vector3_test
src/mof/math/threshold.hpp [new file with mode: 0644]
src/mof/math/vector2.hpp
src/mof/math/vector3.hpp

index 30a310b..11c5964 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,6 +1,3 @@
-matrix multipla test
-matrix devide test
-debug print test
 make_rotation make_scaling ***
 test for above
 sample for matrix
index e96bc09..32925b0 100755 (executable)
Binary files a/bin/numeric and b/bin/numeric differ
diff --git a/include/mof/base/mofdef.hpp b/include/mof/base/mofdef.hpp
deleted file mode 100644 (file)
index c6cc2ee..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-#include <cstddef>
-#include <mof/base/tstring.hpp>
-
-
-namespace mof
-{
-
-}// namespace mof
diff --git a/include/mof/base/tstring.hpp b/include/mof/base/tstring.hpp
deleted file mode 100644 (file)
index 8e4fdba..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-#include <string>
-#ifndef _MSC_VER
-/* Microsoft VisualC++\82Å\92è\8b`\82³\82ê\82Ä\82¢\82éTCHAR\8c^\82ð\92è\8b` */
-typedef char TCHAR;
-#else
-#include <tchar.h>
-#endif
-
-namespace mof
-{
-       typedef std::basic_string<TCHAR> tstring;
-}// namespace mof
diff --git a/include/mof/math/basic_matrix.hpp b/include/mof/math/basic_matrix.hpp
deleted file mode 100644 (file)
index e378261..0000000
+++ /dev/null
@@ -1,247 +0,0 @@
-#pragma once
-#include <mof/base/mofdef.hpp>
-#include <boost/operators.hpp>
-#include <ostream>
-
-namespace mof
-{
-namespace math
-{
-
-       template <size_t Dim> struct row_of_matrix;
-       
-       /**
-        * @brief 同次座標変換行列テンプレートクラス
-        * @note  このテンプレートから直接特殊化することは想定していない.
-        * あくまでmatrixxを実装するための補助テンプレートである.
-        * このクラスは不変クラスである.
-        * @tparam Dim        行列の次元(要素数はこの数値の2乗)
-        * @tparam Derived    特殊化されたテンプレートの派生クラス(matrixx)の型
-        * @tparam Coordinate 対応するベクトルクラス(vectorx)の型
-        */
-       template <size_t Dim, typename Derived, typename Coordinate>
-       class basic_matrix
-               : boost::addable< Derived 
-               , boost::addable2< Derived, float
-               , boost::subtractable< Derived 
-               , boost::subtractable2< Derived, float
-               , boost::multipliable< Derived
-               , boost::multipliable2< Derived, float
-               , boost::equality_comparable< Derived
-               > > > > > > >
-       {
-       protected:
-//{{{ last_index
-               /**
-                * @brief elements_の最後の添字を得る
-                */
-               size_t last_index() const
-               {
-                       return (Dim + 1) * (Dim + 1);
-               }
-//}}}
-               float elements_[(Dim + 1) * (Dim + 1)];///< 要素の配列
-       public:
-//{{{ array
-/*
-               struct array
-               {
-                       float arr_[(Dim + 1) * (Dim + 1) - 1];
-
-                       float& operator[](size_t index)
-                       {
-                               return arr_[index];
-                       }
-
-               };
-*/
-//}}}
-               // コンストラクタ,デストラクタはデフォルトのものを使う
-               // 代入演算子,コピーコンストラクタはデフォルトのものを使う
-//{{{ operator +=
-               Derived& operator+=(const Derived& rhs)
-               {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               elements_[i] += rhs.elements_[i];
-                       }
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               Derived& operator+=(float rhs)
-               {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               elements_[i] += rhs;
-                       }
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               friend Derived operator+(float rhs1, Derived& rhs2) 
-               {
-                       Derived retval;
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               retval.elements_[i] = rhs1 + rhs2.elements_[i];
-                       }
-                       return retval;
-               }
-//}}}
-//{{{ operator -=
-               Derived& operator-=(const Derived& rhs)
-               {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               elements_[i] -= rhs.elements_[i];
-                       }
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               Derived& operator-=(float rhs)
-               {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               elements_[i] -= rhs;
-                       }
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               friend Derived operator-(float rhs1, Derived& rhs2) 
-               {
-                       Derived retval;
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               retval.elements_[i] = rhs1 - rhs2.elements_[i];
-                       }
-                       return retval;
-               }
-//}}}
-//{{{ operator *=      
-               Derived& operator*=(const Derived& rhs)
-               {
-                       Derived retval;
-                       for (size_t a = 0; a < last_index(); ++a) {
-                               int b = a / Dim * Dim;
-                               int c = a % Dim;
-                               float sum = 0;
-                               for (size_t i = 0; i < Dim; ++i) {
-                                       sum += elements_[b + i] * rhs.elements_[c + i * Dim];
-                               }
-                               retval.elements_[a] = sum;
-                       }
-                       *this = retval;
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-
-               Derived& operator*=(float rhs)
-               {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               elements_[i] *= rhs;
-                       }
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-       
-               Coordinate& operator*(const Coordinate& rhs)
-               {
-                       Coordinate retval;
-                       for (size_t a = 0; a < Dim; ++a) {
-                               int b = a / Dim * Dim;
-                               int c = a % Dim;
-                               float sum = 0;
-                               for (size_t i = 0; i < Dim; ++i) {
-                                       sum += elements_[b + i] * rhs[c + i];
-                               }
-                               retval.components_[a] = sum;
-                       }
-                       return retval;
-               }
-
-               friend Derived operator*(float rhs1, Derived& rhs2) 
-               {
-                       Derived retval;
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               retval.elements_[i] = rhs1 * rhs2.elements_[i];
-                       }
-                       return retval;
-               }
-//}}}
-//{{{ operator /=
-               Derived& operator/=(float rhs)
-               {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               elements_[i] /= rhs;
-                       }
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-//}}}
-//{{{ operator ==
-               bool operator==(const Derived& rhs) const
-               {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               if (elements_[i] != rhs.elements_[i]) return false;
-                       }
-                       return true;
-               }
-//}}}
-//{{{ operator []
-               /**
-                * @note 補助クラスによってM[i][j]のように参照可能
-                * @note この方法による複数の要素への参照は非効率
-                */
-               row_of_matrix<Dim> operator [](size_t i) const
-               {
-                       return row_of_matrix<Dim>(elements_, i);
-               }
-//}}}
-//{{{ operator <<
-               /**
-                * @brief デバッグ出力用ストリーム演算子
-                * @param [in] stream 出力ストリーム
-                * @param [in] rhs    出力対象となる行列オブジェクト
-                * @return 引数で与えられた出力ストリーム
-                */
-               friend std::ostream& operator<<
-               (
-                       std::ostream& stream,
-                       const Derived& rhs
-               )
-               {
-                       for (size_t i = 0; i < Dim + 1; ++i) {
-                               for (size_t j = 0; j < Dim + 1; ++j) {
-                                       if (j != 0) stream << ", ";
-                                       else if (j != Dim) stream << "\n";
-                                       stream << rhs.elements_[i * (Dim + 1) + j];
-                               }
-                       }
-                       return stream;
-               }
-//}}}
-       };
-//{{{ row_of_matrix
-       /**
-        * @brief M[i][j]のように行列の要素を参照できるようにするための補助クラス
-        */
-       template <size_t Dim>
-       struct row_of_matrix
-       {
-               const float* elements_;
-               size_t row_index_;
-
-               row_of_matrix(const float* elements, size_t row_index) 
-                       : elements_(elements), row_index_(row_index)
-               {
-               }
-               
-               float operator [](size_t index)
-               {
-                       return elements_[row_index_ * (Dim + 1) + index];
-               }
-       };
-//}}}
-
-}// namespace math
-}// namespace mof
diff --git a/include/mof/math/basic_vector.hpp b/include/mof/math/basic_vector.hpp
deleted file mode 100644 (file)
index b2e3bac..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-#pragma once
-#include <mof/base/mofdef.hpp>
-#include <boost/operators.hpp>
-#include <ostream>
-
-namespace mof
-{
-namespace math
-{
-       /**
-        * @brief 同次列ベクトルテンプレートクラス
-        * @note  このテンプレートから直接特殊化することは想定していない.
-        * あくまでvectorxを実装するための補助テンプレートである.
-        * このクラスは不変クラスである.
-        * @tparam Dim     ベクトルの次元(要素数)
-        * @tparam Derived 特殊化されたテンプレートの派生クラス(vectorx)の型
-        */
-       template <size_t Dim, typename Derived>
-       class basic_vector 
-               : boost::addable< Derived 
-               , boost::addable2< Derived, float
-               , boost::subtractable< Derived 
-               , boost::subtractable2< Derived, float
-               , boost::multipliable2< Derived, float
-               , boost::dividable2< Derived, float
-               , boost::equality_comparable< Derived
-               > > > > > > > 
-       {
-       protected:
-               float components_[Dim];///< 要素の配列
-       public:
-//{{{ array
-               struct array
-               {
-                       float arr_[Dim];
-
-                       float& operator[](size_t index)
-                       {
-                               return arr_[index];
-                       }
-
-               };
-//}}}
-               // コンストラクタ,デストラクタはデフォルトのものを使う
-               // 代入演算子,コピーコンストラクタはデフォルトのものを使う
-//{{{ operator +=
-               Derived& operator+=(const Derived& rhs)
-               {
-                       for (size_t i = 0; i < Dim; ++i) components_[i] += rhs.components_[i];
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               Derived& operator+=(float rhs)
-               {
-                       for (size_t i = 0; i < Dim; ++i) components_[i] += rhs;
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               friend Derived operator+(float rhs1, Derived& rhs2) 
-               {
-                       Derived retval;
-                       for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 + rhs2.components_[i];
-                       return retval;
-               }
-//}}}
-//{{{ operator -=
-               Derived& operator-=(const Derived& rhs)
-               {
-                       for (size_t i = 0; i < Dim; ++i) components_[i] -= rhs.components_[i];
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               Derived& operator-=(float rhs)
-               {
-                       for (size_t i = 0; i < Dim; ++i) components_[i] -= rhs;
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-
-               friend Derived operator-(float rhs1, Derived& rhs2) 
-               {
-                       Derived retval;
-                       for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 - rhs2.components_[i];
-                       return retval;
-               }
-//}}}
-//{{{ operator *=
-               Derived& operator*=(float rhs)
-               {
-                       for (size_t i = 0; i < Dim; ++i) components_[i] *= rhs;
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-               friend Derived operator*(float rhs1, Derived& rhs2) 
-               {
-                       Derived retval;
-                       for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 * rhs2.components_[i];
-                       return retval;
-               }
-//}}}
-//{{{ operator /=
-               Derived& operator/=(float rhs)
-               {
-                       for (size_t i = 0; i < Dim; ++i) components_[i] /= rhs;
-                       return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
-               }
-               
-//}}}
-//{{{ operator ==
-               bool operator==(const Derived& rhs) const
-               {
-                       for (size_t i = 0; i < Dim; ++i) {
-                               if (components_[i] != rhs.components_[i]) return false;
-                       }
-                       return true;
-               }
-//}}}
-//{{{ operator []
-               /**
-                * @note Dim+1番目の要素は常に1
-                * @param[in] index 添字
-                */
-               float operator[](size_t index) const
-               {
-                       if (index < Dim) return components_[index];
-                       else if (index == Dim) return 1;
-                       // TODO exception
-                       return 0;
-               }
-//}}}
-//{{{ operator <<
-               /**
-                * @brief デバッグ出力用ストリーム演算子
-                * @param[in] stream 出力ストリーム
-                * @param[in] rhs    出力対象となるベクトルオブジェクト
-                * @return 引数で与えられた出力ストリーム
-                */
-               friend std::ostream& operator<<
-               (
-                       std::ostream& stream,
-                       const Derived& rhs
-               )
-               {
-                       for (size_t i = 0; i < Dim; ++i)
-                       {
-                               if (i != 0) stream << ", ";
-                               stream << rhs.components_[i];
-                       }
-                       return stream;
-               }
-//}}}
-       };
-
-
-}// namespace math
-}// namespace mof
diff --git a/include/mof/math/matrix.hpp b/include/mof/math/matrix.hpp
deleted file mode 100644 (file)
index 2fcce2a..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * @file 各次元の行列をまとめてインクルードするためのヘッダ
- */
-#pragma once
-#include <mof/math/matrix2.hpp>
-#include <mof/math/matrix3.hpp>
diff --git a/include/mof/math/matrix2.hpp b/include/mof/math/matrix2.hpp
deleted file mode 100644 (file)
index c05bbb1..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#pragma once
-#include <mof/math/basic_matrix.hpp>
-
-namespace mof
-{
-namespace math
-{
-       class vector2;
-
-       /**
-        * @brief 2次元同次座標変換行列クラス
-        */
-       class matrix2 : public basic_matrix<2, matrix2, vector2>
-       {
-       public:
-//{{{ constructor
-               /**
-                * @brief デフォルトコンストラクタ.最後の要素以外を0で初期化する.
-                */
-               matrix2()
-               {
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
-                               elements_[i] = 0;
-                       }
-                       elements_[last_index() - 1] = 1;
-               }
-
-               /**
-                * @brief 指定した値で初期化する.
-                * @param[in] arr 初期化用配列
-                */
-/*
-               matrix2(const matrix2::array& arr)
-               {
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
-                               elements_[i] = arr[i];
-                       }
-                       elements_[last_index() - 1] = 1;
-               }
-*/
-               
-               /**
-                * @brief 指定した値で初期化する.
-                */
-               matrix2
-               (
-                       float m11, float m12, float m13,
-                       float m21, float m22, float m23,
-                       float m31, float m32
-               )
-               {
-                       const float* table[] =
-                               {
-                                       &m11, &m12, &m13,
-                                       &m21, &m22, &m23,
-                                       &m31, &m32
-                               };
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
-                               elements_[i] = *table[i];
-                       }
-                       elements_[last_index() - 1] = 1;
-               }
-
-//}}}
-//{{{ copy constructor
-       matrix2(const matrix2& rhs)
-       {
-               for (size_t i = 0; i < last_index(); ++i) {
-                       elements_[i] = rhs.elements_[i];
-               }
-       }
-//}}}
-//{{{ operator =
-       matrix2& operator = (const matrix2& rhs)
-       {
-               for (size_t i = 0; i < last_index(); ++i) {
-                       elements_[i] = rhs.elements_[i];
-               }
-               return *this;
-       }
-//}}}
-       };
-
-}// namespace math
-}// namespace mof
diff --git a/include/mof/math/matrix3.hpp b/include/mof/math/matrix3.hpp
deleted file mode 100644 (file)
index 3be9730..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-#pragma once
-#include <mof/math/basic_matrix.hpp>
-
-namespace mof
-{
-namespace math
-{
-       class vector3;
-
-       /**
-        * @brief 3次元同次座標変換行列クラス
-        */
-       class matrix3 : public basic_matrix<3, matrix3, vector3>
-       {
-       public:
-//{{{ constructor
-               /**
-                * @brief デフォルトコンストラクタ.最後の要素以外を0で初期化する.
-                */
-               matrix3()
-               {
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
-                               elements_[i] = 0;
-                       }
-                       elements_[last_index() - 1] = 1;
-               }
-
-               /**
-                * @brief 指定した値で初期化する.
-                * @param[in] arr 初期化用配列
-                */
-/*
-               matrix3(const matrix3::array& arr)
-               {
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
-                               elements_[i] = arr[i];
-                       }
-                       elements_[last_index() - 1] = 1;
-               }
-*/
-               
-               /**
-                * @brief 指定した値で初期化する.
-                */
-               matrix3
-               (
-                       float m11, float m12, float m13, float m14,
-                       float m21, float m22, float m23, float m24,
-                       float m31, float m32, float m33, float m34,
-                       float m41, float m42, float m43
-               )
-               {
-                       const float* table[] =
-                               {
-                                       &m11, &m12, &m13, &m14,
-                                       &m21, &m22, &m23, &m24,
-                                       &m31, &m32, &m33, &m34,
-                                       &m41, &m42, &m43
-                               };
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
-                               elements_[i] = *table[i];
-                       }
-                       elements_[last_index() - 1] = 1;
-               }
-
-//}}}
-//{{{ copy constructor
-       matrix3(const matrix3& rhs)
-       {
-               for (size_t i = 0; i < last_index(); ++i) {
-                       elements_[i] = rhs.elements_[i];
-               }
-       }
-//}}}
-//{{{ operator =
-       /**
-        * @note コピーのパフォーマンスのためにこの関数の定義は重要
-        */
-       matrix3& operator = (const matrix3& rhs)
-       {
-               for (size_t i = 0; i < last_index(); ++i) {
-                       elements_[i] = rhs.elements_[i];
-               }
-               return *this;
-       }
-//}}}
-       };
-
-}// namespace math
-}// namespace mof
diff --git a/include/mof/math/vector.hpp b/include/mof/math/vector.hpp
deleted file mode 100644 (file)
index af4e2dd..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * @file 各次元のベクトルをまとめてインクルードするためのヘッダ
- */
-#pragma once
-#include <mof/math/vector2.hpp>
-#include <mof/math/vector3.hpp>
diff --git a/include/mof/math/vector2.hpp b/include/mof/math/vector2.hpp
deleted file mode 100644 (file)
index 3d25998..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#pragma once
-#include <mof/math/basic_vector.hpp>
-
-namespace mof
-{
-namespace math
-{
-       /**
-        * @brief 2次元同次列ベクトルクラス
-        */
-       class vector2 : public basic_vector<2, vector2>
-       {
-       public:
-//{{{ constructor
-               /**
-                * @brief デフォルトコンストラクタ.全ての要素を0で初期化する.
-                */
-               vector2()
-               {
-                       components_[0] = 0;
-                       components_[1] = 0;
-               }
-
-               /**
-                * @brief 指定した値で初期化する.
-                * @param[in] x x座標成分
-                * @param[in] y y座標成分
-                */
-               vector2(float x, float y)
-               {
-                       components_[0] = x;
-                       components_[1] = y;
-               }
-               
-               /**
-                * @brief 指定した値で初期化する.
-                * @param[in] arr 初期化用配列
-                */
-/*
-               vector2(const vector2::array& arr)
-               {
-                       components_[0] = arr[0];
-                       components_[1] = arr[1];
-               }
-*/
-//}}}
-//{{{ accessers
-               float x() const { return components_[0]; }
-               float y() const { return components_[1]; }
-               float z() const { return 1; }// 第3要素は常に1
-//}}}
-       };
-
-}// namespace math
-}// namespace mof
diff --git a/include/mof/math/vector3.hpp b/include/mof/math/vector3.hpp
deleted file mode 100644 (file)
index aaa6a44..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#pragma once
-#include <mof/math/basic_vector.hpp>
-#include <mof/math/vector2.hpp>
-
-namespace mof
-{
-namespace math
-{
-       /**
-        * @brief 3次元同次列ベクトルクラス
-        */
-       class vector3 : public basic_vector<3, vector3>
-       {
-       public:
-//{{{ constructor
-               /**
-                * @brief デフォルトコンストラクタ.全ての要素を0で初期化する.
-                */
-               vector3()
-               {
-                       components_[0] = 0;
-                       components_[1] = 0;
-                       components_[2] = 0;
-               }
-
-               /**
-                * @brief 指定した値で初期化する.
-                * @param[in] x x座標成分
-                * @param[in] y y座標成分
-                * @param[in] z z座標成分
-                */
-               vector3(float x, float y, float z)
-               {
-                       components_[0] = x;
-                       components_[1] = y; 
-                       components_[2] = z;
-               }
-
-               /**
-                * @brief 指定した値で初期化する.
-                * @param[in] arr 初期化用配列
-                */
-/*
-               vector3(const vector3::array& arr)
-               {
-                       components_[0] = arr[0];
-                       components_[1] = arr[1];
-                       components_[2] = arr[2];
-               }
-*/
-
-//}}}
-//{{{ accesser
-               float x() const { return components_[0]; }
-               float y() const { return components_[1]; }
-               float z() const { return components_[2]; }
-               float w() const { return 1; }// 第4要素は常に1
-//}}}
-       };
-
-}// namespace math
-}// namespace mof
diff --git a/include/mof/util/foreach.hpp b/include/mof/util/foreach.hpp
deleted file mode 100644 (file)
index d6ed9d4..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-#include <boost/foreach.hpp>
-#define foreach BOOST_FOREACH
diff --git a/include/mof/util/multimedia_timer.hpp b/include/mof/util/multimedia_timer.hpp
deleted file mode 100644 (file)
index efb0129..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#pragma once
-#include <memory>
-#include <boost/utility.hpp>
-
-namespace mof
-{
-namespace util
-{
-
-       /**
-        * @brief システムのタイマによる高精度な時間計測
-        * @note Linux版の実装ではclock_gettimeのCLOCK_REALTIMEが用いられている.
-        */
-    class multimedia_timer : boost::noncopyable
-    {
-        struct impl;
-        std::unique_ptr<impl> pimpl_;
-    public:
-//{{{ constructor
-               /**
-                * @brief デフォルトコンストラクタ.内部でreset()が呼ばれる.
-                */
-        multimedia_timer();
-//}}}
-//{{{ destructor
-        ~multimedia_timer();
-//}}}
-//{{{ reset
-               /**
-                * @brief 時間の計測を初期化する.
-                * @sa get_time_in_micro_sec
-                */
-        void reset();
-//}}}
-//{{{ get_time_in_micro_sec
-               /**
-                * @brief 最後にreset()を読んだ時点から現在までの経過時間をマイクロ秒単位で返す
-                * @note 経過時間が長時間だった場合、返却値はオーバーフローしている可能性がある.
-                * @retval 経過時間(マイクロ秒単位)
-                */
-        int get_time_in_micro_sec() const; 
-//}}}
-    };
-
-}// namespace util
-}// namespace mof
index 00142d1..5dc0bab 100644 (file)
@@ -7,7 +7,7 @@ project(sample)
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../bin/)
 
 # moflib
-include_directories("${PROJECT_SOURCE_DIR}/../include/")
+include_directories("${PROJECT_SOURCE_DIR}/../src")
 link_directories("${PROJECT_SOURCE_DIR}/../lib")
 
 # set compile flags
index 01b62bc..f61b233 100644 (file)
@@ -10,7 +10,7 @@ SET(CMAKE_FORCE_UNIX_PATHS 1)
 
 # The C and CXX include file search paths:
 SET(CMAKE_C_INCLUDE_PATH
-  "../../include"
+  "../../src"
   "../BOOST_INCLUDE_DIR"
   )
 SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})
index 01b62bc..f61b233 100644 (file)
@@ -10,7 +10,7 @@ SET(CMAKE_FORCE_UNIX_PATHS 1)
 
 # The C and CXX include file search paths:
 SET(CMAKE_C_INCLUDE_PATH
-  "../../include"
+  "../../src"
   "../BOOST_INCLUDE_DIR"
   )
 SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})
index 929f624..2265eae 100644 (file)
@@ -6,69 +6,77 @@
 
 #IncludeRegexTransform: 
 
-../../include/mof/base/mofdef.hpp
+../../src/mof/base/mofdef.hpp
 cstddef
 -
 mof/base/tstring.hpp
 -
 
-../../include/mof/base/tstring.hpp
+../../src/mof/base/tstring.hpp
 string
 -
 tchar.h
 -
 
-../../include/mof/math/basic_matrix.hpp
+../../src/mof/math/basic_matrix.hpp
 mof/base/mofdef.hpp
 -
+mof/math/threshold.hpp
+-
 boost/operators.hpp
 -
 ostream
 -
+iomanip
+-
+cmath
+-
 
-../../include/mof/math/basic_vector.hpp
+../../src/mof/math/basic_vector.hpp
 mof/base/mofdef.hpp
 -
+mof/math/threshold.hpp
+-
 boost/operators.hpp
 -
 ostream
 -
+cmath
+-
 
-../../include/mof/math/matrix.hpp
+../../src/mof/math/matrix.hpp
 mof/math/matrix2.hpp
 -
 mof/math/matrix3.hpp
 -
 
-../../include/mof/math/matrix2.hpp
+../../src/mof/math/matrix2.hpp
 mof/math/basic_matrix.hpp
 -
 
-../../include/mof/math/matrix3.hpp
+../../src/mof/math/matrix3.hpp
 mof/math/basic_matrix.hpp
 -
 
-../../include/mof/math/matrix_tmp.hpp
-mof/math/basic_matrix.hpp
--
+../../src/mof/math/threshold.hpp
 
-../../include/mof/math/vector.hpp
+../../src/mof/math/vector.hpp
 mof/math/vector2.hpp
 -
 mof/math/vector3.hpp
 -
 
-../../include/mof/math/vector2.hpp
+../../src/mof/math/vector2.hpp
 mof/math/basic_vector.hpp
 -
 
-../../include/mof/math/vector3.hpp
+../../src/mof/math/vector3.hpp
 mof/math/basic_vector.hpp
 -
 mof/math/vector2.hpp
 -
 
-../../include/mof/util/multimedia_timer.hpp
+../../src/mof/util/multimedia_timer.hpp
 memory
 -
 boost/utility.hpp
@@ -79,8 +87,6 @@ mof/math/vector.hpp
 -
 mof/math/matrix.hpp
 -
-mof/math/matrix_tmp.hpp
--
 mof/util/multimedia_timer.hpp
 -
 iostream
index 10fa0ef..967b056 100644 (file)
@@ -2,16 +2,16 @@
 # Generated by "Unix Makefiles" Generator, CMake Version 2.8
 
 numeric/CMakeFiles/numeric.dir/main.cpp.o
- ../../include/mof/base/mofdef.hpp
- ../../include/mof/base/tstring.hpp
- ../../include/mof/math/basic_matrix.hpp
- ../../include/mof/math/basic_vector.hpp
- ../../include/mof/math/matrix.hpp
- ../../include/mof/math/matrix2.hpp
- ../../include/mof/math/matrix3.hpp
- ../../include/mof/math/matrix_tmp.hpp
- ../../include/mof/math/vector.hpp
- ../../include/mof/math/vector2.hpp
- ../../include/mof/math/vector3.hpp
- ../../include/mof/util/multimedia_timer.hpp
+ ../../src/mof/base/mofdef.hpp
+ ../../src/mof/base/tstring.hpp
+ ../../src/mof/math/basic_matrix.hpp
+ ../../src/mof/math/basic_vector.hpp
+ ../../src/mof/math/matrix.hpp
+ ../../src/mof/math/matrix2.hpp
+ ../../src/mof/math/matrix3.hpp
+ ../../src/mof/math/threshold.hpp
+ ../../src/mof/math/vector.hpp
+ ../../src/mof/math/vector2.hpp
+ ../../src/mof/math/vector3.hpp
+ ../../src/mof/util/multimedia_timer.hpp
  /home/yasutomo/devel/moflib/sample/numeric/main.cpp
index 1ef0a47..e0c212d 100644 (file)
@@ -1,17 +1,17 @@
 # CMAKE generated file: DO NOT EDIT!
 # Generated by "Unix Makefiles" Generator, CMake Version 2.8
 
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/base/mofdef.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/base/tstring.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/basic_matrix.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/basic_vector.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix2.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix3.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix_tmp.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/vector.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/vector2.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/vector3.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/util/multimedia_timer.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/base/mofdef.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/base/tstring.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/basic_matrix.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/basic_vector.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/matrix.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/matrix2.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/matrix3.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/threshold.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/vector.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/vector2.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/vector3.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/util/multimedia_timer.hpp
 numeric/CMakeFiles/numeric.dir/main.cpp.o: ../numeric/main.cpp
 
index 96fffea..bcadb6a 100644 (file)
@@ -2,7 +2,7 @@
 # Generated by "Unix Makefiles" Generator, CMake Version 2.8
 
 # compile CXX with /usr/bin/c++
-CXX_FLAGS =  -Wall -O3 -DNDEBUG -std=c++0x -I/home/yasutomo/devel/moflib/sample/../include -I/home/yasutomo/devel/moflib/sample/BOOST_INCLUDE_DIR  
+CXX_FLAGS =  -Wall -O3 -DNDEBUG -std=c++0x -I/home/yasutomo/devel/moflib/sample/../src -I/home/yasutomo/devel/moflib/sample/BOOST_INCLUDE_DIR  
 
 CXX_DEFINES = 
 
diff --git a/sample/numeric/.main.cpp.swp b/sample/numeric/.main.cpp.swp
new file mode 100644 (file)
index 0000000..0dd7eb5
Binary files /dev/null and b/sample/numeric/.main.cpp.swp differ
index aaa1378..ea528fb 100644 (file)
@@ -1,6 +1,5 @@
 #include <mof/math/vector.hpp>
 #include <mof/math/matrix.hpp>
-#include <mof/math/matrix_tmp.hpp>
 #include <mof/util/multimedia_timer.hpp>
 #include <iostream>
 #include <memory>
@@ -21,25 +20,22 @@ namespace
                }
        };
 //}}}
-//{{{ raw_type16
-       class raw_type16
+//{{{ raw_type
+       template <size_t Dim>
+       class raw_type
        {
-               float data[16];
-       };
-//}}}
-//{{{ raw_type3
-       class raw_type3
-       {
-               float data[3];
+               float data[Dim];
        };
 //}}}
        mof::math::vector2 unused1;// block compile optimation
-       mof::math::vector3 unused2;// block compile optimation
-       mof::math::matrix2 unused3;// block compile optimation
-       mof::math::matrix3 unused4;// block compile optimation
-       raw_type3 unused6;
-       raw_type16 unused7;
-       shared_type unused5;       // block compile optimation
+       raw_type<2>        unused2;// block compile optimation
+       mof::math::vector3 unused3;// block compile optimation
+       raw_type<3>        unused4;// block compile optimation
+       mof::math::matrix2 unused5;// block compile optimation
+       raw_type<9>        unused6;// block compile optimation
+       mof::math::matrix3 unused7;// block compile optimation
+       raw_type<16>       unused8;// block compile optimation
+       shared_type        unused9;// block compile optimation
 //{{{ copy_test
        template <typename T>
        int copy_test(T& unused) {
@@ -50,38 +46,111 @@ namespace
                return timer.get_time_in_micro_sec();
        }
 //}}}
+//{{{ add_test
+       template <typename T>
+       int add_test(T& unused) {
+               using namespace mof::util;
+               T x;
+               multimedia_timer timer;
+               for (int i = 0; i < REPEAT_COUNT; i++) unused = x + unused;
+               return timer.get_time_in_micro_sec();
+       }
+//}}}
+//{{{ multiply_test
+       template <typename Matrix, typename Vector>
+       int multiply_test(Vector& unused) {
+               using namespace mof::util;
+               Matrix M;
+               Vector v;
+               multimedia_timer timer;
+               for (int i = 0; i < REPEAT_COUNT; i++) unused = M * unused;
+               return timer.get_time_in_micro_sec();
+       }
+//}}}
 }
 
+void copy_tests();
+void add_tests();
+void multiply_tests();
+
+//{{{ main
 int main()
 {
+       std::cout << REPEAT_COUNT << " times repeating" << std::endl;
+       copy_tests();
+       add_tests();
+       multiply_tests();
+       return 0;
+}
+//}}}
+//{{{ copy_tests
+void copy_tests()
+{
        using namespace std;
        using namespace mof::math;
 
        cout << "***copy performance test***" << endl;
-       cout << REPEAT_COUNT << " times repeating" << endl;
        
        cout << "vector2 --- " ;
        cout << copy_test<vector2>(unused1) << "[micro sec]" << endl;
        
+       cout << "raw type2 --- " ;
+       cout << copy_test<raw_type<2>>(unused2) << "[micro sec]" << endl;
+
        cout << "vector3 --- " ;
-       cout << copy_test<vector3>(unused2) << "[micro sec]" << endl;
+       cout << copy_test<vector3>(unused3) << "[micro sec]" << endl;
        
+       cout << "raw type3 --- " ;
+       cout << copy_test<raw_type<3>>(unused4) << "[micro sec]" << endl;
+
        cout << "matrix2 --- " ;
-       cout << copy_test<matrix2>(unused3) << "[micro sec]" << endl;
+       cout << copy_test<matrix2>(unused5) << "[micro sec]" << endl;
+
+       cout << "raw type9 --- " ;
+       cout << copy_test<raw_type<9>>(unused6) << "[micro sec]" << endl;
 
        cout << "matrix3 --- " ;
-       cout << copy_test<matrix3>(unused4) << "[micro sec]" << endl;
+       cout << copy_test<matrix3>(unused7) << "[micro sec]" << endl;
 
-       cout << "raw type3 --- " ;
-       cout << copy_test<raw_type3>(unused6) << "[micro sec]" << endl;
-       
        cout << "raw type16 --- " ;
-       cout << copy_test<raw_type16>(unused7) << "[micro sec]" << endl;
-
+       cout << copy_test<raw_type<16>>(unused8) << "[micro sec]" << endl;
+       
        cout << "shared type --- " ;
-       cout << copy_test<shared_type>(unused5) << "[micro sec]" << endl;
+       cout << copy_test<shared_type>(unused9) << "[micro sec]" << endl;
+}
+//}}}
+//{{{ add_tests
+void add_tests()
+{
+       using namespace std;
+       using namespace mof::math;
+
+       cout << "***add performance test***" << endl;
+
+       cout << "vector2 + vector2 --- " ;
+       cout << add_test<vector2>(unused1) << "[micro sec]" << endl;
        
+       cout << "vector3 + vector3 --- " ;
+       cout << add_test<vector3>(unused3) << "[micro sec]" << endl;
 
+       cout << "matrix2 + matrix2 --- " ;
+       cout << add_test<matrix2>(unused5) << "[micro sec]" << endl;
 
-       return 0;
+       cout << "matrix3 + matrix3 --- " ;
+       cout << add_test<matrix3>(unused7) << "[micro sec]" << endl;
+}
+//}}}
+//{{{ multiply_tests
+void multiply_tests()
+{
+       using namespace std;
+       using namespace mof::math;
+
+       cout << "***multiply performance test***" << endl;
+
+       cout << "matrix2 * vector2 --- " ;
+       cout << multiply_test<matrix2, vector2>(unused1) << "[micro sec]" << endl;
+       cout << "matrix3 * vector3 --- " ;
+       cout << multiply_test<matrix3, vector3>(unused3) << "[micro sec]" << endl;
 }
+//}}}
index cb862a8..e03ff3f 100644 (file)
@@ -1,17 +1,17 @@
-Start testing: Aug 17 13:29 PDT
+Start testing: Aug 18 13:21 PDT
 ----------------------------------------------------------
 1/4 Testing: vector2_test
 1/4 Test: vector2_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/vector2_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"vector2_test" start time: Aug 17 13:29 PDT
+"vector2_test" start time: Aug 18 13:21 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
-Test time =   0.00 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"vector2_test" end time: Aug 17 13:29 PDT
+"vector2_test" end time: Aug 18 13:21 PDT
 "vector2_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -19,14 +19,14 @@ Test Passed.
 2/4 Test: vector3_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/vector3_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"vector3_test" start time: Aug 17 13:29 PDT
+"vector3_test" start time: Aug 18 13:21 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
-Test time =   0.00 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"vector3_test" end time: Aug 17 13:29 PDT
+"vector3_test" end time: Aug 18 13:21 PDT
 "vector3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -34,19 +34,14 @@ Test Passed.
 3/4 Test: matrix2_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/matrix2_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"matrix2_test" start time: Aug 17 13:29 PDT
+"matrix2_test" start time: Aug 18 13:21 PDT
 Output:
 ----------------------------------------------------------
-1
-
-1, 2, 3
-4, 5, 6
-7, 8, 1
 <end of output>
-Test time =   0.00 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"matrix2_test" end time: Aug 17 13:29 PDT
+"matrix2_test" end time: Aug 18 13:21 PDT
 "matrix2_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -54,20 +49,15 @@ Test Passed.
 4/4 Test: matrix3_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/matrix3_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"matrix3_test" start time: Aug 17 13:29 PDT
+"matrix3_test" start time: Aug 18 13:21 PDT
 Output:
 ----------------------------------------------------------
-
-1, 2, 3, 4
-5, 6, 7, 8
-9, 10, 11, 12
-13, 14, 15, 1
 <end of output>
-Test time =   0.00 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"matrix3_test" end time: Aug 17 13:29 PDT
+"matrix3_test" end time: Aug 18 13:21 PDT
 "matrix3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
-End testing: Aug 17 13:29 PDT
+End testing: Aug 18 13:21 PDT
index a19543f..725a89a 100644 (file)
@@ -21,18 +21,44 @@ tchar.h
 ../mof/math/basic_matrix.hpp
 mof/base/mofdef.hpp
 -
+mof/math/threshold.hpp
+-
+boost/operators.hpp
+-
+ostream
+-
+iomanip
+-
+cmath
+-
+
+../mof/math/basic_vector.hpp
+mof/base/mofdef.hpp
+-
+mof/math/threshold.hpp
+-
 boost/operators.hpp
 -
 ostream
 -
+cmath
+-
 
 ../mof/math/matrix2.hpp
 mof/math/basic_matrix.hpp
 -
 
+../mof/math/threshold.hpp
+
+../mof/math/vector2.hpp
+mof/math/basic_vector.hpp
+-
+
 /home/yasutomo/devel/moflib/src/mof/math/test/matrix2_test.cpp
 mof/math/matrix2.hpp
 -
+mof/math/vector2.hpp
+-
 iostream
 -
 sstream
index 3ec6236..be3a690 100644 (file)
@@ -5,5 +5,8 @@ mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o
  ../mof/base/mofdef.hpp
  ../mof/base/tstring.hpp
  ../mof/math/basic_matrix.hpp
+ ../mof/math/basic_vector.hpp
  ../mof/math/matrix2.hpp
+ ../mof/math/threshold.hpp
+ ../mof/math/vector2.hpp
  /home/yasutomo/devel/moflib/src/mof/math/test/matrix2_test.cpp
index bed728c..c5e1130 100644 (file)
@@ -4,6 +4,9 @@
 mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/base/mofdef.hpp
 mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/base/tstring.hpp
 mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/basic_matrix.hpp
+mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/basic_vector.hpp
 mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/matrix2.hpp
+mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/threshold.hpp
+mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/vector2.hpp
 mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/test/matrix2_test.cpp
 
index 6f9fa24..028fd18 100644 (file)
@@ -21,18 +21,50 @@ tchar.h
 ../mof/math/basic_matrix.hpp
 mof/base/mofdef.hpp
 -
+mof/math/threshold.hpp
+-
 boost/operators.hpp
 -
 ostream
 -
+iomanip
+-
+cmath
+-
+
+../mof/math/basic_vector.hpp
+mof/base/mofdef.hpp
+-
+mof/math/threshold.hpp
+-
+boost/operators.hpp
+-
+ostream
+-
+cmath
+-
 
 ../mof/math/matrix3.hpp
 mof/math/basic_matrix.hpp
 -
 
+../mof/math/threshold.hpp
+
+../mof/math/vector2.hpp
+mof/math/basic_vector.hpp
+-
+
+../mof/math/vector3.hpp
+mof/math/basic_vector.hpp
+-
+mof/math/vector2.hpp
+-
+
 /home/yasutomo/devel/moflib/src/mof/math/test/matrix3_test.cpp
 mof/math/matrix3.hpp
 -
+mof/math/vector3.hpp
+-
 iostream
 -
 sstream
index 8fb24ac..2f7124a 100644 (file)
@@ -5,5 +5,9 @@ mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o
  ../mof/base/mofdef.hpp
  ../mof/base/tstring.hpp
  ../mof/math/basic_matrix.hpp
+ ../mof/math/basic_vector.hpp
  ../mof/math/matrix3.hpp
+ ../mof/math/threshold.hpp
+ ../mof/math/vector2.hpp
+ ../mof/math/vector3.hpp
  /home/yasutomo/devel/moflib/src/mof/math/test/matrix3_test.cpp
index 262554f..0c980bc 100644 (file)
@@ -4,6 +4,10 @@
 mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/base/mofdef.hpp
 mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/base/tstring.hpp
 mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/basic_matrix.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/basic_vector.hpp
 mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/matrix3.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/threshold.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/vector2.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/vector3.hpp
 mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/test/matrix3_test.cpp
 
index c9c24df..e0f96a0 100644 (file)
@@ -21,10 +21,16 @@ tchar.h
 ../mof/math/basic_vector.hpp
 mof/base/mofdef.hpp
 -
+mof/math/threshold.hpp
+-
 boost/operators.hpp
 -
 ostream
 -
+cmath
+-
+
+../mof/math/threshold.hpp
 
 ../mof/math/vector2.hpp
 mof/math/basic_vector.hpp
index 2c5014a..a0f9f89 100644 (file)
@@ -5,5 +5,6 @@ mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o
  ../mof/base/mofdef.hpp
  ../mof/base/tstring.hpp
  ../mof/math/basic_vector.hpp
+ ../mof/math/threshold.hpp
  ../mof/math/vector2.hpp
  /home/yasutomo/devel/moflib/src/mof/math/test/vector2_test.cpp
index e61d75d..9b5f76f 100644 (file)
@@ -4,6 +4,7 @@
 mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/base/mofdef.hpp
 mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/base/tstring.hpp
 mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/basic_vector.hpp
+mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/threshold.hpp
 mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/vector2.hpp
 mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/test/vector2_test.cpp
 
index b26e252..b1fe7ee 100644 (file)
@@ -21,10 +21,16 @@ tchar.h
 ../mof/math/basic_vector.hpp
 mof/base/mofdef.hpp
 -
+mof/math/threshold.hpp
+-
 boost/operators.hpp
 -
 ostream
 -
+cmath
+-
+
+../mof/math/threshold.hpp
 
 ../mof/math/vector2.hpp
 mof/math/basic_vector.hpp
index 85aa35b..82239da 100644 (file)
@@ -5,6 +5,7 @@ mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o
  ../mof/base/mofdef.hpp
  ../mof/base/tstring.hpp
  ../mof/math/basic_vector.hpp
+ ../mof/math/threshold.hpp
  ../mof/math/vector2.hpp
  ../mof/math/vector3.hpp
  /home/yasutomo/devel/moflib/src/mof/math/test/vector3_test.cpp
index cb405b0..5ff7f43 100644 (file)
@@ -4,6 +4,7 @@
 mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/base/mofdef.hpp
 mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/base/tstring.hpp
 mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/basic_vector.hpp
+mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/threshold.hpp
 mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/vector2.hpp
 mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/vector3.hpp
 mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/test/vector3_test.cpp
index e378261..e735a88 100644 (file)
@@ -1,7 +1,10 @@
 #pragma once
 #include <mof/base/mofdef.hpp>
+#include <mof/math/threshold.hpp>
 #include <boost/operators.hpp>
 #include <ostream>
+#include <iomanip>
+#include <cmath>
 
 namespace mof
 {
@@ -27,8 +30,9 @@ namespace math
                , boost::subtractable2< Derived, float
                , boost::multipliable< Derived
                , boost::multipliable2< Derived, float
+               , boost::dividable2< Derived, float
                , boost::equality_comparable< Derived
-               > > > > > > >
+               > > > > > > > >
        {
        protected:
 //{{{ last_index
@@ -37,7 +41,7 @@ namespace math
                 */
                size_t last_index() const
                {
-                       return (Dim + 1) * (Dim + 1);
+                       return (Dim + 1) * (Dim + 1) - 1;
                }
 //}}}
                float elements_[(Dim + 1) * (Dim + 1)];///< 要素の配列
@@ -62,7 +66,7 @@ namespace math
                Derived& operator+=(const Derived& rhs)
                {
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                elements_[i] += rhs.elements_[i];
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -71,7 +75,7 @@ namespace math
                Derived& operator+=(float rhs)
                {
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                elements_[i] += rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -81,7 +85,7 @@ namespace math
                {
                        Derived retval;
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                retval.elements_[i] = rhs1 + rhs2.elements_[i];
                        }
                        return retval;
@@ -91,7 +95,7 @@ namespace math
                Derived& operator-=(const Derived& rhs)
                {
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                elements_[i] -= rhs.elements_[i];
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -100,7 +104,7 @@ namespace math
                Derived& operator-=(float rhs)
                {
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                elements_[i] -= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -110,24 +114,38 @@ namespace math
                {
                        Derived retval;
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                retval.elements_[i] = rhs1 - rhs2.elements_[i];
                        }
                        return retval;
                }
 //}}}
 //{{{ operator *=      
+               /**
+                * @brief 行列の積を計算し,最後の要素が1になるように定数倍する.
+                */
                Derived& operator*=(const Derived& rhs)
                {
                        Derived retval;
-                       for (size_t a = 0; a < last_index(); ++a) {
-                               int b = a / Dim * Dim;
-                               int c = a % Dim;
+                       const int SIZE = Dim + 1;
+                       
+                       // calculate the last element previously
+                       int b = last_index() - Dim;
+                       int c = Dim;
+                       float last_sum = 0;
+                       for (int i = 0; i < SIZE; ++i) {
+                               last_sum += elements_[b + i] * rhs.elements_[c + i * SIZE];
+                       }
+                       retval.elements_[last_index()] = 1;
+
+                       for (int a = last_index() - 1; a >= 0; --a) {
+                               int b = a / SIZE * SIZE;
+                               int c = a % SIZE;
                                float sum = 0;
-                               for (size_t i = 0; i < Dim; ++i) {
-                                       sum += elements_[b + i] * rhs.elements_[c + i * Dim];
+                               for (int i = 0; i < SIZE; ++i) {
+                                       sum += elements_[b + i] * rhs.elements_[c + i * SIZE];
                                }
-                               retval.elements_[a] = sum;
+                               retval.elements_[a] = sum / last_sum;
                        }
                        *this = retval;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -136,32 +154,41 @@ namespace math
                Derived& operator*=(float rhs)
                {
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                elements_[i] *= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
        
-               Coordinate& operator*(const Coordinate& rhs)
+               /**
+                * @brief ベクトルを変換し,最後の要素が1になるように定数倍する.
+                */
+               Coordinate operator*(const Coordinate& rhs)
                {
-                       Coordinate retval;
+                       typename Coordinate::array arr;
+                       const size_t SIZE = Dim + 1;
+
+                       float last_sum = 0;
+                       for (size_t i = 0; i < SIZE; ++i) {
+                               last_sum += elements_[Dim * SIZE + i] * rhs[i];
+                       }
+
                        for (size_t a = 0; a < Dim; ++a) {
-                               int b = a / Dim * Dim;
-                               int c = a % Dim;
                                float sum = 0;
-                               for (size_t i = 0; i < Dim; ++i) {
-                                       sum += elements_[b + i] * rhs[c + i];
+                               for (size_t i = 0; i < SIZE; ++i) {
+                                       sum += elements_[a * SIZE + i] * rhs[i];
                                }
-                               retval.components_[a] = sum;
+                               arr[a] = sum / last_sum;
                        }
-                       return retval;
+                       return Coordinate(arr);
                }
 
+
                friend Derived operator*(float rhs1, Derived& rhs2) 
                {
                        Derived retval;
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       const size_t END = rhs2.last_index() - 1;// 最後の要素は1で保存
+                       for (size_t i = 0; i <= END; ++i) {
                                retval.elements_[i] = rhs1 * rhs2.elements_[i];
                        }
                        return retval;
@@ -171,7 +198,7 @@ namespace math
                Derived& operator/=(float rhs)
                {
                        const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
+                       for (size_t i = 0; i <= END; ++i) {
                                elements_[i] /= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -180,9 +207,9 @@ namespace math
 //{{{ operator ==
                bool operator==(const Derived& rhs) const
                {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i < END; ++i) {
-                               if (elements_[i] != rhs.elements_[i]) return false;
+                       const size_t END = last_index() - 1;// 最後の要素は1で保存されている
+                       for (size_t i = 0; i <= END; ++i) {
+                               if (std::abs(elements_[i] - rhs.elements_[i]) > MOF_ERROR_THRESHOLD) return false;
                        }
                        return true;
                }
@@ -214,7 +241,7 @@ namespace math
                                for (size_t j = 0; j < Dim + 1; ++j) {
                                        if (j != 0) stream << ", ";
                                        else if (j != Dim) stream << "\n";
-                                       stream << rhs.elements_[i * (Dim + 1) + j];
+                                       stream << std::setw(5) << rhs.elements_[i * (Dim + 1) + j];
                                }
                        }
                        return stream;
index b2e3bac..06cb7a7 100644 (file)
@@ -1,7 +1,10 @@
 #pragma once
 #include <mof/base/mofdef.hpp>
+#include <mof/math/threshold.hpp>
 #include <boost/operators.hpp>
 #include <ostream>
+#include <cmath>
+
 
 namespace mof
 {
@@ -33,12 +36,8 @@ namespace math
                struct array
                {
                        float arr_[Dim];
-
-                       float& operator[](size_t index)
-                       {
-                               return arr_[index];
-                       }
-
+                       float& operator[](size_t index){return arr_[index];}
+                       const float& operator[](size_t index) const {return arr_[index];}
                };
 //}}}
                // コンストラクタ,デストラクタはデフォルトのものを使う
@@ -109,7 +108,7 @@ namespace math
                bool operator==(const Derived& rhs) const
                {
                        for (size_t i = 0; i < Dim; ++i) {
-                               if (components_[i] != rhs.components_[i]) return false;
+                               if (std::abs(components_[i] - rhs.components_[i]) > MOF_ERROR_THRESHOLD) return false;
                        }
                        return true;
                }
index c05bbb1..9e2cf4d 100644 (file)
@@ -19,10 +19,10 @@ namespace math
                 */
                matrix2()
                {
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
+                       for (size_t i = 0; i <= last_index() - 1; ++i) {
                                elements_[i] = 0;
                        }
-                       elements_[last_index() - 1] = 1;
+                       elements_[last_index()] = 1;
                }
 
                /**
@@ -55,17 +55,17 @@ namespace math
                                        &m21, &m22, &m23,
                                        &m31, &m32
                                };
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
+                       for (size_t i = 0; i <= last_index() - 1; ++i) {
                                elements_[i] = *table[i];
                        }
-                       elements_[last_index() - 1] = 1;
+                       elements_[last_index()] = 1;
                }
 
 //}}}
 //{{{ copy constructor
        matrix2(const matrix2& rhs)
        {
-               for (size_t i = 0; i < last_index(); ++i) {
+               for (size_t i = 0; i <= last_index(); ++i) {
                        elements_[i] = rhs.elements_[i];
                }
        }
@@ -73,7 +73,7 @@ namespace math
 //{{{ operator =
        matrix2& operator = (const matrix2& rhs)
        {
-               for (size_t i = 0; i < last_index(); ++i) {
+               for (size_t i = 0; i <= last_index(); ++i) {
                        elements_[i] = rhs.elements_[i];
                }
                return *this;
index 3be9730..555ffad 100644 (file)
@@ -19,10 +19,10 @@ namespace math
                 */
                matrix3()
                {
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
+                       for (size_t i = 0; i <= last_index() - 1; ++i) {
                                elements_[i] = 0;
                        }
-                       elements_[last_index() - 1] = 1;
+                       elements_[last_index()] = 1;
                }
 
                /**
@@ -57,10 +57,10 @@ namespace math
                                        &m31, &m32, &m33, &m34,
                                        &m41, &m42, &m43
                                };
-                       for (size_t i = 0; i < last_index() - 1; ++i) {
+                       for (size_t i = 0; i <= last_index() - 1; ++i) {
                                elements_[i] = *table[i];
                        }
-                       elements_[last_index() - 1] = 1;
+                       elements_[last_index()] = 1;
                }
 
 //}}}
index fc36b77..e19e489 100644 (file)
@@ -1,4 +1,5 @@
 #include <mof/math/matrix2.hpp>
+#include <mof/math/vector2.hpp>
 #include <iostream>
 #include <sstream>
 
@@ -14,7 +15,6 @@ int main()
                for (size_t i = 0; i < 8; ++i) {
                        if (M[i / 3][i % 3] != 0) failed = true;
                }
-               std::cout << M[2][2] << std::endl;
                if (failed || M[2][2] != 1) {
                        cerr << "Failed:" << " default constructor makes zero matrix" << endl;  
                        failed_count++;
@@ -23,7 +23,6 @@ int main()
 
        {
                matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
-               std::cout << M << std::endl;
                bool failed = false;
                for (size_t i = 0; i < 8; ++i) {
                        if (M[i / 3][i % 3] != i + 1) failed = true;
@@ -39,7 +38,7 @@ int main()
                matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
                matrix2 N(1, 2, 3, 4, 5, 6, 7, 8);
                if (M != N) {
-                       cerr << "Failed:" << " comparation test" << endl;       
+                       cerr << "Failed:" << " M == N test" << endl;    
                        failed_count++;
                }
        }
@@ -48,7 +47,7 @@ int main()
                matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
                matrix2 N(0, 2, 3, 4, 5, 6, 7, 8);
                if (M == N) {
-                       cerr << "Failed:" << " comparation test" << endl;       
+                       cerr << "Failed:" << " M != N test" << endl;    
                        failed_count++;
                }
        }
@@ -75,16 +74,60 @@ int main()
                }
        }
 
-       /*
-       v = vector2(10, 10);
-       v = 2 * v * 3;
-       if (v.x() != 60 || v.y() != 60 || v.z() != 1) {
-               cerr << "Failed:"  << " multiplation with scalar test" << endl; 
-               failed_count++;
+       {
+               matrix2 N1(1, 2, 3, 4, 5, 6, 0, 0);
+               matrix2 N2(2, 3, 4, 5, 6, 7, 0, 0);
+               matrix2 N = N1 * N2;
+               matrix2 A(12, 15, 21, 33, 42, 57, 0, 0);
+               if (N != A) {
+                       cerr << "Failed:" << "Affine matrix N1 * N2 test" << endl;      
+                       failed_count++;
+               }
+       }
+       
+       {
+               matrix2 N1(1, 2, 3, 4, 5, 6, 7, 8);
+               matrix2 N2(2, 3, 4, 5, 6, 7, 8, 9);
+               matrix2 N = N1 * N2;
+               matrix2 A(0.42353f, 0.49412f, 0.24706f, 0.95294f, 1.12941f, 0.67059f, 0.72941f, 0.91765f);
+               if (N != A) {
+                       cerr << "Failed:" << "Projective matrix N1 * N2 test" << endl;  
+                       failed_count++;
+               }
        }
-       */
-       // TODO matrix devide
        
+       {
+               matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
+               vector2 v(1, 2);
+               vector2 w = M * v;
+               vector2 a(0.33333f, 0.83333f);
+               if (a != w) {
+                       cerr << "Failed:" << "M * v test" << endl;      
+                       failed_count++;
+               }
+       }
+
+
+       {
+               matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
+               matrix2 N = 2 * M * 3;
+               matrix2 A(6, 12, 18, 24, 30, 36, 42, 48);
+               if (N != A) {
+                       cerr << "Failed:" << "s * M * s test" << endl;  
+                       failed_count++;
+               }
+       }
+       
+       {
+               matrix2 M(3, 6, 9, 12, 15, 18, 21, 24);
+               matrix2 N = M / 3;
+               matrix2 A(1, 2, 3, 4, 5, 6, 7, 8);
+               if (N != A) {
+                       cerr << "Failed:" << "M / s test" << endl;      
+                       failed_count++;
+               }
+       }
+
 
        return failed_count;
 }
index 668e865..2ab4b26 100644 (file)
@@ -1,4 +1,5 @@
 #include <mof/math/matrix3.hpp>
+#include <mof/math/vector3.hpp>
 #include <iostream>
 #include <sstream>
 
@@ -26,7 +27,6 @@ int main()
                for (size_t i = 0; i < 15; ++i) {
                        if (M[i / 4][i % 4] != i + 1) failed = true;
                }
-               cout << M << endl;
                if (failed || M[3][3] != 1) {
                        cerr << "Failed:" << " initialize test" << endl;        
                        failed_count++;
@@ -38,7 +38,7 @@ int main()
                matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
                matrix3 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
                if (M != N) {
-                       cerr << "Failed:" << " comparation test" << endl;       
+                       cerr << "Failed:" << " M == N test" << endl;    
                        failed_count++;
                }
        }
@@ -47,7 +47,7 @@ int main()
                matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
                matrix3 N(0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
                if (M == N) {
-                       cerr << "Failed:" << " comparation test" << endl;       
+                       cerr << "Failed:" << " M != N test" << endl;    
                        failed_count++;
                }
        }
@@ -80,16 +80,65 @@ int main()
                }
        }
 
-       /*
-       v = vector2(10, 10);
-       v = 2 * v * 3;
-       if (v.x() != 60 || v.y() != 60 || v.z() != 1) {
-               cerr << "Failed:"  << " multiplation with scalar test" << endl; 
-               failed_count++;
+       {
+               matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0);
+               matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0);
+               matrix3 N = N1 * N2;
+               matrix3 A(44, 50, 56, 66, 116, 134, 152, 178, 188, 218, 248, 290, 0, 0, 0);
+               if (N != A) {
+                       cerr << "Failed:" << "Affine matrix N1 * N2 test" << endl;      
+                       failed_count++;
+               }
        }
-       */
-       // TODO matrix devide
        
+       {
+               matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+               matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
+               matrix3 N = N1 * N2;
+               matrix3 A
+               (
+                       0.25840f, 0.28424f, 0.31008, 0.17054f,
+                       0.58915f, 0.65633f, 0.72351f, 0.45995f,
+                       0.91990f, 1.02842f, 1.13695f, 0.74935f,
+                       0.70801f, 0.81912f, 0.93023f
+               );
+               if (N != A) {
+                       cerr << "Failed:" << "Projective matrix N1 * N2 test" << endl;  
+                       failed_count++;
+               }
+       }
+       
+       {
+               matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+               vector3 v(1, 2, 3);
+               vector3 w = M * v;
+               vector3 a(0.20690f, 0.52874f, 0.85057f);
+               if (a != w) {
+                       cerr << "Failed:" << "M * v test" << endl;      
+                       failed_count++;
+               }
+       }
+
+
+       {
+               matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+               matrix3 N = 2 * M * 3;
+               matrix3 A(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90);
+               if (N != A) {
+                       cerr << "Failed:" << "s * M * s test" << endl;  
+                       failed_count++;
+               }
+       }
+       
+       {
+               matrix3 M(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90);
+               matrix3 N = M / 6;
+               matrix3 A(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+               if (N != A) {
+                       cerr << "Failed:" << "M / s test" << endl;      
+                       failed_count++;
+               }
+       }
 
        return failed_count;
 }
index 7e7b38a..1b278a1 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix2_test and b/src/mof/math/test/testbin/matrix2_test differ
index ce6c672..5513585 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix3_test and b/src/mof/math/test/testbin/matrix3_test differ
index 4527d37..37ddfae 100755 (executable)
Binary files a/src/mof/math/test/testbin/vector2_test and b/src/mof/math/test/testbin/vector2_test differ
index db7ecb5..4fef542 100755 (executable)
Binary files a/src/mof/math/test/testbin/vector3_test and b/src/mof/math/test/testbin/vector3_test differ
diff --git a/src/mof/math/threshold.hpp b/src/mof/math/threshold.hpp
new file mode 100644 (file)
index 0000000..bf7a2a7
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+#define MOF_ERROR_THRESHOLD 1e-3// 誤差閾値
index 3d25998..e4d1a82 100644 (file)
@@ -36,13 +36,11 @@ namespace math
                 * @brief 指定した値で初期化する.
                 * @param[in] arr 初期化用配列
                 */
-/*
                vector2(const vector2::array& arr)
                {
                        components_[0] = arr[0];
                        components_[1] = arr[1];
                }
-*/
 //}}}
 //{{{ accessers
                float x() const { return components_[0]; }
index aaa6a44..60a8970 100644 (file)
@@ -40,14 +40,12 @@ namespace math
                 * @brief 指定した値で初期化する.
                 * @param[in] arr 初期化用配列
                 */
-/*
                vector3(const vector3::array& arr)
                {
                        components_[0] = arr[0];
                        components_[1] = arr[1];
                        components_[2] = arr[2];
                }
-*/
 
 //}}}
 //{{{ accesser