OSDN Git Service

fix basic_matrix to pass tests
authortomohiro yasutomo <o_ggy@users.sourceforge.jp>
Mon, 6 Sep 2010 01:19:53 +0000 (18:19 -0700)
committertomohiro yasutomo <o_ggy@users.sourceforge.jp>
Mon, 6 Sep 2010 01:19:53 +0000 (18:19 -0700)
21 files changed:
TODO.txt
bin/numeric
lib/libmofmath.a
sample/CMakeLists.txt
src/build_unix/Testing/Temporary/LastTest.log
src/build_unix/Testing/Temporary/LastTestsFailed.log
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/make_matrix_test
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/test/vector2_test.cpp
src/mof/math/test/vector3_test.cpp
src/mof/math/vector2.hpp
src/mof/math/vector3.hpp

index 1a9b22e..72eef3c 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,4 +1,6 @@
+いらないfriend削除
 実装の理由のメモ
+make_zero
 test using boost::test
 make_rotation make_scaling *** test 
 make_rotation make_scaling *** impl
index c7a2b7b..22a530a 100755 (executable)
Binary files a/bin/numeric and b/bin/numeric differ
index 8802177..fde4fc2 100644 (file)
Binary files a/lib/libmofmath.a and b/lib/libmofmath.a differ
index 5dc0bab..e564b5f 100644 (file)
@@ -15,7 +15,7 @@ if (MSVC)
        set(CMAKE_CXX_FLAGS "/EHsc /nologo /W4 /WX")
 elseif (CMAKE_COMPILER_IS_GNUCC)
        set(CMAKE_CXX_FLAGS " -Wall -O3 -DNDEBUG -std=c++0x")
-       #set(CMAKE_CXX_FLAGS "-Wall -Werror -g -DPSTSDK_VALIDATION_LEVEL_FULL -std=c++0x")
+       #set(CMAKE_CXX_FLAGS "-Wall - -std=c++0x")
 endif()
 
 
index b8f8692..227fe09 100644 (file)
@@ -1,17 +1,17 @@
-Start testing: Sep 01 12:40 PDT
+Start testing: Sep 03 15:16 PDT
 ----------------------------------------------------------
 1/5 Testing: vector2_test
 1/5 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: Sep 01 12:40 PDT
+"vector2_test" start time: Sep 03 15:16 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
-Test time =   0.09 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"vector2_test" end time: Sep 01 12:40 PDT
+"vector2_test" end time: Sep 03 15:16 PDT
 "vector2_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -19,14 +19,14 @@ Test Passed.
 2/5 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: Sep 01 12:40 PDT
+"vector3_test" start time: Sep 03 15:16 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
-Test time =   0.01 sec
+Test time =   0.02 sec
 ----------------------------------------------------------
 Test Passed.
-"vector3_test" end time: Sep 01 12:40 PDT
+"vector3_test" end time: Sep 03 15:16 PDT
 "vector3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -34,23 +34,14 @@ Test Passed.
 3/5 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: Sep 01 12:40 PDT
+"matrix2_test" start time: Sep 03 15:16 PDT
 Output:
 ----------------------------------------------------------
-Failed: default constructor makes zero matrix
-Failed: initialize by array test
-Failed: addition test
-Failed: subtraction test
-Failed:Affine matrix N1 * N2 test
-Failed:Projective matrix N1 * N2 test
-Failed:M * v test
-Failed:s * M * s test
-Failed:M / s test
 <end of output>
 Test time =   0.01 sec
 ----------------------------------------------------------
-Test Failed.
-"matrix2_test" end time: Sep 01 12:40 PDT
+Test Passed.
+"matrix2_test" end time: Sep 03 15:16 PDT
 "matrix2_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -58,19 +49,14 @@ Test Failed.
 4/5 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: Sep 01 12:40 PDT
+"matrix3_test" start time: Sep 03 15:16 PDT
 Output:
 ----------------------------------------------------------
-Failed: initialize test
-Failed: initialize by array test
-Failed:Affine matrix N1 * N2 test
-Failed:M * v test
-Failed:s * M * s test
 <end of output>
-Test time =   0.01 sec
+Test time =   0.02 sec
 ----------------------------------------------------------
-Test Failed.
-"matrix3_test" end time: Sep 01 12:40 PDT
+Test Passed.
+"matrix3_test" end time: Sep 03 15:16 PDT
 "matrix3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -78,16 +64,15 @@ Test Failed.
 5/5 Test: make_matrix_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/make_matrix_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"make_matrix_test" start time: Sep 01 12:40 PDT
