Line data Source code
1 : ///////////////////////////////////////////////////////////////////////////////
2 : // Copyright 2019 Lakshman Anumolu, Raunak Bardia.
3 : //
4 : // Redistribution and use in source and binary forms, with or without
5 : // modification, are permitted provided that the following conditions are
6 : // met:
7 : //
8 : // 1. Redistributions of source code must retain the above copyright notice,
9 : // this list of conditions and the following disclaimer.
10 : //
11 : // 2. Redistributions in binary form must reproduce the above copyright notice,
12 : // this list of conditions and the following disclaimer in the documentation
13 : // and/or other materials provided with the distribution.
14 : //
15 : // 3. Neither the name of the copyright holder nor the names of its contributors
16 : // may be used to endorse or promote products derived from this software without
17 : // specific prior written permission.
18 : //
19 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 : // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 : ///////////////////////////////////////////////////////////////////////////////
31 :
32 : #include "gals/utilities/mat3.h"
33 :
34 : #include "gals/utilities/utilities.h"
35 :
36 : template <typename T>
37 20076 : GALS::CPU::Mat3<T>::Mat3(T a00, T a01, T a02, T a10, T a11, T a12, T a20, T a21, T a22)
38 : {
39 20076 : m_data[0] = a00;
40 20076 : m_data[1] = a01;
41 20076 : m_data[2] = a02;
42 20076 : m_data[3] = a10;
43 20076 : m_data[4] = a11;
44 20076 : m_data[5] = a12;
45 20076 : m_data[6] = a20;
46 20076 : m_data[7] = a21;
47 20076 : m_data[8] = a22;
48 20076 : }
49 :
50 : template <typename T>
51 20066 : GALS::CPU::Mat3<T>::Mat3()
52 : : Mat3(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0),
53 20066 : static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0))
54 : {
55 20066 : }
56 :
57 : template <typename T>
58 20076 : GALS::CPU::Mat3<T>::~Mat3()
59 : {
60 20076 : }
61 :
62 : template <typename T>
63 22 : const int GALS::CPU::Mat3<T>::size() const
64 : {
65 22 : return SIZE;
66 : }
67 :
68 : template <typename T>
69 1110 : const GALS::CPU::Vec3<T> GALS::CPU::Mat3<T>::dot(GALS::CPU::Vec3<T> vec) const
70 : {
71 1110 : GALS::CPU::Vec3<T> res;
72 :
73 7770 : for (int i = 0; i < 3; ++i)
74 13320 : for (int j = 0; j < 3; ++j) res[i] += m_data[j * 3 + i] * vec[j];
75 :
76 1110 : return res;
77 : }
78 :
79 : template <typename T>
80 100341 : const T GALS::CPU::Mat3<T>::operator[](const int idx) const
81 : {
82 100341 : return m_data[idx];
83 : }
84 :
85 : template <typename T>
86 22702 : T& GALS::CPU::Mat3<T>::operator[](const int idx)
87 : {
88 22702 : return m_data[idx];
89 : }
90 :
91 : template <typename T>
92 252259 : const T GALS::CPU::Mat3<T>::operator()(const int i_row, const int i_col) const
93 : {
94 252259 : return m_data[i_row * 3 + i_col];
95 : }
96 :
97 : template <typename T>
98 18918 : T& GALS::CPU::Mat3<T>::operator()(const int i_row, const int i_col)
99 : {
100 18918 : return m_data[i_row * 3 + i_col];
101 : }
102 :
103 : template <typename T>
104 10030 : void GALS::CPU::Mat3<T>::operator=(const Mat3<T>& mat)
105 : {
106 100300 : for (int i = 0; i < SIZE; ++i) m_data[i] = mat[i];
107 10030 : }
108 :
109 : template <typename T>
110 1112 : const GALS::CPU::Mat3<T> GALS::CPU::Mat3<T>::operator-(const Mat3<T>& mat) const
111 : {
112 1112 : Mat3<T> res;
113 11120 : for (int i = 0; i < SIZE; ++i) res[i] = m_data[i] - mat[i];
114 :
115 1112 : return res;
116 : }
117 :
118 : template <typename T>
119 1114 : const GALS::CPU::Mat3<T> GALS::CPU::Mat3<T>::operator*(const T var) const
120 : {
121 1114 : Mat3<T> res;
122 11140 : for (int i = 0; i < SIZE; ++i) res[i] = m_data[i] * var;
123 :
124 1114 : return res;
125 : }
126 :
127 : template <typename T>
128 3 : bool GALS::CPU::Mat3<T>::operator==(const Mat3<T>& mat) const
129 : {
130 11 : return (GALS::is_equal(m_data[0], mat[0]) && GALS::is_equal(m_data[1], mat[1]) && GALS::is_equal(m_data[2], mat[2]) &&
131 11 : GALS::is_equal(m_data[3], mat[3]) && GALS::is_equal(m_data[4], mat[4]) && GALS::is_equal(m_data[5], mat[5]) &&
132 11 : GALS::is_equal(m_data[6], mat[6]) && GALS::is_equal(m_data[7], mat[7]) && GALS::is_equal(m_data[8], mat[8]));
133 : }
134 :
135 : template class GALS::CPU::Mat3<int>;
136 2 : template class GALS::CPU::Mat3<double>;
|