PeriDyno 1.0.0
Loading...
Searching...
No Matches
Vector4D.inl
Go to the documentation of this file.
1#include <limits>
2#include <glm/gtx/norm.hpp>
3
4namespace dyno
5{
6 template <typename T>
8 :Vector(0) //delegating ctor
9 {
10 }
11
12 template <typename T>
14 : Vector(x, x, x, x) //delegating ctor
15 {
16 }
17
18 template <typename T>
19 DYN_FUNC Vector<T, 4>::Vector(T x, T y, T z, T w)
20 : data_(x, y, z, w)
21 {
22 }
23
24 template <typename T>
27 {
28
29 }
30
31 template <typename T>
33 {
34
35 }
36
37 template <typename T>
38 DYN_FUNC T& Vector<T, 4>::operator[] (unsigned int idx)
39 {
40 return const_cast<T &> (static_cast<const Vector<T, 4> &>(*this)[idx]);
41 }
42
43 template <typename T>
44 DYN_FUNC const T& Vector<T, 4>::operator[] (unsigned int idx) const
45 {
46 // #ifndef __CUDA_ARCH__
47 // if(idx>=4)
48 // throw PhysikaException("Vector index out of range!");
49 // #endif
50 return data_[idx];
51 }
52
53 template <typename T>
55 {
56 return Vector<T, 4>(*this) += vec2;
57 }
58
59 template <typename T>
61 {
62 data_ += vec2.data_;
63 return *this;
64 }
65
66 template <typename T>
68 {
69 return Vector<T, 4>(*this) -= vec2;
70 }
71
72 template <typename T>
74 {
75 data_ -= vec2.data_;
76 return *this;
77 }
78
79 template <typename T>
81 {
82 return Vector<T, 4>(data_[0] * vec2.data_[0], data_[1] * vec2.data_[1], data_[2] * vec2.data_[2], data_[3] * vec2.data_[3]);
83 }
84
85 template <typename T>
87 {
88 data_[0] *= vec2.data_[0]; data_[1] *= vec2.data_[1]; data_[2] *= vec2.data_[2]; data_[3] *= vec2.data_[3];
89 return *this;
90 }
91
92 template <typename T>
94 {
95 return Vector<T, 4>(data_[0] / vec2[0], data_[1] / vec2[1], data_[2] / vec2[2], data_[3] / vec2[3]);
96 }
97
98 template <typename T>
100 {
101 data_[0] /= vec2.data_[0]; data_[1] /= vec2.data_[1]; data_[2] /= vec2.data_[2]; data_[3] /= vec2.data_[3];
102 return *this;
103 }
104
105 template <typename T>
107 {
108 data_ = vec2.data_;
109 return *this;
110 }
111
112 template <typename T>
113 DYN_FUNC bool Vector<T, 4>::operator== (const Vector<T, 4> &vec2) const
114 {
115 return data_ == vec2.data_;
116 }
117
118 template <typename T>
119 DYN_FUNC bool Vector<T, 4>::operator!= (const Vector<T, 4> &vec2) const
120 {
121 return !((*this) == vec2);
122 }
123
124 template <typename T>
125 DYN_FUNC const Vector<T, 4> Vector<T, 4>::operator+(T value) const
126 {
127 return Vector<T, 4>(*this) += value;
128 }
129
130 template <typename T>
132 {
133 data_ += value;
134 return *this;
135 }
136
137 template <typename T>
138 DYN_FUNC const Vector<T, 4> Vector<T, 4>::operator-(T value) const
139 {
140 return Vector<T, 4>(*this) -= value;
141 }
142
143 template <typename T>
145 {
146 data_ -= value;
147 return *this;
148 }
149
150 template <typename T>
151 DYN_FUNC const Vector<T, 4> Vector<T, 4>::operator* (T scale) const
152 {
153 return Vector<T, 4>(*this) *= scale;
154 }
155
156 template <typename T>
158 {
159 data_ *= scale;
160 return *this;
161 }
162
163 template <typename T>
164 DYN_FUNC const Vector<T, 4> Vector<T, 4>::operator/ (T scale) const
165 {
166 return Vector<T, 4>(*this) /= scale;
167 }
168
169 template <typename T>
171 {
172 data_ /= scale;
173 return *this;
174 }
175
176 template <typename T>
177 DYN_FUNC const Vector<T, 4> Vector<T, 4>::operator-(void) const
178 {
179 Vector<T, 4> res;
180 res.data_ = -data_;
181 return res;
182 }
183
184 template <typename T>
185 DYN_FUNC T Vector<T, 4>::norm() const
186 {
187 return glm::length(data_);
188 }
189
190 template <typename T>
192 {
193 return glm::length2(data_);
194 }
195
196 template <typename T>
198 {
199 data_ = glm::length(data_) > glm::epsilon<T>() ? glm::normalize(data_) : glm::tvec4<T>(0, 0, 0, 0);
200 return *this;
201 }
202
203 template <typename T>
204 DYN_FUNC T Vector<T, 4>::dot(const Vector<T, 4>& vec2) const
205 {
206 return glm::dot(data_, vec2.data_);
207 }
208
209 template <typename T>
211 {
212 Vector<T, 4> res;
213 res[0] = data_[0] < vec2[0] ? data_[0] : vec2[0];
214 res[1] = data_[1] < vec2[1] ? data_[1] : vec2[1];
215 res[2] = data_[2] < vec2[2] ? data_[2] : vec2[2];
216 res[3] = data_[3] < vec2[3] ? data_[3] : vec2[3];
217 return res;
218 }
219
220 template <typename T>
222 {
223 Vector<T, 4> res;
224 res[0] = data_[0] > vec2[0] ? data_[0] : vec2[0];
225 res[1] = data_[1] > vec2[1] ? data_[1] : vec2[1];
226 res[2] = data_[2] > vec2[2] ? data_[2] : vec2[2];
227 res[3] = data_[3] > vec2[3] ? data_[3] : vec2[3];
228 return res;
229 }
230
231 template <typename S, typename T>
232 DYN_FUNC const Vector<T, 4> operator *(S scale, const Vector<T, 4> &vec)
233 {
234 return vec * (T)scale;
235 }
236}
DYN_FUNC Vector()
Definition Vector4D.inl:7
glm::tvec4< T > data_
Definition Vector4D.h:77
DYN_FUNC ~Vector()
Definition VectorBase.h:27
DYN_FUNC Vector()
Definition VectorBase.h:26
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC const Complex< T > operator*(S scale, const Complex< T > &complex)
Definition Complex.inl:247
vgm::Vec2 vec2
Definition vgMath.h:630