--- /dev/null
+100000000 times repeating
+***copy performance test***
+vector2 --- 61140[micro sec]
+raw type2 --- 44058[micro sec]
+vector3 --- 41559[micro sec]
+raw type3 --- 41272[micro sec]
+matrix2 --- 42470[micro sec]
+raw type9 --- 40862[micro sec]
+matrix3 --- 40334[micro sec]
+raw type16 --- 39556[micro sec]
+shared type --- 123380[micro sec]
+***add performance test***
+vector2 + vector2 --- 122974[micro sec]
+vector3 + vector3 --- 123472[micro sec]
+matrix2 + matrix2 --- 626758[micro sec]
+matrix3 + matrix3 --- 957516[micro sec]
+***multiply performance test***
+matrix2 * vector2 --- 1158626[micro sec]
+matrix3 * vector3 --- 1700042[micro sec]
+
+100000000 times repeating
+***copy performance test***
+vector2 --- 62594[micro sec]
+raw type2 --- 40726[micro sec]
+vector3 --- 41518[micro sec]
+raw type3 --- 42889[micro sec]
+matrix2 --- 41901[micro sec]
+raw type9 --- 43194[micro sec]
+matrix3 --- 40890[micro sec]
+raw type16 --- 39739[micro sec]
+shared type --- 126350[micro sec]
+***add performance test***
+vector2 + vector2 --- 123069[micro sec]
+vector3 + vector3 --- 127493[micro sec]
+matrix2 + matrix2 --- 632304[micro sec]
+matrix3 + matrix3 --- 972639[micro sec]
+***multiply performance test***
+matrix2 * vector2 --- 1149971[micro sec]
+matrix3 * vector3 --- 1704253[micro sec]
--- /dev/null
+empty
\ No newline at end of file
--- /dev/null
+empty
\ No newline at end of file
#IncludeRegexTransform:
+../mof/base/mofdef.hpp
+cstddef
+-
+mof/base/tstring.hpp
+-
+
+../mof/base/tstring.hpp
+string
+-
+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/make_matrix.hpp
+mof/math/matrix.hpp
+-
+mof/math/vector.hpp
+-
+
+../mof/math/matrix.hpp
+mof/math/matrix2.hpp
+-
+mof/math/matrix3.hpp
+-
+
+../mof/math/matrix2.hpp
+mof/math/basic_matrix.hpp
+-
+
+../mof/math/matrix3.hpp
+mof/math/basic_matrix.hpp
+-
+
+../mof/math/threshold.hpp
+
+../mof/math/vector.hpp
+mof/math/vector2.hpp
+-
+mof/math/vector3.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/make_matrix.cpp
-make_matrix.hpp
+mof/math/make_matrix.hpp
-
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o
+ ../mof/base/mofdef.hpp
+ ../mof/base/tstring.hpp
+ ../mof/math/basic_matrix.hpp
+ ../mof/math/basic_vector.hpp
+ ../mof/math/make_matrix.hpp
+ ../mof/math/matrix.hpp
+ ../mof/math/matrix2.hpp
+ ../mof/math/matrix3.hpp
+ ../mof/math/threshold.hpp
+ ../mof/math/vector.hpp
+ ../mof/math/vector2.hpp
+ ../mof/math/vector3.hpp
/home/yasutomo/devel/moflib/src/mof/math/make_matrix.cpp
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/base/mofdef.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/base/tstring.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/basic_matrix.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/basic_vector.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/make_matrix.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/matrix.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/matrix2.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/matrix3.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/threshold.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/vector.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/vector2.hpp
+mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/vector3.hpp
mof/math/CMakeFiles/mofmath.dir/make_matrix.cpp.o: ../mof/math/make_matrix.cpp
{
namespace math
{
-
- template <size_t Dim> struct row_of_matrix;
-
/**
- * @brief 同次座標変換行列テンプレートクラス
+ * @brief アフィン同次変換行列テンプレートクラス
* @note このテンプレートから直接特殊化することは想定していない.
* あくまでmatrixxを実装するための補助テンプレートである.
* このクラスは不変クラスである.
protected:
//{{{ last_index
/**
- * @brief elements_の最後の添字を得る
+ * @brief components_の最後の添字を得る
*/
size_t last_index() const
{
- return (Dim + 1) * (Dim + 1) - 1;
+ return Dim * (Dim + 1) - 1;
}
//}}}
- float elements_[(Dim + 1) * (Dim + 1)];///< 要素の配列
+ union
+ {
+ float components_[Dim * (Dim + 1)];
+ float elements_[Dim][Dim + 1];
+ };///< 要素の配列(アフィン行列なので,最後の行は省略している)
public:
// コンストラクタ,デストラクタはデフォルトのものを使う
// 代入演算子,コピーコンストラクタはデフォルトのものを使う
//{{{ operator +=
- Derived& operator+=(const Derived& rhs)
+ Derived& operator+=(const Derived& rhs) const
{
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i <= END; ++i) {
- elements_[i] += rhs.elements_[i];
+ for (size_t i = 0; i <= last_index(); ++i) {
+ components_[i] += rhs.components_[i];
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- Derived& operator+=(float rhs)
+ Derived& operator+=(float rhs) const
{
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i <= END; ++i) {
- elements_[i] += rhs;
+ for (size_t i = 0; i <= last_index(); ++i) {
+ components_[i] += rhs;
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- friend Derived operator+(float rhs1, Derived& rhs2)
+ 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];
+ float tmp[last_index() + 1];
+ for (size_t i = 0; i <= last_index(); ++i) {
+ tmp[i] = rhs1 + rhs2.components_[i];
}
- return retval;
+ return Derived(tmp);
}
//}}}
//{{{ operator -=
- Derived& operator-=(const Derived& rhs)
+ Derived& operator-=(const Derived& rhs) const
{
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i <= END; ++i) {
- elements_[i] -= rhs.elements_[i];
+ for (size_t i = 0; i <= last_index(); ++i) {
+ components_[i] -= rhs.components_[i];
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- Derived& operator-=(float rhs)
+ Derived& operator-=(float rhs) const
{
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i <= END; ++i) {
- elements_[i] -= rhs;
+ for (size_t i = 0; i <= last_index(); ++i) {
+ components_[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];
+ float tmp[last_index() + 1];
+ for (size_t i = 0; i <= last_index(); ++i) {
+ retval.components_[i] = rhs1 - rhs2.components_[i];
}
- return retval;
+ return Derived(tmp);
}
//}}}
//{{{ operator *=
- /**
- * @brief 行列の積を計算し,最後の要素が1になるように定数倍する.
- */
- Derived& operator*=(const Derived& rhs)
- {
- Derived retval;
- 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 (int i = 0; i < SIZE; ++i) {
- sum += elements_[b + i] * rhs.elements_[c + i * SIZE];
+ Derived& operator*=(const Derived& rhs) const
+ {
+ Derived M;
+ for (int i = 0; i < Dim; ++i) {
+ for (int j = 0; j <= Dim; ++j) {
+ for (int k = 0; k <= Dim; ++k) {
+ M.elements_[i][j] += (*this)[i][k] * rhs[k][j];
+ }
}
- retval.elements_[a] = sum / last_sum;
}
- *this = retval;
+ *this = M;
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- Derived& operator*=(float rhs)
+ Derived& operator*=(float rhs) const
{
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i <= END; ++i) {
- elements_[i] *= rhs;
+ for (size_t i = 0; i <= last_index(); ++i) {
+ components_[i] *= rhs;
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- /**
- * @brief ベクトルを変換し,最後の要素が1になるように定数倍する.
- */
- Coordinate operator*(const Coordinate& rhs)
+ Coordinate operator*(const Coordinate& rhs) const
{
- 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];
- }
-
float arr[Dim];
- for (size_t a = 0; a < Dim; ++a) {
- float sum = 0;
- for (size_t i = 0; i < SIZE; ++i) {
- sum += elements_[a * SIZE + i] * rhs[i];
+ for (int i = 0; i < Dim; ++i) {
+ for (int k = 0; k <= Dim; ++k) {
+ arr[i] += (*this)[i][k] * rhs[k];
}
- arr[a] = sum / last_sum;
}
return Coordinate(arr);
}
-
friend Derived operator*(float rhs1, Derived& rhs2)
{
- Derived retval;
- const size_t END = rhs2.last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i <= END; ++i) {
- retval.elements_[i] = rhs1 * rhs2.elements_[i];
+ float arr[last_index() + 1];
+ for (size_t i = 0; i <= last_index(); ++i) {
+ arr[i] *= rhs;
}
- return retval;
+ return Derived(arr);
}
//}}}
//{{{ operator /=
- Derived& operator/=(float rhs)
+ Derived& operator/=(float rhs) const
{
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i <= END; ++i) {
- elements_[i] /= rhs;
+ for (size_t i = 0; i <= last_index(); ++i) {
+ components_[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 (std::abs(elements_[i] - rhs.elements_[i]) > MOF_ERROR_THRESHOLD) return false;
+ for (size_t i = 0; i <= last_index(); ++i) {
+ if (std::abs(components_[i] - rhs.components_[i]) > MOF_ERROR_THRESHOLD) return false;
}
return true;
}
//}}}
//{{{ operator []
/**
- * @note 補助クラスによってM[i][j]のように参照可能
+ * @note M[i][j]のように参照可能
* @note この方法による複数の要素への参照は非効率
*/
- row_of_matrix<Dim> operator [](size_t i) const
+ const float* const operator [](size_t i) const
{
- return row_of_matrix<Dim>(elements_, i);
+ static float arr[] = {0, 0, 0, 1};
+ if (i < Dim) return &components_[i * Dim];
+ return arr;
+ // TODO index bounds check
}
//}}}
//{{{ operator <<
for (size_t j = 0; j < Dim + 1; ++j) {
if (j != 0) stream << ", ";
else if (j != Dim) stream << "\n";
- stream << std::setw(5) << rhs.elements_[i * (Dim + 1) + j];
+ stream << std::setw(5) << rhs[i][j];
}
}
return stream;
* @param[in] 列番号
* @return 要素
*/
- float at(size_t i, size_t j) const
+ const float at(size_t i, size_t j) const
{
- return elements_[i * (Dim + 1) + j];
+ return elements_[i][j];
}
//}}}
};
-//{{{ 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) const {return elements_[row_index_ * (Dim + 1) + index];}
- };
-//}}}
-
}// namespace math
}// namespace mof
public:
// コンストラクタ,デストラクタはデフォルトのものを使う
// 代入演算子,コピーコンストラクタはデフォルトのものを使う
+//{{{ swap
+ void swap(Derived& rhs) const throw()
+ {
+ float c;
+ for (size_t i = 0; i < Dim; ++i) std::swap(rhs.components_[i], components_[i]);
+ }
+//}}}
//{{{ operator +=
- Derived& operator+=(const Derived& rhs)
+ Derived& operator+=(const Derived& rhs) const
{
for (size_t i = 0; i < Dim; ++i) components_[i] += rhs.components_[i];
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- Derived& operator+=(float rhs)
+ Derived& operator+=(float rhs) const
{
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)
+ friend Derived operator+(float rhs1, Derived& rhs2)
{
Derived retval;
for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 + rhs2.components_[i];
}
//}}}
//{{{ operator -=
- Derived& operator-=(const Derived& rhs)
+ Derived& operator-=(const Derived& rhs) const
{
for (size_t i = 0; i < Dim; ++i) components_[i] -= rhs.components_[i];
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- Derived& operator-=(float rhs)
+ Derived& operator-=(float rhs) const
{
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)
+ friend Derived operator-(float rhs1, Derived& rhs2)
{
Derived retval;
for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 - rhs2.components_[i];
}
//}}}
//{{{ operator *=
- Derived& operator*=(float rhs)
+ Derived& operator*=(float rhs) const
{
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)
+ friend Derived operator*(float rhs1, Derived& rhs2)
{
Derived retval;
for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 * rhs2.components_[i];
}
//}}}
//{{{ operator /=
- Derived& operator/=(float rhs)
+ Derived& operator/=(float rhs) const
{
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
{
namespace math
{
- matrix2 make_identity2()
+ const matrix2& make_identity2()
{
- return matrix2();
+ static matrix2 M(1, 0, 0, 0, 1, 0);
+ return M;
}
- matrix2 make_transposed2(const matrix2& M)
+ matrix2 make_scaling2(const vector2& v)
{
return matrix2();
}
-
- matrix2 make_scaling2(const vector2& v)
+
+ matrix2 make_reverse_scaling2(const matrix2& M)
{
return matrix2();
}
return matrix2();
}
+ matrix2 make_reverse_rotation2(const matrix2& M)
+ {
+ return matrix2();
+ }
+
matrix2 make_translation2(const vector2& v)
{
return matrix2();
}
- matrix3 make_identity3()
+ matrix2 make_reverse_translation2(const matrix2& M)
{
- return matrix3();
+ return matrix2();
}
- matrix3 make_transposed3(const matrix3& M)
+ const matrix3& make_identity3()
{
- return matrix3();
+ static matrix3 M(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0);
+ return M;
}
matrix3 make_scaling3(const vector3& v)
{
return matrix3();
}
+
+ matrix3 make_reverse_scaling3(const matrix3& M)
+ {
+ return matrix3();
+ }
matrix3 make_rotation3(const vector3& v)
{
return matrix3();
}
+
+ matrix3 make_reverse_rotation3(const matrix3& M)
+ {
+ return matrix3();
+ }
matrix3 make_translation3(const vector3& v)
{
return matrix3();
+ }
+
+ matrix3 make_reverse_translation3(const matrix3& M)
+ {
+ return matrix3();
}
matrix3 make_view3(const vector3& eye, const vector3& lookat, const vector3& up)
* @brief 2次元同次変換行列の恒等行列を生成する.
* @return 生成した行列
*/
- matrix2 make_identity2();
+ const matrix2& make_identity2();
/**
- * @brief 2次元同次変換行列の転置行列を生成する.
- * @param[in] å\85\83ã\81®è¡\8cå\88\97
+ * @brief 2次元同次変換行列の拡大行列を生成する.
+ * @param[in] å\90\84軸ã\81®æ\8b¡å¤§æ\88\90å\88\86ã\82\92表ã\81\99ã\83\99ã\82¯ã\83\88ã\83«
* @return 生成した行列
*/
- matrix2 make_transposed2(const matrix2& M);
+ matrix2 make_scaling2(const vector2& v);
/**
- * @brief 2次元同次変換行列の拡大行列を生成する.
- * @param[in] 各軸の拡大成分を表すベクトル
+ * @brief 指定した拡大行列の逆の作用をもつ行列を生成する.
+ * @note 元の行列の対角要素の符号を逆にした行列を生成している.
+ * @param[in] 拡大行列
* @return 生成した行列
*/
- matrix2 make_scaling2(const vector2& v);
+ matrix2 make_reverse_scaling2(const matrix2& M);
+
/**
* @brief 2次元同次変換行列の回転行列を生成する.
matrix2 make_rotation2(const vector2& v);
/**
+ * @brief 指定した回転行列の逆の作用をもつ行列を生成する.
+ * @note 元の行列の転置行列を生成している.
+ * @param[in] 回転行列
+ * @return 生成した行列
+ */
+ matrix2 make_reverse_rotation2(const matrix2& M);
+
+ /**
* @brief 2次元同次変換行列の並進行列を生成する.
* @param[in] 各軸の並進成分を表すベクトル
* @return 生成した行列
matrix2 make_translation2(const vector2& v);
/**
- * @brief 3次元同次変換行列の恒等行列を生成する.
+ * @brief 指定した並進行列の逆の作用をもつ行列を生成する.
+ * @note 元の行列の並進要素の符号を逆にした行列を生成している.
+ * @param[in] 並進行列
* @return 生成した行列
*/
- matrix3 make_identity3();
+ matrix2 make_reverse_translation2(const matrix2& M);
/**
- * @brief 3次元同次変換行列の転置行列を生成する.
- * @param[in] 元の行列
+ * @brief 3次元同次変換行列の恒等行列を生成する.
* @return 生成した行列
*/
- matrix3 make_transposed3(const matrix3& M);
+ const matrix3& make_identity3();
/**
* @brief 3次元同次変換行列の拡大行列を生成する.
matrix3 make_scaling3(const vector3& v);
/**
+ * @brief 指定した拡大行列の逆の作用をもつ行列を生成する.
+ * @note 元の行列の対角要素の符号を逆にした行列を生成している.
+ * @param[in] 拡大行列
+ * @return 生成した行列
+ */
+ matrix3 make_reverse_scaling3(const matrix3& M);
+
+ /**
* @brief 3次元同次変換行列の回転行列を生成する.
* @param[in] 各軸の回転成分を表すベクトル
* @return 生成した行列
matrix3 make_rotation3(const vector3& v);
/**
+ * @brief 指定した回転行列の逆の作用をもつ行列を生成する.
+ * @note 元の行列の転置行列を生成している.
+ * @param[in] 回転行列
+ * @return 生成した行列
+ */
+ matrix3 make_reverse_rotation3(const matrix3& M);
+
+ /**
* @brief 3次元同次変換行列の並進行列を生成する.
* @param[in] 各軸の並進成分を表すベクトル
* @return 生成した行列
matrix3 make_translation3(const vector3& v);
/**
+ * @brief 指定した並進行列の逆の作用をもつ行列を生成する.
+ * @note 元の行列の並進要素の符号を逆にした行列を生成している.
+ * @param[in] 並進行列
+ * @return 生成した行列
+ */
+ matrix3 make_reverse_translation3(const matrix3& M);
+
+ /**
* @brief 3次元同次変換行列のカメラ行列を生成する.
* @param[in] eyeベクトル
* @param[in] lookatベクトル
class vector2;
/**
- * @brief 2次元同次座標変換行列クラス
+ * @brief 2次元アフィン同次座標変換行列クラス
*/
class matrix2 : public basic_matrix<2, matrix2, vector2>
{
*/
matrix2()
{
- for (size_t i = 0; i <= last_index() - 1; ++i) {
- elements_[i] = 0;
+ for (size_t i = 0; i <= last_index(); ++i) {
+ components_[i] = 0;
}
- elements_[last_index()] = 1;
}
/**
matrix2(const matrix2& rhs)
{
for (size_t i = 0; i <= last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
+ components_[i] = rhs.components_[i];
}
}
//}}}
matrix2& operator = (const matrix2& rhs)
{
for (size_t i = 0; i <= last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
+ components_[i] = rhs.components_[i];
}
return *this;
}
class vector3;
/**
- * @brief 3次元同次座標変換行列クラス
+ * @brief 3次元アフィン同次座標変換行列クラス
*/
class matrix3 : public basic_matrix<3, matrix3, vector3>
{
matrix3()
{
for (size_t i = 0; i <= last_index() - 1; ++i) {
- elements_[i] = 0;
+ components_[i] = 0;
}
- elements_[last_index()] = 1;
+ components_[last_index()] = 1;
}
/**
explicit matrix3(const T& arr)
{
for (size_t i = 0; i <= last_index() - 1; ++i) {
- elements_[i] = arr[i];
+ components_[i] = arr[i];
}
- elements_[last_index()] = 1;
+ components_[last_index()] = 1;
}
/**
&m41, &m42, &m43
};
for (size_t i = 0; i <= last_index() - 1; ++i) {
- elements_[i] = *table[i];
+ components_[i] = *table[i];
}
- elements_[last_index()] = 1;
+ components_[last_index()] = 1;
}
//}}}
matrix3(const matrix3& rhs)
{
for (size_t i = 0; i < last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
+ components_[i] = rhs.components_[i];
}
}
//}}}
matrix3& operator = (const matrix3& rhs)
{
for (size_t i = 0; i < last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
+ components_[i] = rhs.components_[i];
}
return *this;
}
}
{
- float arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
+ float arr[] = {1, 2, 3, 4, 5, 6};
matrix2 M(arr);
bool failed = false;
- for (size_t i = 0; i < 8; ++i) {
+ for (size_t i = 0; i < 6; ++i) {
if (M[i / 3][i % 3] != i + 1) failed = true;
}
- if (failed || M[2][2] != 1) {
+ if (failed || M[2][0] != 0 || M[2][1] != 0 || M[2][2] != 1) {
cerr << "Failed:" << " initialize by array test" << endl;
failed_count++;
}
// any operations keeps the last component 1
{
- matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
- matrix2 N(1, 2, 3, 4, 5, 6, 7, 8);
+ matrix2 M(1, 2, 3, 4, 5, 6);
+ matrix2 N(1, 2, 3, 4, 5, 6);
if (M != N) {
cerr << "Failed:" << " M == N test" << endl;
failed_count++;
}
{
- matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
- matrix2 N(0, 2, 3, 4, 5, 6, 7, 8);
+ matrix2 M(1, 2, 3, 4, 5, 6);
+ matrix2 N(0, 2, 3, 4, 5, 6);
if (M == N) {
cerr << "Failed:" << " M != N test" << endl;
failed_count++;
}
{
- matrix2 N1(1, 2, 3, 4, 5, 6, 7, 8);
- matrix2 N2(15, 13, 11, 9, 7, 5, 3, 1);
+ matrix2 N1(1, 2, 3, 4, 5, 6);
+ matrix2 N2(15, 13, 11, 9, 7, 5);
matrix2 N = N1 + N2;
- matrix2 A(16, 15, 14, 13, 12, 11, 10, 9);
+ matrix2 A(16, 15, 14, 13, 12, 11);
if (N != A) {
cerr << "Failed:" << " addition test" << endl;
failed_count++;
}
{
- matrix2 N1(1, 2, 3, 4, 5, 6, 7, 8);
- matrix2 N2(15, 13, 11, 9, 7, 5, 3, 1);
+ matrix2 N1(1, 2, 3, 4, 5, 6);
+ matrix2 N2(15, 13, 11, 9, 7, 5);
matrix2 N = N1 - N2;
- matrix2 A(-14, -11, -8, -5, -2, 1, 4, 7);
+ matrix2 A(-14, -11, -8, -5, -2, 1);
if (N != A) {
cerr << "Failed:" << " subtraction 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 N1(1, 2, 3, 4, 5, 6);
+ matrix2 N2(2, 3, 4, 5, 6, 7);
matrix2 N = N1 * N2;
- matrix2 A(12, 15, 21, 33, 42, 57, 0, 0);
+ matrix2 A(12, 15, 21, 33, 42, 57);
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 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, 0.72941f, 0.91765f);
+ 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, 7, 8);
+ matrix2 M(1, 2, 3, 4, 5, 6);
vector2 v(1, 2);
vector2 w = M * v;
vector2 a(0.33333f, 0.83333f);
{
- matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
+ matrix2 M(1, 2, 3, 4, 5, 6);
matrix2 N = 2 * M * 3;
- matrix2 A(6, 12, 18, 24, 30, 36, 42, 48);
+ matrix2 A(6, 12, 18, 24, 30, 36);
if (N != A) {
cerr << "Failed:" << "s * M * s test" << endl;
failed_count++;
}
{
- matrix2 M(3, 6, 9, 12, 15, 18, 21, 24);
+ matrix2 M(3, 6, 9, 12, 15, 18);
matrix2 N = M / 3;
- matrix2 A(1, 2, 3, 4, 5, 6, 7, 8);
+ matrix2 A(1, 2, 3, 4, 5, 6);
if (N != A) {
cerr << "Failed:" << "M / s test" << endl;
failed_count++;
}
{
- matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
bool failed = false;
- for (size_t i = 0; i < 15; ++i) {
+ for (size_t i = 0; i < 12; ++i) {
if (M[i / 4][i % 4] != i + 1) failed = true;
}
- if (failed || M[3][3] != 1) {
+ if (failed || M[3][0] != 0 || M[3][1] != 1 || M[3][2] != 2 || M[3][3] != 1) {
cerr << "Failed:" << " initialize test" << endl;
failed_count++;
}
}
{
- float arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ float arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
matrix3 M(arr);
bool failed = false;
- for (size_t i = 0; i < 15; ++i) {
+ for (size_t i = 0; i < 12; ++i) {
if (M[i / 4][i % 4] != i + 1) failed = true;
}
- if (failed || M[3][3] != 1) {
+ if (failed || M[3][0] != 0 || M[3][1] != 1 || M[3][2] != 2 || M[3][3] != 1) {
cerr << "Failed:" << " initialize by array test" << endl;
failed_count++;
}
}
- // any operations keeps the last component 1
{
- 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);
+ matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
+ matrix3 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
if (M != N) {
cerr << "Failed:" << " M == N test" << endl;
failed_count++;
}
{
- 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);
+ matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
+ matrix3 N(0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
if (M == N) {
cerr << "Failed:" << " M != N test" << endl;
failed_count++;
}
{
- matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
- matrix3 N2(29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
+ matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
+ matrix3 N2(29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7);
matrix3 N = N1 + N2;
- matrix3 A(30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16);
+ matrix3 A(30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19);
if (N != A) {
cerr << "Failed:" << " addition test" << endl;
failed_count++;
}
{
- matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
- matrix3 N2(29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
+ matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
+ matrix3 N2(29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7);
matrix3 N = N1 - N2;
matrix3 A
(
-28, -25, -22, -19,
-16, -13, -10, -7,
- -4, -1, 2, 5,
- 8, 11, 14
+ -4, -1, 2, 5
);
if (N != A) {
cerr << "Failed:" << " subtraction test" << endl;
}
{
- 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 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
+ matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
matrix3 N = N1 * N2;
- matrix3 A(44, 50, 56, 66, 116, 134, 152, 178, 188, 218, 248, 290, 0, 0, 0);
+ matrix3 A(44, 50, 56, 66, 116, 134, 152, 178, 188, 218, 248, 290);
if (N != A) {
cerr << "Failed:" << "Affine matrix N1 * N2 test" << endl;
failed_count++;
}
{
- 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);
+ 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);
{
- matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 125);
matrix3 N = 2 * M * 3;
- matrix3 A(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90);
+ matrix3 A(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72);
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 M(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72);
matrix3 N = M / 6;
- matrix3 A(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ matrix3 A(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
if (N != A) {
cerr << "Failed:" << "M / s test" << endl;
failed_count++;
failed_count++;
}
-
+ v = vector2(1, 2);
+ w = vector2(3, 4);
+ v.swap(w);
+ if (v.x != 3 || v.y != 4 || w.x != 1 || w.y != 2) {
+ cerr << "Failed:" << " swap test" << endl;
+ failed_count++;
+ }
return failed_count;
}
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) {
+ cerr << "Failed:" << " swap test" << endl;
+ failed_count++;
+ }
+
return failed_count;
}