+"make_matrix_test" start time: Sep 03 15:16 PDT
 Output:
 ----------------------------------------------------------
-Failed --- make_identity2
 <end of output>
 Test time =   0.01 sec
 ----------------------------------------------------------
-Test Failed.
-"make_matrix_test" end time: Sep 01 12:40 PDT
+Test Passed.
+"make_matrix_test" end time: Sep 03 15:16 PDT
 "make_matrix_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
-End testing: Sep 01 12:40 PDT
+End testing: Sep 03 15:16 PDT
index bcb8473..5f9cf06 100644 (file)
@@ -10,8 +10,11 @@ namespace mof
 {
 namespace math
 {
+       template <size_t Dim> class row_of_matrix;
+
        /**
-        * @brief アフィン同次変換行列テンプレートクラス
+        * @brief 同次座標変換行列テンプレートクラス
+        * @note  このクラスはアフィン変換行列を表す
         * @note  このテンプレートから直接特殊化することは想定していない.
         * あくまでmatrixxを実装するための補助テンプレートである.
         * このクラスは不変クラスである.
@@ -116,9 +119,11 @@ namespace math
                        Derived M;
                        for (size_t i = 0; i < Dim; ++i) {
                                for (size_t j = 0; j <= Dim; ++j) {
+                                       float sum = 0;
                                        for (size_t k = 0; k <= Dim; ++k) {
-                                               M.elements_[i][j] += (*this)[i][k] * rhs[k][j];
+                                               sum += at(i, k) * rhs.at(k, j);
                                        }
+                                       M.elements_[i][j] = sum;
                                }
                        }
                        *this = M;
@@ -137,9 +142,11 @@ namespace math
                {
                        float arr[Dim];
                        for (size_t i = 0; i < Dim; ++i) {
+                               float sum = 0;
                                for (size_t k = 0; k <= Dim; ++k) {
-                                       arr[i] += (*this)[i][k] * rhs[k];
+                                       sum += (*this)[i][k] * rhs[k];
                                }
+                               arr[i] = sum;
                        }
                        return Coordinate(arr);
                }
@@ -167,12 +174,9 @@ namespace math
                 * @note M[i][j]のように参照可能
                 * @note この方法による複数の要素への参照は非効率
                 */
-               const float* const operator [](size_t i) const
+               row_of_matrix<Dim> const operator [](size_t i) const
                {
-                       static float arr[] = {0, 0, 0, 1};
-                       if (i < Dim) return &components_[i * Dim];
-                       return arr;
-                       // TODO index bounds check
+                       return row_of_matrix<Dim>(i, elements_);
                }
 //}}}
 //{{{ operator <<
@@ -207,7 +211,9 @@ namespace math
                 */
                const float at(size_t i, size_t j) const
                {
-                       return elements_[i][j];
+                       if (i < Dim ) return elements_[i][j];
+                       if (j == Dim) return 1;
+                       else return 0;
                }
 //}}}
        };
@@ -222,5 +228,28 @@ namespace math
                a.swap(b);
        }
 //}}}
+//{{{ row_of_matrix
+       /**
+        * @brief M[i][j]のように行列の要素を取得するための補助クラス
+        */
+       template <size_t Dim>
+       class row_of_matrix
+       {
+               size_t index_;
+               const float (&elements_)[Dim][Dim+1];
+       public:
+               row_of_matrix(size_t i, const float (&elements)[Dim][Dim+1])
+                       : index_(i), elements_(elements)
+               {
+               }
+
+               float operator[](size_t j) const
+               {
+                       if (Dim != index_) return elements_[index_][j];
+                       else if (Dim == j) return 1;
+                       else return 0;
+               }
+       };
+//}}}
 }// namespace math
 }// namespace mof
