OSDN Git Service

mat_fix end
authortomohiro yasutomo <o_ggy@users.sourceforge.jp>
Wed, 1 Sep 2010 19:52:04 +0000 (12:52 -0700)
committertomohiro yasutomo <o_ggy@users.sourceforge.jp>
Wed, 1 Sep 2010 19:52:04 +0000 (12:52 -0700)
20 files changed:
TODO.txt
bin/numeric
lib/libmofmath.a
src/build_unix/CMakeFiles/Progress/4 [deleted file]
src/build_unix/CMakeFiles/Progress/5 [deleted file]
src/build_unix/CMakeFiles/Progress/count.txt [deleted file]
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/make_matrix_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

index 618e19d..1a9b22e 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,3 +1,5 @@
+実装の理由のメモ
+test using boost::test
 make_rotation make_scaling *** test 
 make_rotation make_scaling *** impl
 doxygen
index 32925b0..c7a2b7b 100755 (executable)
Binary files a/bin/numeric and b/bin/numeric differ
index 0534f27..8802177 100644 (file)
Binary files a/lib/libmofmath.a and b/lib/libmofmath.a differ
diff --git a/src/build_unix/CMakeFiles/Progress/4 b/src/build_unix/CMakeFiles/Progress/4
deleted file mode 100644 (file)
index 7b4d68d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-empty
\ No newline at end of file
diff --git a/src/build_unix/CMakeFiles/Progress/5 b/src/build_unix/CMakeFiles/Progress/5
deleted file mode 100644 (file)
index 7b4d68d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-empty
\ No newline at end of file
diff --git a/src/build_unix/CMakeFiles/Progress/count.txt b/src/build_unix/CMakeFiles/Progress/count.txt
deleted file mode 100644 (file)
index 7f8f011..0000000
+++ /dev/null
@@ -1 +0,0 @@
-7
index 1c8a599..b8f8692 100644 (file)
@@ -1,17 +1,17 @@
-Start testing: Aug 19 13:43 PDT
+Start testing: Sep 01 12:40 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: Aug 19 13:43 PDT
+"vector2_test" start time: Sep 01 12:40 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
-Test time =   0.00 sec
+Test time =   0.09 sec
 ----------------------------------------------------------
 Test Passed.
-"vector2_test" end time: Aug 19 13:43 PDT
+"vector2_test" end time: Sep 01 12:40 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: Aug 19 13:43 PDT
+"vector3_test" start time: Sep 01 12:40 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
-Test time =   0.00 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"vector3_test" end time: Aug 19 13:43 PDT
+"vector3_test" end time: Sep 01 12:40 PDT
 "vector3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -34,14 +34,23 @@ 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: Aug 19 13:43 PDT
+"matrix2_test" start time: Sep 01 12:40 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.00 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
-Test Passed.
-"matrix2_test" end time: Aug 19 13:43 PDT
+Test Failed.
+"matrix2_test" end time: Sep 01 12:40 PDT
 "matrix2_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -49,14 +58,19 @@ Test Passed.
 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: Aug 19 13:43 PDT
+"matrix3_test" start time: Sep 01 12:40 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.00 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
-Test Passed.
-"matrix3_test" end time: Aug 19 13:43 PDT
+Test Failed.
+"matrix3_test" end time: Sep 01 12:40 PDT
 "matrix3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -64,21 +78,16 @@ Test Passed.
 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: Aug 19 13:43 PDT
+"make_matrix_test" start time: Sep 01 12:40 PDT
 Output:
 ----------------------------------------------------------
 Failed --- make_identity2
-
-    0,     0,     0
-    0,     0,     0
-    0,     0,     1
-Failed --- make_identity2
 <end of output>
-Test time =   0.02 sec
+Test time =   0.01 sec
 ----------------------------------------------------------
 Test Failed.
-"make_matrix_test" end time: Aug 19 13:43 PDT
+"make_matrix_test" end time: Sep 01 12:40 PDT
 "make_matrix_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
