openMSX
gl_vec.hh
Go to the documentation of this file.
1#ifndef GL_VEC_HH
2#define GL_VEC_HH
3
4// This code implements a mathematical vector, comparable in functionality
5// and syntax to the vector types in GLSL.
6//
7// Only vector sizes 2, 3 and 4 are supported. Though when it doesn't
8// complicate stuff the code was written to support any size.
9//
10// Most basic functionality is already there, but this is not meant to be a
11// full set of GLSL functions. We can always extend the functionality if/when
12// required.
13//
14// In the past we had (some) manual SSE optimizations in this code. Though for
15// the functions that matter (matrix-vector and matrix-matrix multiplication are
16// built on top of the functions in this file), the compiler's
17// auto-vectorization has become as good as the manually vectorized code.
18
19#include "Math.hh"
20#include "narrow.hh"
21#include "unreachable.hh"
22#include "xrange.hh"
23#include <algorithm>
24#include <array>
25#include <cmath>
26#include <iostream>
27#include <utility>
28
29namespace gl {
30
31// Vector with N components of type T.
32template<int N, typename T> class vecN;
33
34// Specialization for N=2.
35template<typename T> class vecN<2, T>
36{
37public:
38 // Default copy-constructor and assignment operator.
39
40 // Construct vector containing all zeros.
41 constexpr vecN() : x(T(0)), y(T(0)) {}
42
43 // Construct vector containing the same value repeated N times.
44 constexpr explicit vecN(T t) : x(t), y(t) {}
45
46 // Conversion constructor from vector of same size but different type.
47 template<typename T2>
48 constexpr explicit vecN(const vecN<2, T2>& v) : x(T(v.x)), y(T(v.y)) {}
49
50 // Construct from larger vector (higher order elements are dropped).
51 template<int N2> constexpr explicit vecN(const vecN<N2, T>& v) : x(v.x), y(v.y) {}
52
53 // Construct vector from 2 given values.
54 constexpr vecN(T a, T b) : x(a), y(b) {}
55
56 // Access the i-th element of this vector.
57 [[nodiscard]] constexpr T operator[](unsigned i) const {
58 if (i == 0) return x;
59 if (i == 1) return y;
61 }
62 [[nodiscard]] constexpr T& operator[](unsigned i) {
63 if (i == 0) return x;
64 if (i == 1) return y;
66 }
67
68 [[nodiscard]] constexpr const T* data() const { return &x; }
69 [[nodiscard]] constexpr T* data() { return &x; }
70
71 // For structured bindings
72 template<size_t I> [[nodiscard]] constexpr T get() const noexcept { return (*this)[I]; }
73 template<size_t I> [[nodiscard]] constexpr T& get() noexcept { return (*this)[I]; }
74
75 // Assignment version of the +,-,* operations defined below.
76 constexpr vecN& operator+=(const vecN& v) { *this = *this + v; return *this; }
77 constexpr vecN& operator-=(const vecN& v) { *this = *this - v; return *this; }
78 constexpr vecN& operator*=(const vecN& v) { *this = *this * v; return *this; }
79 constexpr vecN& operator*=(T t) { *this = *this * t; return *this; }
80
81 [[nodiscard]] constexpr bool operator==(const vecN&) const = default;
82
83 // vector + vector
84 [[nodiscard]] constexpr friend vecN operator+(const vecN& v1, const vecN& v2) {
85 vecN r;
86 for (auto i : xrange(2)) r[i] = v1[i] + v2[i];
87 return r;
88 }
89
90 // vector - vector
91 [[nodiscard]] constexpr friend vecN operator-(const vecN& v1, const vecN& v2) {
92 vecN r;
93 for (auto i : xrange(2)) r[i] = v1[i] - v2[i];
94 return r;
95 }
96
97 // scalar * vector
98 [[nodiscard]] constexpr friend vecN operator*(T a, const vecN& v) {
99 vecN r;
100 for (auto i : xrange(2)) r[i] = a * v[i];
101 return r;
102 }
103
104 // vector * scalar
105 [[nodiscard]] constexpr friend vecN operator*(const vecN& v, T a) {
106 vecN r;
107 for (auto i : xrange(2)) r[i] = v[i] * a;
108 return r;
109 }
110
111 // vector * vector
112 [[nodiscard]] constexpr friend vecN operator*(const vecN& v1, const vecN& v2)
113 {
114 vecN r;
115 for (auto i : xrange(2)) r[i] = v1[i] * v2[i];
116 return r;
117 }
118
119 // element-wise reciprocal
120 [[nodiscard]] constexpr friend vecN recip(const vecN& v) {
121 vecN r;
122 for (auto i : xrange(2)) r[i] = T(1) / v[i];
123 return r;
124 }
125
126 // scalar / vector
127 [[nodiscard]] constexpr friend vecN operator/(T a, const vecN& v) {
128 return a * recip(v);
129 }
130
131 // vector / scalar
132 [[nodiscard]] constexpr friend vecN operator/(const vecN& v, T a) {
133 return v * (T(1) / a);
134 }
135
136 // vector / vector
137 [[nodiscard]] constexpr friend vecN operator/(const vecN& v1, const vecN& v2) {
138 return v1 * recip(v2);
139 }
140
141 // Textual representation. (Only) used to debug unittest.
142 friend std::ostream& operator<<(std::ostream& os, const vecN& v) {
143 os << "[ ";
144 for (auto i : xrange(2)) {
145 os << v[i] << ' ';
146 }
147 os << ']';
148 return os;
149 }
150
151public:
152 T x, y;
153};
154
155// Specialization for N=3.
156template<typename T> class vecN<3, T>
157{
158public:
159 constexpr vecN() : x(T(0)), y(T(0)), z(T(0)) {}
160 constexpr explicit vecN(T t) : x(t), y(t), z(t) {}
161 template<typename T2>
162 constexpr explicit vecN(const vecN<3, T2>& v) : x(T(v.x)), y(T(v.y)), z(T(v.z)) {}
163 constexpr explicit vecN(const vecN<4, T>& v) : x(v.x), y(v.y), z(v.z) {}
164 constexpr vecN(T a, T b, T c) : x(a), y(b), z(c) {}
165 constexpr vecN(T a, const vecN<2, T>& b) : x(a), y(b.x), z(b.y) {}
166 constexpr vecN(const vecN<2, T>& a, T b) : x(a.x), y(a.y), z(b) {}
167
168 [[nodiscard]] constexpr T operator[](unsigned i) const {
169 if (i == 0) return x;
170 if (i == 1) return y;
171 if (i == 2) return z;
173 }
174 [[nodiscard]] constexpr T& operator[](unsigned i) {
175 if (i == 0) return x;
176 if (i == 1) return y;
177 if (i == 2) return z;
179 }
180
181 [[nodiscard]] constexpr const T* data() const { return &x; }
182 [[nodiscard]] constexpr T* data() { return &x; }
183
184 template<size_t I> [[nodiscard]] constexpr T get() const noexcept { return (*this)[I]; }
185 template<size_t I> [[nodiscard]] constexpr T& get() noexcept { return (*this)[I]; }
186
187 constexpr vecN& operator+=(const vecN& v) { *this = *this + v; return *this; }
188 constexpr vecN& operator-=(const vecN& v) { *this = *this - v; return *this; }
189 constexpr vecN& operator*=(const vecN& v) { *this = *this * v; return *this; }
190 constexpr vecN& operator*=(T t) { *this = *this * t; return *this; }
191
192 [[nodiscard]] constexpr bool operator==(const vecN&) const = default;
193
194 // vector + vector
195 [[nodiscard]] constexpr friend vecN operator+(const vecN& v1, const vecN& v2) {
196 vecN r;
197 for (auto i : xrange(3)) r[i] = v1[i] + v2[i];
198 return r;
199 }
200
201 // vector - vector
202 [[nodiscard]] constexpr friend vecN operator-(const vecN& v1, const vecN& v2) {
203 vecN r;
204 for (auto i : xrange(3)) r[i] = v1[i] - v2[i];
205 return r;
206 }
207
208 // scalar * vector
209 [[nodiscard]] constexpr friend vecN operator*(T a, const vecN& v) {
210 vecN r;
211 for (auto i : xrange(3)) r[i] = a * v[i];
212 return r;
213 }
214
215 // vector * scalar
216 [[nodiscard]] constexpr friend vecN operator*(const vecN& v, T a) {
217 vecN r;
218 for (auto i : xrange(3)) r[i] = v[i] * a;
219 return r;
220 }
221
222 // vector * vector
223 [[nodiscard]] constexpr friend vecN operator*(const vecN& v1, const vecN& v2)
224 {
225 vecN r;
226 for (auto i : xrange(3)) r[i] = v1[i] * v2[i];
227 return r;
228 }
229
230 // element-wise reciprocal
231 [[nodiscard]] constexpr friend vecN recip(const vecN& v) {
232 vecN r;
233 for (auto i : xrange(3)) r[i] = T(1) / v[i];
234 return r;
235 }
236
237 // scalar / vector
238 [[nodiscard]] constexpr friend vecN operator/(T a, const vecN& v) {
239 return a * recip(v);
240 }
241
242 // vector / scalar
243 [[nodiscard]] constexpr friend vecN operator/(const vecN& v, T a) {
244 return v * (T(1) / a);
245 }
246
247 // vector / vector
248 [[nodiscard]] constexpr friend vecN operator/(const vecN& v1, const vecN& v2) {
249 return v1 * recip(v2);
250 }
251
252 // Textual representation. (Only) used to debug unittest.
253 friend std::ostream& operator<<(std::ostream& os, const vecN& v) {
254 os << "[ ";
255 for (auto i : xrange(3)) {
256 os << v[i] << ' ';
257 }
258 os << ']';
259 return os;
260 }
261
262public:
263 T x, y, z;
264};
265
266// Specialization for N=4.
267template<typename T> class vecN<4, T>
268{
269public:
270 constexpr vecN() : x(T(0)), y(T(0)), z(T(0)), w(T(0)) {}
271 constexpr explicit vecN(T t) : x(t), y(t), z(t), w(t) {}
272 template<typename T2>
273 constexpr explicit vecN(const vecN<4, T2>& v) : x(T(v.x)), y(T(v.y)), z(T(v.z)), w(T(v.w)) {}
274 constexpr vecN(T a, T b, T c, T d) : x(a), y(b), z(c), w(d) {}
275 constexpr vecN(T a, const vecN<3, T>& b) : x(a), y(b.x), z(b.y), w(b.z) {}
276 constexpr vecN(const vecN<3, T>& a, T b) : x(a.x), y(a.y), z(a.z), w(b) {}
277 constexpr vecN(const vecN<2, T>& a, const vecN<2, T>& b) : x(a.x), y(a.y), z(b.x), w(b.y) {}
278
279 [[nodiscard]] constexpr T operator[](unsigned i) const {
280 if (i == 0) return x;
281 if (i == 1) return y;
282 if (i == 2) return z;
283 if (i == 3) return w;
285 }
286 [[nodiscard]] constexpr T& operator[](unsigned i) {
287 if (i == 0) return x;
288 if (i == 1) return y;
289 if (i == 2) return z;
290 if (i == 3) return w;
292 }
293
294 [[nodiscard]] constexpr const T* data() const { return &x; }
295 [[nodiscard]] constexpr T* data() { return &x; }
296
297 template<size_t I> [[nodiscard]] constexpr T get() const noexcept { return (*this)[I]; }
298 template<size_t I> [[nodiscard]] constexpr T& get() noexcept { return (*this)[I]; }
299
300 // Assignment version of the +,-,* operations defined below.
301 constexpr vecN& operator+=(const vecN& v) { *this = *this + v; return *this; }
302 constexpr vecN& operator-=(const vecN& v) { *this = *this - v; return *this; }
303 constexpr vecN& operator*=(const vecN& v) { *this = *this * v; return *this; }
304 constexpr vecN& operator*=(T t) { *this = *this * t; return *this; }
305
306 [[nodiscard]] constexpr bool operator==(const vecN&) const = default;
307
308 // vector + vector
309 [[nodiscard]] constexpr friend vecN operator+(const vecN& v1, const vecN& v2) {
310 vecN r;
311 for (auto i : xrange(4)) r[i] = v1[i] + v2[i];
312 return r;
313 }
314
315 // vector - vector
316 [[nodiscard]] constexpr friend vecN operator-(const vecN& v1, const vecN& v2) {
317 vecN r;
318 for (auto i : xrange(4)) r[i] = v1[i] - v2[i];
319 return r;
320 }
321
322 // scalar * vector
323 [[nodiscard]] constexpr friend vecN operator*(T a, const vecN& v) {
324 vecN r;
325 for (auto i : xrange(4)) r[i] = a * v[i];
326 return r;
327 }
328
329 // vector * scalar
330 [[nodiscard]] constexpr friend vecN operator*(const vecN& v, T a) {
331 vecN r;
332 for (auto i : xrange(4)) r[i] = v[i] * a;
333 return r;
334 }
335
336 // vector * vector
337 [[nodiscard]] constexpr friend vecN operator*(const vecN& v1, const vecN& v2)
338 {
339 vecN r;
340 for (auto i : xrange(4)) r[i] = v1[i] * v2[i];
341 return r;
342 }
343
344 // element-wise reciprocal
345 [[nodiscard]] constexpr friend vecN recip(const vecN& v) {
346 vecN r;
347 for (auto i : xrange(4)) r[i] = T(1) / v[i];
348 return r;
349 }
350
351 // scalar / vector
352 [[nodiscard]] constexpr friend vecN operator/(T a, const vecN& v) {
353 return a * recip(v);
354 }
355
356 // vector / scalar
357 [[nodiscard]] constexpr friend vecN operator/(const vecN& v, T a) {
358 return v * (T(1) / a);
359 }
360
361 // vector / vector
362 [[nodiscard]] constexpr friend vecN operator/(const vecN& v1, const vecN& v2) {
363 return v1 * recip(v2);
364 }
365
366 // Textual representation. (Only) used to debug unittest.
367 friend std::ostream& operator<<(std::ostream& os, const vecN& v) {
368 os << "[ ";
369 for (auto i : xrange(4)) {
370 os << v[i] << ' ';
371 }
372 os << ']';
373 return os;
374 }
375
376public:
377 T x, y, z, w;
378};
379
380
381// Convenience typedefs (same names as used by GLSL).
388
389static_assert(sizeof( vec2) == 2 * sizeof(float));
390static_assert(sizeof( vec3) == 3 * sizeof(float));
391static_assert(sizeof( vec4) == 4 * sizeof(float));
392static_assert(sizeof(ivec2) == 2 * sizeof(int));
393static_assert(sizeof(ivec3) == 3 * sizeof(int));
394static_assert(sizeof(ivec4) == 4 * sizeof(int));
395
396
397// -- Scalar functions --
398
399// reciprocal square root
400[[nodiscard]] inline float rsqrt(float x)
401{
402 return 1.0f / sqrtf(x);
403}
404[[nodiscard]] inline double rsqrt(double x)
405{
406 return 1.0 / sqrt(x);
407}
408
409// convert radians <-> degrees
410template<typename T> [[nodiscard]] constexpr T radians(T d)
411{
412 return d * T(Math::pi / 180.0);
413}
414template<typename T> [[nodiscard]] constexpr T degrees(T r)
415{
416 return r * T(180.0 / Math::pi);
417}
418
419
420// -- Vector functions --
421
422// vector negation
423template<int N, typename T>
424[[nodiscard]] constexpr vecN<N, T> operator-(const vecN<N, T>& x)
425{
426 return vecN<N, T>() - x;
427}
428
429// min(vector, vector)
430template<int N, typename T>
431[[nodiscard]] constexpr vecN<N, T> min(const vecN<N, T>& x, const vecN<N, T>& y)
432{
433 vecN<N, T> r;
434 for (auto i : xrange(N)) r[i] = std::min(x[i], y[i]);
435 return r;
436}
437
438// min(vector, vector)
439template<int N, typename T>
440[[nodiscard]] constexpr T min_component(const vecN<N, T>& x)
441{
442 T r = x[0];
443 for (auto i : xrange(1, N)) r = std::min(r, x[i]);
444 return r;
445}
446
447// max(vector, vector)
448template<int N, typename T>
449[[nodiscard]] constexpr vecN<N, T> max(const vecN<N, T>& x, const vecN<N, T>& y)
450{
451 vecN<N, T> r;
452 for (auto i : xrange(N)) r[i] = std::max(x[i], y[i]);
453 return r;
454}
455
456// clamp(vector, vector, vector)
457template<int N, typename T>
458[[nodiscard]] constexpr vecN<N, T> clamp(const vecN<N, T>& x, const vecN<N, T>& minVal, const vecN<N, T>& maxVal)
459{
460 return min(maxVal, max(minVal, x));
461}
462
463// clamp(vector, scalar, scalar)
464template<int N, typename T>
465[[nodiscard]] constexpr vecN<N, T> clamp(const vecN<N, T>& x, T minVal, T maxVal)
466{
467 return clamp(x, vecN<N, T>(minVal), vecN<N, T>(maxVal));
468}
469
470// sum of components
471template<int N, typename T>
472[[nodiscard]] constexpr T sum(const vecN<N, T>& x)
473{
474 T result(0);
475 for (auto i : xrange(N)) result += x[i];
476 return result;
477}
478template<int N, typename T>
479[[nodiscard]] constexpr vecN<N, T> sum_broadcast(const vecN<N, T>& x)
480{
481 return vecN<N, T>(sum(x));
482}
483
484// dot product
485template<int N, typename T>
486[[nodiscard]] constexpr T dot(const vecN<N, T>& x, const vecN<N, T>& y)
487{
488 return sum(x * y);
489}
490template<int N, typename T>
491[[nodiscard]] constexpr vecN<N, T> dot_broadcast(const vecN<N, T>& x, const vecN<N, T>& y)
492{
493 return sum_broadcast(x * y);
494}
495
496// squared length (norm-2)
497template<int N, typename T>
498[[nodiscard]] constexpr T length2(const vecN<N, T>& x)
499{
500 return dot(x, x);
501}
502
503// length (norm-2)
504template<int N, typename T>
505[[nodiscard]] inline T length(const vecN<N, T>& x)
506{
507 return std::sqrt(length2(x));
508}
509
510// normalize vector
511template<int N, typename T>
512[[nodiscard]] inline vecN<N, T> normalize(const vecN<N, T>& x)
513{
514 return x * rsqrt(length2(x));
515}
516
517// cross product (only defined for vectors of length 3)
518template<typename T>
519[[nodiscard]] constexpr vecN<3, T> cross(const vecN<3, T>& a, const vecN<3, T>& b)
520{
521 return vecN<3, T>(a.y * b.z - a.z * b.y,
522 a.z * b.x - a.x * b.z,
523 a.x * b.y - a.y * b.x);
524}
525
526// round each component to the nearest integer (returns a vector of integers)
527template<int N, typename T>
528[[nodiscard]] inline vecN<N, int> round(const vecN<N, T>& x)
529{
530 vecN<N, int> r;
531 // note: std::lrint() is more generic (e.g. also works with double),
532 // but Dingux doesn't seem to have std::lrint().
533 for (auto i : xrange(N)) r[i] = narrow_cast<int>(lrintf(narrow_cast<float>(x[i])));
534 return r;
535}
536
537// truncate each component to the nearest integer that is not bigger in
538// absolute value (returns a vector of integers)
539template<int N, typename T>
540[[nodiscard]] constexpr vecN<N, int> trunc(const vecN<N, T>& x)
541{
542 vecN<N, int> r;
543 for (auto i : xrange(N)) r[i] = int(x[i]);
544 return r;
545}
546
547} // namespace gl
548
549// Support for structured bindings
550namespace std {
551// On some platforms tuple_size is a class and on others it is a struct.
552// Such a mismatch is only a problem when targeting the Microsoft C++ ABI,
553// which we don't do when compiling with Clang.
554#if defined(__clang__)
555#pragma clang diagnostic push
556#pragma clang diagnostic ignored "-Wmismatched-tags"
557#endif
558 template<int N, typename T> class tuple_size<gl::vecN<N, T>>
559 : public std::integral_constant<size_t, N> {};
560#if defined(__clang__)
561#pragma clang diagnostic pop
562#endif
563 template<size_t I, int N, typename T> class tuple_element<I, gl::vecN<N, T>> {
564 public:
565 using type = T;
566 };
567}
568
569#endif // GL_VEC_HH
TclObject t
constexpr friend vecN operator*(const vecN &v, T a)
Definition gl_vec.hh:105
constexpr T & get() noexcept
Definition gl_vec.hh:73
constexpr vecN & operator+=(const vecN &v)
Definition gl_vec.hh:76
constexpr bool operator==(const vecN &) const =default
constexpr T operator[](unsigned i) const
Definition gl_vec.hh:57
constexpr friend vecN operator/(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:137
constexpr vecN(const vecN< 2, T2 > &v)
Definition gl_vec.hh:48
constexpr friend vecN operator*(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:112
constexpr T & operator[](unsigned i)
Definition gl_vec.hh:62
constexpr friend vecN operator+(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:84
constexpr vecN(T a, T b)
Definition gl_vec.hh:54
constexpr T * data()
Definition gl_vec.hh:69
constexpr vecN & operator*=(T t)
Definition gl_vec.hh:79
constexpr const T * data() const
Definition gl_vec.hh:68
constexpr T get() const noexcept
Definition gl_vec.hh:72
constexpr vecN & operator-=(const vecN &v)
Definition gl_vec.hh:77
constexpr friend vecN operator/(T a, const vecN &v)
Definition gl_vec.hh:127
friend std::ostream & operator<<(std::ostream &os, const vecN &v)
Definition gl_vec.hh:142
constexpr friend vecN operator/(const vecN &v, T a)
Definition gl_vec.hh:132
constexpr vecN()
Definition gl_vec.hh:41
constexpr vecN & operator*=(const vecN &v)
Definition gl_vec.hh:78
constexpr friend vecN recip(const vecN &v)
Definition gl_vec.hh:120
constexpr vecN(T t)
Definition gl_vec.hh:44
constexpr vecN(const vecN< N2, T > &v)
Definition gl_vec.hh:51
constexpr friend vecN operator*(T a, const vecN &v)
Definition gl_vec.hh:98
constexpr friend vecN operator-(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:91
constexpr vecN & operator-=(const vecN &v)
Definition gl_vec.hh:188
constexpr friend vecN operator*(const vecN &v, T a)
Definition gl_vec.hh:216
constexpr vecN(const vecN< 2, T > &a, T b)
Definition gl_vec.hh:166
constexpr vecN & operator*=(T t)
Definition gl_vec.hh:190
constexpr T & operator[](unsigned i)
Definition gl_vec.hh:174
constexpr vecN(const vecN< 3, T2 > &v)
Definition gl_vec.hh:162
constexpr friend vecN operator/(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:248
constexpr friend vecN operator*(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:223
constexpr bool operator==(const vecN &) const =default
constexpr friend vecN operator+(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:195
constexpr vecN & operator+=(const vecN &v)
Definition gl_vec.hh:187
constexpr vecN(T a, T b, T c)
Definition gl_vec.hh:164
constexpr friend vecN operator/(T a, const vecN &v)
Definition gl_vec.hh:238
constexpr T operator[](unsigned i) const
Definition gl_vec.hh:168
constexpr vecN()
Definition gl_vec.hh:159
friend std::ostream & operator<<(std::ostream &os, const vecN &v)
Definition gl_vec.hh:253
constexpr T & get() noexcept
Definition gl_vec.hh:185
constexpr friend vecN operator/(const vecN &v, T a)
Definition gl_vec.hh:243
constexpr vecN(T t)
Definition gl_vec.hh:160
constexpr vecN(const vecN< 4, T > &v)
Definition gl_vec.hh:163
constexpr friend vecN recip(const vecN &v)
Definition gl_vec.hh:231
constexpr friend vecN operator*(T a, const vecN &v)
Definition gl_vec.hh:209
constexpr vecN(T a, const vecN< 2, T > &b)
Definition gl_vec.hh:165
constexpr friend vecN operator-(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:202
constexpr T * data()
Definition gl_vec.hh:182
constexpr vecN & operator*=(const vecN &v)
Definition gl_vec.hh:189
constexpr T get() const noexcept
Definition gl_vec.hh:184
constexpr const T * data() const
Definition gl_vec.hh:181
constexpr T & get() noexcept
Definition gl_vec.hh:298
constexpr friend vecN operator*(const vecN &v, T a)
Definition gl_vec.hh:330
constexpr vecN()
Definition gl_vec.hh:270
constexpr vecN & operator*=(T t)
Definition gl_vec.hh:304
constexpr vecN & operator*=(const vecN &v)
Definition gl_vec.hh:303
constexpr vecN(const vecN< 4, T2 > &v)
Definition gl_vec.hh:273
constexpr friend vecN operator/(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:362
constexpr vecN & operator+=(const vecN &v)
Definition gl_vec.hh:301
constexpr friend vecN operator*(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:337
constexpr vecN & operator-=(const vecN &v)
Definition gl_vec.hh:302
constexpr bool operator==(const vecN &) const =default
constexpr friend vecN operator+(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:309
constexpr vecN(T a, const vecN< 3, T > &b)
Definition gl_vec.hh:275
constexpr T & operator[](unsigned i)
Definition gl_vec.hh:286
constexpr T * data()
Definition gl_vec.hh:295
constexpr vecN(const vecN< 2, T > &a, const vecN< 2, T > &b)
Definition gl_vec.hh:277
constexpr friend vecN operator/(T a, const vecN &v)
Definition gl_vec.hh:352
constexpr vecN(T t)
Definition gl_vec.hh:271
friend std::ostream & operator<<(std::ostream &os, const vecN &v)
Definition gl_vec.hh:367
constexpr friend vecN operator/(const vecN &v, T a)
Definition gl_vec.hh:357
constexpr T operator[](unsigned i) const
Definition gl_vec.hh:279
constexpr friend vecN recip(const vecN &v)
Definition gl_vec.hh:345
constexpr T get() const noexcept
Definition gl_vec.hh:297
constexpr vecN(T a, T b, T c, T d)
Definition gl_vec.hh:274
constexpr friend vecN operator*(T a, const vecN &v)
Definition gl_vec.hh:323
constexpr vecN(const vecN< 3, T > &a, T b)
Definition gl_vec.hh:276
constexpr friend vecN operator-(const vecN &v1, const vecN &v2)
Definition gl_vec.hh:316
constexpr const T * data() const
Definition gl_vec.hh:294
constexpr double pi
Definition Math.hh:24
Definition gl_mat.hh:23
vecN< 3, float > vec3
Definition gl_vec.hh:383
vecN< 3, int > ivec3
Definition gl_vec.hh:386
constexpr T min_component(const vecN< N, T > &x)
Definition gl_vec.hh:440
constexpr T dot(const vecN< N, T > &x, const vecN< N, T > &y)
Definition gl_vec.hh:486
vecN< 2, int > ivec2
Definition gl_vec.hh:385
constexpr vecN< 3, T > cross(const vecN< 3, T > &a, const vecN< 3, T > &b)
Definition gl_vec.hh:519
constexpr vecN< N, int > trunc(const vecN< N, T > &x)
Definition gl_vec.hh:540
constexpr matMxN< M, N, T > operator-(const matMxN< M, N, T > &A)
Definition gl_mat.hh:181
vecN< 2, float > vec2
Definition gl_vec.hh:382
vecN< 4, int > ivec4
Definition gl_vec.hh:387
vecN< 4, float > vec4
Definition gl_vec.hh:384
T length(const vecN< N, T > &x)
Definition gl_vec.hh:505
vecN< N, int > round(const vecN< N, T > &x)
Definition gl_vec.hh:528
constexpr T length2(const vecN< N, T > &x)
Definition gl_vec.hh:498
constexpr vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition gl_vec.hh:431
constexpr vecN< N, T > dot_broadcast(const vecN< N, T > &x, const vecN< N, T > &y)
Definition gl_vec.hh:491
constexpr T degrees(T r)
Definition gl_vec.hh:414
constexpr vecN< N, T > sum_broadcast(const vecN< N, T > &x)
Definition gl_vec.hh:479
constexpr T sum(const vecN< N, T > &x)
Definition gl_vec.hh:472
constexpr T radians(T d)
Definition gl_vec.hh:410
vecN< N, T > normalize(const vecN< N, T > &x)
Definition gl_vec.hh:512
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition gl_vec.hh:449
float rsqrt(float x)
Definition gl_vec.hh:400
constexpr vecN< N, T > clamp(const vecN< N, T > &x, const vecN< N, T > &minVal, const vecN< N, T > &maxVal)
Definition gl_vec.hh:458
STL namespace.
#define UNREACHABLE
constexpr auto xrange(T e)
Definition xrange.hh:132