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/vec3.h"
33 :
34 : #include "gals/utilities/utilities.h"
35 :
36 : template <typename T>
37 1077673 : GALS::CPU::Vec3<T>::Vec3(const T a, const T b, const T c)
38 : {
39 1077673 : m_data[0] = a;
40 1077673 : m_data[1] = b;
41 1077673 : m_data[2] = c;
42 1077673 : }
43 :
44 : template <typename T>
45 5 : GALS::CPU::Vec3<T>::Vec3(const std::vector<T> a)
46 : {
47 10 : if (a.size() != 3) GALS_ABORT("While constructing Vec3 object using std::vector, input must be of size 3.");
48 :
49 5 : m_data[0] = a[0];
50 5 : m_data[1] = a[1];
51 5 : m_data[2] = a[2];
52 5 : }
53 :
54 : template <typename T>
55 998893 : GALS::CPU::Vec3<T>::Vec3() : Vec3(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0))
56 : {
57 998893 : }
58 :
59 : template <typename T>
60 2449532 : GALS::CPU::Vec3<T>::~Vec3()
61 : {
62 2449532 : }
63 :
64 : template <typename T>
65 2 : const int GALS::CPU::Vec3<T>::size() const
66 : {
67 2 : return SIZE;
68 : }
69 :
70 : template <typename T>
71 102 : const double GALS::CPU::Vec3<T>::mag() const
72 : {
73 103 : return sqrt(m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]);
74 : }
75 :
76 : template <typename T>
77 2 : const T GALS::CPU::Vec3<T>::min() const
78 : {
79 2 : if (m_data[0] < m_data[1] && m_data[0] < m_data[2]) return m_data[0];
80 0 : if (m_data[1] < m_data[0] && m_data[1] < m_data[2]) return m_data[1];
81 0 : return m_data[2];
82 : }
83 :
84 : template <typename T>
85 7223507 : const T GALS::CPU::Vec3<T>::operator[](const int idx) const
86 : {
87 7223507 : return m_data[idx];
88 : }
89 :
90 : template <typename T>
91 3962624 : T& GALS::CPU::Vec3<T>::operator[](const int idx)
92 : {
93 3962624 : return m_data[idx];
94 : }
95 :
96 : template <typename T>
97 586040 : void GALS::CPU::Vec3<T>::operator=(const Vec3<T>& vec)
98 : {
99 2344160 : for (int i = 0; i < SIZE; ++i) m_data[i] = vec[i];
100 586040 : }
101 :
102 : template <typename T>
103 5 : bool GALS::CPU::Vec3<T>::operator==(const Vec3<T>& vec) const
104 : {
105 8 : return (GALS::is_equal(m_data[0], vec[0]) && GALS::is_equal(m_data[1], vec[1]) && GALS::is_equal(m_data[2], vec[2]));
106 : }
107 :
108 : template <typename T>
109 6910 : const GALS::CPU::Vec3<T> GALS::CPU::Vec3<T>::operator-(const Vec3<T>& vec) const
110 : {
111 6910 : return Vec3<T>(m_data[0] - vec[0], m_data[1] - vec[1], m_data[2] - vec[2]);
112 : }
113 :
114 : template <typename T>
115 5700 : const GALS::CPU::Vec3<T> GALS::CPU::Vec3<T>::operator*(const Vec3<T>& vec) const
116 : {
117 5700 : return Vec3<T>(m_data[0] * vec[0], m_data[1] * vec[1], m_data[2] * vec[2]);
118 : }
119 :
120 : template <typename T>
121 1112 : const GALS::CPU::Vec3<T> GALS::CPU::Vec3<T>::operator*(const T var) const
122 : {
123 1112 : return Vec3<T>(m_data[0] * var, m_data[1] * var, m_data[2] * var);
124 : }
125 :
126 : template <typename T>
127 2 : const GALS::CPU::Vec3<T> GALS::CPU::Vec3<T>::operator/(const Vec3<T>& vec) const
128 : {
129 2 : return Vec3<T>(m_data[0] / vec[0], m_data[1] / vec[1], m_data[2] / vec[2]);
130 : }
131 :
132 : template class GALS::CPU::Vec3<int>;
133 2 : template class GALS::CPU::Vec3<double>;
|