-End testing: Aug 19 13:43 PDT
+End testing: Sep 01 12:40 PDT
index 08ad246..bcb8473 100644 (file)
@@ -32,13 +32,13 @@ namespace math
                > > > > > > > >
        {
        protected:
-//{{{ last_index
+//{{{ size
                /**
-                * @brief components_の最後の添字を得る
+                * @brief components_のサイズを返す
                 */
-               size_t last_index() const
+               size_t size() const
                {
-                       return Dim * (Dim + 1) - 1;
+                       return Dim * (Dim + 1);
                }
 //}}}
                union 
@@ -49,18 +49,27 @@ namespace math
        public:
                // コンストラクタ,デストラクタはデフォルトのものを使う
                // 代入演算子,コピーコンストラクタはデフォルトのものを使う
+//{{{ swap
+               void swap(Derived& rhs) throw()
+               {
+                       using std::swap;
+                       for (size_t i = 0; i < size(); ++i) {
+                               swap(components_[i], rhs.components_[i]);
+                       }
+               }
+//}}}
 //{{{ operator +=
-               Derived& operator+=(const Derived& rhs) const
+               Derived& operator+=(const Derived& rhs)
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] += rhs.components_[i];
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
                
-               Derived& operator+=(float rhs) const
+               Derived& operator+=(float rhs) 
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] += rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -68,25 +77,25 @@ namespace math
                
                friend Derived operator+(float rhs1, Derived& rhs2)
                {
-                       float tmp[last_index() + 1];
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       float tmp[size()];
+                       for (size_t i = 0; i < size(); ++i) {
                                tmp[i] = rhs1 + rhs2.components_[i];
                        }
                        return Derived(tmp);
                }
 //}}}
 //{{{ operator -=
-               Derived& operator-=(const Derived& rhs) const
+               Derived& operator-=(const Derived& rhs)
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] -= rhs.components_[i];
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
                
-               Derived& operator-=(float rhs) const
+               Derived& operator-=(float rhs)
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] -= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -94,20 +103,20 @@ namespace math
                
                friend Derived operator-(float rhs1, Derived& rhs2) 
                {
-                       float tmp[last_index() + 1];
-                       for (size_t i = 0; i <= last_index(); ++i) {
-                               retval.components_[i] = rhs1 - rhs2.components_[i];
+                       float tmp[size()];
+                       for (size_t i = 0; i < size(); ++i) {
+                               tmp[i] = rhs1 - rhs2.components_[i];
                        }
                        return Derived(tmp);
                }
 //}}}
 //{{{ operator *=      
-               Derived& operator*=(const Derived& rhs) const
+               Derived& operator*=(const Derived& rhs)
                {
                        Derived M;
-                       for (int i = 0; i < Dim; ++i) {
-                               for (int j = 0; j <= Dim; ++j) {
-                                       for (int k = 0; k <= Dim; ++k) {
+                       for (size_t i = 0; i < Dim; ++i) {
+                               for (size_t j = 0; j <= Dim; ++j) {
+                                       for (size_t k = 0; k <= Dim; ++k) {
                                                M.elements_[i][j] += (*this)[i][k] * rhs[k][j];
                                        }
                                }
@@ -116,38 +125,29 @@ namespace math
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
 
-               Derived& operator*=(float rhs) const
+               Derived& operator*=(float rhs) 
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] *= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
        
-               Coordinate operator*(const Coordinate& rhs) const
+               Coordinate operator*(const Coordinate& rhs)
                {
                        float arr[Dim];
-                       for (int i = 0; i < Dim; ++i) {
-                               for (int k = 0; k <= Dim; ++k) {
+                       for (size_t i = 0; i < Dim; ++i) {
+                               for (size_t k = 0; k <= Dim; ++k) {
                                        arr[i] += (*this)[i][k] * rhs[k];
                                }
                        }
                        return Coordinate(arr);
                }
-
-               friend Derived operator*(float rhs1, Derived& rhs2) 
-               {
-                       float arr[last_index() + 1];
-                       for (size_t i = 0; i <= last_index(); ++i) {
-                               arr[i] *= rhs;
-                       }
-                       return Derived(arr);
-               }
 //}}}
 //{{{ operator /=
-               Derived& operator/=(float rhs) const
+               Derived& operator/=(float rhs)
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] /= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -156,7 +156,7 @@ namespace math
 //{{{ operator ==
                bool operator==(const Derived& rhs) const
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                if (std::abs(components_[i] - rhs.components_[i]) > MOF_ERROR_THRESHOLD) return false;
                        }
                        return true;
@@ -211,5 +211,16 @@ namespace math
                }
 //}}}
        };
+//{{{ swap
+       template <size_t Dim, typename Derived, typename Coordinate>
+       void swap
+       (
+               basic_matrix<Dim, Derived, Coordinate>& a,
+               basic_matrix<Dim, Derived, Coordinate>& b
+       ) throw()
+       {
+               a.swap(b);
+       }
+//}}}
 }// namespace math
 }// namespace mof
index fd01e00..a5df51c 100644 (file)
@@ -35,20 +35,19 @@ namespace math
                // コンストラクタ,デストラクタはデフォルトのものを使う
                // 代入演算子,コピーコンストラクタはデフォルトのものを使う
 //{{{ swap
-               void swap(Derived& rhs) const throw()
+               void swap(Derived& rhs) throw()
                {
-                       float c;
                        for (size_t i = 0; i < Dim; ++i) std::swap(rhs.components_[i], components_[i]);
                }
 //}}}
 //{{{ operator +=
-               Derived& operator+=(const Derived& rhs) const
+               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) const
+               Derived& operator+=(float rhs) 
                {
                        for (size_t i = 0; i < Dim; ++i) components_[i] += rhs;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -62,13 +61,13 @@ namespace math
                }
 //}}}
 //{{{ operator -=