index a5df51c..80e0410 100644 (file)
@@ -11,7 +11,7 @@ namespace mof
 namespace math
 {
        /**
-        * @brief å\90\8c次å\88\97ベクトルテンプレートクラス
+        * @brief å\90\8c次座æ¨\99ベクトルテンプレートクラス
         * @note  このテンプレートから直接特殊化することは想定していない.
         * あくまでvectorxを実装するための補助テンプレートである.
         * このクラスは不変クラスである.
index c7d2215..a460b76 100644 (file)
@@ -8,20 +8,18 @@ namespace math
        class vector2;
 
        /**
-        * @brief 2次元アフィン同次座標変換行列クラス
+        * @brief 2次元同次座標変換行列クラス
         */
        class matrix2 : public basic_matrix<2, matrix2, vector2>
        {
        public:
 //{{{ constructor
                /**
-                * @brief デフォルトコンストラクタ.最後の要素以外を0で初期化する.
+                * @brief デフォルトコンストラクタ
+                * @note  効率のため,初期化は行われない
                 */
                matrix2()
                {
-                       for (size_t i = 0; i < size(); ++i) {
-                               components_[i] = 0;
-                       }
                }
 
                /**
@@ -51,7 +49,7 @@ namespace math
                                        &m11, &m12, &m13,
                                        &m21, &m22, &m23
                                };
-                       for (size_t i = 0; i < size() - 1; ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] = *table[i];
                        }
                }
index fcf48f3..77e6ade 100644 (file)
@@ -8,20 +8,18 @@ namespace math
        class vector3;
 
        /**
-        * @brief 3次元アフィン同次座標変換行列クラス
+        * @brief 3次元同次座標変換行列クラス
         */
        class matrix3 : public basic_matrix<3, matrix3, vector3>
        {
        public:
 //{{{ constructor
                /**
-                * @brief デフォルトコンストラクタ.最後の要素以外を0で初期化する.
+                * @brief デフォルトコンストラクタ
+                * @note  効率のため,初期化は行われない
                 */
                matrix3()
                {
-                       for (size_t i = 0; i < size(); ++i) {
-                               components_[i] = 0;
-                       }
                }
 
                /**
index 987640a..0f87c0c 100644 (file)
@@ -10,18 +10,6 @@ int main()
        int failed_count = 0;
 
        {
-               matrix2 M;
-               bool failed = false;
-               for (size_t i = 0; i < 8; ++i) {
-                       if (M[i / 3][i % 3] != 0) failed = true;
-               }
-               if (failed || M[2][2] != 1) {
-                       cerr << "Failed:" << " default constructor makes zero matrix" << endl;  
-                       failed_count++;
-               }
-       }
-
-       {
                float arr[] = {1, 2, 3, 4, 5, 6};
                matrix2 M(arr);
                bool failed = false;
@@ -34,7 +22,6 @@ int main()
                }
        }
 
-       // any operations keeps the last component 1
        {       
                matrix2 M(1, 2, 3, 4, 5, 6);
                matrix2 N(1, 2, 3, 4, 5, 6);
@@ -87,21 +74,10 @@ int main()
        }
        
        {
-               matrix2 N1(1, 2, 3, 4, 5, 6);
-               matrix2 N2(2, 3, 4, 5, 6, 7);
-               matrix2 N = N1 * N2;
-               matrix2 A(0.42353f, 0.49412f, 0.24706f, 0.95294f, 1.12941f, 0.67059f);
-               if (N != A) {
-                       cerr << "Failed:" << "Projective matrix N1 * N2 test" << endl;  
-                       failed_count++;
-               }
-       }
-       
-       {
                matrix2 M(1, 2, 3, 4, 5, 6);
                vector2 v(1, 2);
                vector2 w = M * v;
-               vector2 a(0.33333f, 0.83333f);
+               vector2 a(8, 20);
                if (a != w) {
                        cerr << "Failed:" << "M * v test" << endl;      
                        failed_count++;
index 0b0b908..f079e11 100644 (file)
@@ -10,24 +10,12 @@ int main()
        int failed_count = 0;
 
        {
-               matrix3 M;
-               bool failed = false;
-               for (size_t i = 0; i < 15; ++i) {
-                       if (M[i / 4][i % 4] != 0) failed = true;
-               }
-               if (failed || M[3][3] != 1) {
-                       cerr << "Failed:" << " default constructor makes zero matrix" << endl;  
-                       failed_count++;
-               }
-       }
-
-       {
                matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
                bool failed = false;
                for (size_t i = 0; i < 12; ++i) {
                        if (M[i / 4][i % 4] != i + 1) failed = true;
                }
-               if (failed || M[3][0] != 0 || M[3][1] != 1 || M[3][2] != 2 || M[3][3] != 1) {
+               if (failed || M[3][0] != 0 || M[3][1] != 0 || M[3][2] != 0 || M[3][3] != 1) {
                        cerr << "Failed:" << " initialize test" << endl;        
                        failed_count++;
                }
@@ -40,7 +28,7 @@ int main()
                for (size_t i = 0; i < 12; ++i) {
                        if (M[i / 4][i % 4] != i + 1) failed = true;
                }
-               if (failed || M[3][0] != 0 || M[3][1] != 1 || M[3][2] != 2 || M[3][3] != 1) {
+               if (failed || M[3][0] != 0 || M[3][1] != 0 || M[3][2] != 0 || M[3][3] != 1) {
                        cerr << "Failed:" << " initialize by array test" << endl;       
                        failed_count++;
                }
@@ -106,7 +94,7 @@ int main()
                matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
                vector3 v(1, 2, 3);
                vector3 w = M * v;
-               vector3 a(0.20690f, 0.52874f, 0.85057f);
+               vector3 a(18, 46, 74);
                if (a != w) {
                        cerr << "Failed:" << "M * v test" << endl;      
                        failed_count++;
@@ -115,7 +103,7 @@ int main()
 
 
        {
-               matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 125);
+               matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
                matrix3 N = 2 * M * 3;
                matrix3 A(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72);
                if (N != A) {
index 90f5f58..b193979 100755 (executable)
Binary files a/src/mof/math/test/testbin/make_matrix_test and b/src/mof/math/test/testbin/make_matrix_test differ
index 9c8f72e..0de64cd 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix2_test and b/src/mof/math/test/testbin/matrix2_test differ
index 7115e0b..6e36d71 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix3_test and b/src/mof/math/test/testbin/matrix3_test differ
index 48a738a..9e9025b 100755 (executable)
Binary files a/src/mof/math/test/testbin/vector2_test and b/src/mof/math/test/testbin/vector2_test differ
index 6d8521c..a440908 100755 (executable)
Binary files a/src/mof/math/test/testbin/vector3_test and b/src/mof/math/test/testbin/vector3_test differ
index b18021e..43e2b26 100644 (file)
@@ -9,11 +9,6 @@ int main()
        vector2 v;
        int failed_count = 0;
 
-       if (v.x() != 0 || v.y() != 0 || v.z() != 1) {
-               cerr << "Failed:" << " default constructor makes zero vector" << endl;  
-               failed_count++;
-       }
-
        v = vector2(1, 2);
        if (v[0] != 1 || v[1] != 2 || v[2] != 1) {
                cerr << "Failed:" << " initialize by array" << endl;    
index cfcaab3..0595787 100644 (file)
@@ -8,11 +8,6 @@ int main()
        vector3 v;
        int failed_count = 0;
 
-       if (v.x() != 0 || v.y() != 0 || v.z() != 0 || v.w() != 1) {
-               cerr << "Failed:" << " default constructor makes zero vector" << endl;  
-               failed_count++;
-       }
-
        v = vector3(1, 2, 3);
        if (v[0] != 1 || v[1] != 2 || v[2] != 3 || v[3] != 1) {
                cerr << "Failed:" << " initialize by array" << endl;    
index d34a248..5948019 100644 (file)
@@ -6,19 +6,18 @@ namespace mof
 namespace math
 {
        /**
-        * @brief 2次å\85\83å\90\8c次å\88\97ベクトルクラス
+        * @brief 2次å\85\83å\90\8c次座æ¨\99ベクトルクラス
         */
        class vector2 : public basic_vector<2, vector2>
        {
        public:
 //{{{ constructor
                /**
-                * @brief デフォルトコンストラクタ.全ての要素を0で初期化する.
+                * @brief デフォルトコンストラクタ.
+                * @note  効率のためは初期化されない
                 */
                vector2()
                {
-                       components_[0] = 0;
-                       components_[1] = 0;
                }
 
                /**
index e3b4f2b..9b71f41 100644 (file)
@@ -7,20 +7,18 @@ namespace mof
 namespace math
 {
        /**
-        * @brief 3次å\85\83å\90\8c次å\88\97ベクトルクラス
+        * @brief 3次å\85\83å\90\8c次座æ¨\99ベクトルクラス
         */
        class vector3 : public basic_vector<3, vector3>
        {
        public:
 //{{{ constructor
                /**
-                * @brief デフォルトコンストラクタ.全ての要素を0で初期化する.
+                * @brief デフォルトコンストラクタ.
+                * @note  効率のためは初期化されない
                 */
                vector3()
                {
-                       components_[0] = 0;
-                       components_[1] = 0;
-                       components_[2] = 0;
                }
 
                /**