wykobi_matrix.hpp
Go to the documentation of this file.
1 /*
2 (***********************************************************************)
3 (* *)
4 (* Wykobi Computational Geometry Library *)
5 (* Release Version 0.0.5 *)
6 (* http://www.wykobi.com *)
7 (* Copyright (c) 2005-2017 Arash Partow, All Rights Reserved. *)
8 (* *)
9 (* The Wykobi computational geometry library and its components are *)
10 (* supplied under the terms of the open source MIT License. *)
11 (* The contents of the Wykobi computational geometry library and its *)
12 (* components may not be copied or disclosed except in accordance with *)
13 (* the terms of the MIT License. *)
14 (* *)
15 (* URL: https://opensource.org/licenses/MIT *)
16 (* *)
17 (***********************************************************************)
18 */
19 
20 #ifndef INCLUDE_WYKOBI_MATRIX
21 #define INCLUDE_WYKOBI_MATRIX
22 
23 #include <cassert>
24 #include <cstdlib>
25 #include <limits>
26 #include <vector>
27 
28 #include "wykobi.hpp"
29 #include "wykobi_math.hpp"
30 
31 namespace wykobi {
32 template <typename T, std::size_t M, std::size_t N>
33 class matrix {
34  public:
35  matrix() : dptr(reinterpret_cast<T*>(&data)) { zero(); }
36 
37  ~matrix() {}
38 
39  matrix(const matrix<T, M, N>& m);
40 
41  // column major
42  const T& operator()(std::size_t x, std::size_t y) const { return data[y][x]; }
43 
44  T& operator()(std::size_t x, std::size_t y) { return data[y][x]; }
45 
46  const T& operator()(std::size_t i) const { return dptr[i]; }
47 
48  T& operator()(std::size_t i) { return dptr[i]; }
49 
50  const T& operator[](std::size_t i) const { return dptr[i]; }
51 
52  T& operator[](std::size_t i) { return dptr[i]; }
53 
55  matrix<T, M, N>& operator+=(const T& value);
56  matrix<T, M, N>& operator-=(const T& value);
57  matrix<T, M, N>& operator*=(const T& value);
58  matrix<T, M, N>& operator/=(const T& value);
61 
62  void zero();
63  void identity();
64  void swap(const unsigned int& x1, const unsigned int& y1,
65  const unsigned int& x2, const unsigned int& y2);
66 
67  std::size_t size() const { return M * N; }
68 
69  private:
70  T data[M][N];
71  T* dptr;
72 };
73 
74 template <typename T>
75 inline T det(const matrix<T, 1, 1>& matrix);
76 template <typename T>
77 inline T det(const matrix<T, 2, 2>& matrix);
78 template <typename T>
79 inline T det(const matrix<T, 3, 3>& matrix);
80 template <typename T>
81 inline T det(const matrix<T, 4, 4>& matrix);
82 
83 template <typename T>
84 inline void transpose(matrix<T, 1, 1>& matrix);
85 template <typename T>
86 inline void transpose(matrix<T, 2, 2>& matrix);
87 template <typename T>
88 inline void transpose(matrix<T, 3, 3>& matrix);
89 template <typename T>
90 inline void transpose(matrix<T, 4, 4>& matrix);
91 
92 template <typename T>
93 inline void inverse(matrix<T, 2, 2>& out_matrix,
94  const matrix<T, 2, 2>& in_matrix);
95 template <typename T>
96 inline void inverse(matrix<T, 3, 3>& out_matrix,
97  const matrix<T, 3, 3>& in_matrix);
98 template <typename T>
99 inline void inverse(matrix<T, 4, 4>& out_matrix,
100  const matrix<T, 4, 4>& in_matrix);
101 
102 template <typename T, std::size_t N>
103 inline void inverse(matrix<T, N, N>& out_matrix,
104  const matrix<T, N, N>& in_matrix);
105 
106 template <typename T>
107 inline void eigen_values(const matrix<T, 2, 2>& matrix, T& eigen_value1,
108  T& eigen_value2);
109 template <typename T>
110 inline void eigenvector(const matrix<T, 2, 2>& matrix,
111  vector2d<T>& eigenvector1, vector2d<T>& eigenvector2);
112 
113 } // namespace wykobi
114 
115 #include "wykobi_matrix.inl"
116 
117 #endif
wykobi::matrix::matrix
matrix()
Definition: wykobi_matrix.hpp:35
wykobi::matrix::operator()
T & operator()(std::size_t x, std::size_t y)
Definition: wykobi_matrix.hpp:44
wykobi::matrix::identity
void identity()
wykobi::matrix::operator-=
matrix< T, M, N > & operator-=(const T &value)
wykobi::matrix::operator[]
const T & operator[](std::size_t i) const
Definition: wykobi_matrix.hpp:50
wykobi::matrix::zero
void zero()
wykobi::matrix::operator()
T & operator()(std::size_t i)
Definition: wykobi_matrix.hpp:48
wykobi_math.hpp
wykobi::inverse
void inverse(matrix< T, 2, 2 > &out_matrix, const matrix< T, 2, 2 > &in_matrix)
wykobi::eigenvector
void eigenvector(const matrix< T, 2, 2 > &matrix, vector2d< T > &eigenvector1, vector2d< T > &eigenvector2)
wykobi::matrix::operator*=
matrix< T, M, N > & operator*=(const T &value)
wykobi::matrix::operator=
matrix< T, M, N > & operator=(const matrix< T, M, N > &m)
wykobi::matrix::operator/=
matrix< T, M, N > & operator/=(const T &value)
wykobi::matrix::size
std::size_t size() const
Definition: wykobi_matrix.hpp:67
wykobi::matrix::operator[]
T & operator[](std::size_t i)
Definition: wykobi_matrix.hpp:52
wykobi::matrix::swap
void swap(const unsigned int &x1, const unsigned int &y1, const unsigned int &x2, const unsigned int &y2)
wykobi::det
T det(const matrix< T, 1, 1 > &matrix)
wykobi.hpp
wykobi::matrix::operator()
const T & operator()(std::size_t i) const
Definition: wykobi_matrix.hpp:46
wykobi::transpose
void transpose(matrix< T, 1, 1 > &matrix)
wykobi::matrix::~matrix
~matrix()
Definition: wykobi_matrix.hpp:37
wykobi::matrix::operator()
const T & operator()(std::size_t x, std::size_t y) const
Definition: wykobi_matrix.hpp:42
wykobi::eigen_values
void eigen_values(const matrix< T, 2, 2 > &matrix, T &eigen_value1, T &eigen_value2)
wykobi
Definition: wykobi.hpp:32
wykobi::matrix::operator+=
matrix< T, M, N > & operator+=(const T &value)
wykobi::matrix
Definition: wykobi_matrix.hpp:33