-               Derived& operator-=(const Derived& rhs) const
+               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) const
+               Derived& operator-=(float rhs)
                {
                        for (size_t i = 0; i < Dim; ++i) components_[i] -= rhs;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -82,7 +81,7 @@ namespace math
                }
 //}}}
 //{{{ operator *=
-               Derived& operator*=(float rhs) const
+               Derived& operator*=(float rhs)
                {
                        for (size_t i = 0; i < Dim; ++i) components_[i] *= rhs;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -96,7 +95,7 @@ namespace math
                }
 //}}}
 //{{{ operator /=
-               Derived& operator/=(float rhs) const
+               Derived& operator/=(float rhs)
                {
                        for (size_t i = 0; i < Dim; ++i) components_[i] /= rhs;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@ -146,7 +145,13 @@ namespace math
                }
 //}}}
        };
-
+//{{{ swap
+       template <size_t Dim, typename Derived>
+       void swap(basic_vector<Dim, Derived>& a, basic_vector<Dim, Derived>& b) throw()
+       {
+               a.swap(b);
+       }
+//}}}
 
 }// namespace math
 }// namespace mof
index cdd1f7e..c7d2215 100644 (file)
@@ -19,7 +19,7 @@ namespace math
                 */
                matrix2()
                {
-                       for (size_t i = 0; i <= last_index(); ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] = 0;
                        }
                }
@@ -32,10 +32,9 @@ namespace math
                template <class T>
                explicit matrix2(const T& arr)
                {
-                       for (size_t i = 0; i <= last_index() - 1; ++i) {
-                               elements_[i] = arr[i];
+                       for (size_t i = 0; i < size(); ++i) {
+                               components_[i] = arr[i];
                        }
-                       elements_[last_index()] = 1;
                }
                
                /**
@@ -44,27 +43,24 @@ namespace math
                matrix2
                (
                        float m11, float m12, float m13,
-                       float m21, float m22, float m23,
-                       float m31, float m32
+                       float m21, float m22, float m23
                )
                {
                        const float* table[] =
                                {
                                        &m11, &m12, &m13,
-                                       &m21, &m22, &m23,
-                                       &m31, &m32
+                                       &m21, &m22, &m23
                                };
-                       for (size_t i = 0; i <= last_index() - 1; ++i) {
-                               elements_[i] = *table[i];
+                       for (size_t i = 0; i < size() - 1; ++i) {
+                               components_[i] = *table[i];
                        }
-                       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 < size(); ++i) {
                        components_[i] = rhs.components_[i];
                }
        }
@@ -72,7 +68,7 @@ namespace math
 //{{{ operator =
        matrix2& operator = (const matrix2& rhs)
        {
-               for (size_t i = 0; i <= last_index(); ++i) {
+               for (size_t i = 0; i < size(); ++i) {
                        components_[i] = rhs.components_[i];
                }
                return *this;
index 71147a0..fcf48f3 100644 (file)
@@ -19,10 +19,9 @@ namespace math
                 */
                matrix3()
                {
-                       for (size_t i = 0; i <= last_index() - 1; ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] = 0;
                        }
-                       components_[last_index()] = 1;
                }
 
                /**
@@ -33,10 +32,9 @@ namespace math
                template <class T>
                explicit matrix3(const T& arr)
                {
-                       for (size_t i = 0; i <= last_index() - 1; ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] = arr[i];
                        }
-                       components_[last_index()] = 1;
                }
 
                /**
@@ -46,28 +44,25 @@ namespace math
                (
                        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
+                       float m31, float m32, float m33, float m34
                )
                {
                        const float* table[] =
                                {
                                        &m11, &m12, &m13, &m14,
                                        &m21, &m22, &m23, &m24,
-                                       &m31, &m32, &m33, &m34,
-                                       &m41, &m42, &m43
+                                       &m31, &m32, &m33, &m34
                                };
-                       for (size_t i = 0; i <= last_index() - 1; ++i) {
+                       for (size_t i = 0; i < size(); ++i) {
                                components_[i] = *table[i];
                        }
-                       components_[last_index()] = 1;
                }
 
 //}}}
 //{{{ copy constructor
        matrix3(const matrix3& rhs)
        {
-               for (size_t i = 0; i < last_index(); ++i) {
+               for (size_t i = 0; i < size(); ++i) {
                        components_[i] = rhs.components_[i];
                }
        }
@@ -78,7 +73,7 @@ namespace math
         */
        matrix3& operator = (const matrix3& rhs)
        {
-               for (size_t i = 0; i < last_index(); ++i) {
+               for (size_t i = 0; i < size(); ++i) {
                        components_[i] = rhs.components_[i];
                }
                return *this;
index 7696590..cdac064 100644 (file)
@@ -9,22 +9,13 @@ int main()
        
        {
                matrix2 M = make_identity2();
-               matrix2 A = matrix2(1, 0, 0, 0, 1, 0, 0, 0);
+               matrix2 A = matrix2(1, 0, 0, 0, 1, 0);
                if (M != A) {
                        failed_count++;
                        cerr << "Failed --- make_identity2" << endl;
                }
        }
        
-       {
-               matrix2 M1 = matrix2(1, 2, 3, 4, 5, 6, 7, 8);
-               matrix2 M2 = make_transposed2(M1);
-               matrix2 A = matrix2(1, 4, 7, 2, 5, 0, 0, 0);
-               if (M2 != A) {
-                       failed_count++;
-                       cerr << "Failed --- make_identity2" << endl;
-               }
-       }
 
        return failed_count;
 }
index 961e17f..90f5f58 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 61ca3bf..9c8f72e 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix2_test and b/src/mof/math/test/testbin/matrix2_test differ
index 0c0198f..7115e0b 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix3_test and b/src/mof/math/test/testbin/matrix3_test differ
index 1831ade..48a738a 100755 (executable)
Binary files a/src/mof/math/test/testbin/vector2_test and b/src/mof/math/test/testbin/vector2_test differ
index d22339c..6d8521c 100755 (executable)
Binary files a/src/mof/math/test/testbin/vector3_test and b/src/mof/math/test/testbin/vector3_test differ
index 3506253..b18021e 100644 (file)
@@ -68,8 +68,8 @@ int main()
 
        v = vector2(1, 2);
        w = vector2(3, 4);
-       v.swap(w);
-       if (v.x != 3 || v.y != 4 || w.x != 1 || w.y != 2) {
+       swap(v, w);
+       if (v.x() != 3 || v.y() != 4 || w.x() != 1 || w.y() != 2) {
                cerr << "Failed:" << " swap test" << endl;      
                failed_count++;
        }
index 3d792b4..cfcaab3 100644 (file)
@@ -66,10 +66,10 @@ int main()
                failed_count++;
        }
 
-       v = vector2(1, 2, 3);
-       w = vector2(4, 5, 6);
-       v.swap(w);
-       if (v.x != 4 || v.y != 5 || v.z != 6 || w.x != 1 || w.y != 2 || w.z != 3) {
+       v = vector3(1, 2, 3);
+       w = vector3(4, 5, 6);
+       swap(v, w);
+       if (v.x() != 4 || v.y() != 5 || v.z() != 6 || w.x() != 1 || w.y() != 2 || w.z() != 3) {
                cerr << "Failed:" << " swap test" << endl;      
                failed_count++;
        }