HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImathVec.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5 
6 //
7 // 2D, 3D and 4D point/vector class templates
8 //
9 
10 #ifndef INCLUDED_IMATHVEC_H
11 #define INCLUDED_IMATHVEC_H
12 
13 #include "ImathExport.h"
14 #include "ImathNamespace.h"
15 #include "ImathTypeTraits.h"
16 
17 #include "ImathMath.h"
18 
19 #include <iostream>
20 #include <limits>
21 #include <stdexcept>
22 
23 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
24 // suppress exception specification warnings
25 # pragma warning(push)
26 # pragma warning(disable : 4290)
27 #endif
28 
29 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
30 
31 template <class T> class Vec2;
32 template <class T> class Vec3;
33 template <class T> class Vec4;
34 
35 /// Enum for the Vec4 to Vec3 conversion constructor
37 {
38  INF_EXCEPTION
39 };
40 
41 ///
42 /// 2-element vector
43 ///
44 
45 template <class T> class IMATH_EXPORT_TEMPLATE_TYPE Vec2
46 {
47  public:
48 
49  /// @{
50  /// @name Direct access to elements
51 
52  T x, y;
53 
54  /// @}
55 
56  /// Element access by index.
57  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T& operator[] (int i) IMATH_NOEXCEPT;
58 
59  /// Element access by index.
60  IMATH_HOSTDEVICE constexpr const T& operator[] (int i) const IMATH_NOEXCEPT;
61 
62  /// @{
63  /// @name Constructors and Assignment
64 
65  /// Uninitialized by default
67 
68  /// Initialize to a scalar `(a,a)`
69  IMATH_HOSTDEVICE constexpr explicit Vec2 (T a) IMATH_NOEXCEPT;
70 
71  /// Initialize to given elements `(a,b)`
72  IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT;
73 
74  /// Copy constructor
75  IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT;
76 
77  /// Construct from Vec2 of another base type
78  template <class S> IMATH_HOSTDEVICE constexpr Vec2 (const Vec2<S>& v) IMATH_NOEXCEPT;
79 
80 
81  /// Assignment
82  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator= (const Vec2& v) IMATH_NOEXCEPT;
83 
84  /// Destructor
85  ~Vec2() IMATH_NOEXCEPT = default;
86 
87  /// @}
88 
89 #if IMATH_FOREIGN_VECTOR_INTEROP
90  /// @{
91  /// @name Interoperability with other vector types
92  ///
93  /// Construction and assignment are allowed from other classes that
94  /// appear to be equivalent vector types, provided that they have either
95  /// a subscripting operator, or data members .x and .y, that are of the
96  /// same type as the elements of this vector, and their size appears to
97  /// be the right number of elements.
98  ///
99  /// This functionality is disabled for gcc 4.x, which seems to have a
100  /// compiler bug that results in spurious errors. It can also be
101  /// disabled by defining IMATH_FOREIGN_VECTOR_INTEROP to be 0 prior to
102  /// including any Imath header files.
103  ///
104 
106  IMATH_HOSTDEVICE explicit constexpr Vec2 (const V& v) IMATH_NOEXCEPT
107  : Vec2(T(v.x), T(v.y)) { }
108 
110  && !has_xy<V,T>::value)>
111  IMATH_HOSTDEVICE explicit Vec2 (const V& v) : Vec2(T(v[0]), T(v[1])) { }
112 
114  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator= (const V& v) IMATH_NOEXCEPT {
115  x = T(v.x);
116  y = T(v.y);
117  return *this;
118  }
119 
121  && !has_xy<V,T>::value)>
122  IMATH_HOSTDEVICE const Vec2& operator= (const V& v) {
123  x = T(v[0]);
124  y = T(v[1]);
125  return *this;
126  }
127 #endif
128 
129  /// @{
130  /// @name Compatibility with Sb
131 
132  /// Set the value
133  template <class S> IMATH_HOSTDEVICE void setValue (S a, S b) IMATH_NOEXCEPT;
134 
135  /// Set the value
136  template <class S> IMATH_HOSTDEVICE void setValue (const Vec2<S>& v) IMATH_NOEXCEPT;
137 
138  /// Return the value in `a` and `b`
139  template <class S> IMATH_HOSTDEVICE void getValue (S& a, S& b) const IMATH_NOEXCEPT;
140 
141  /// Return the value in `v`
142  template <class S> IMATH_HOSTDEVICE void getValue (Vec2<S>& v) const IMATH_NOEXCEPT;
143 
144  /// Return a raw pointer to the array of values
145  IMATH_HOSTDEVICE T* getValue() IMATH_NOEXCEPT;
146 
147  /// Return a raw pointer to the array of values
148  IMATH_HOSTDEVICE const T* getValue() const IMATH_NOEXCEPT;
149 
150  /// @}
151 
152  /// @{
153  /// @name Arithmetic and Comparison
154 
155  /// Equality
156  template <class S> IMATH_HOSTDEVICE constexpr bool operator== (const Vec2<S>& v) const IMATH_NOEXCEPT;
157 
158 
159  /// Inequality
160  template <class S> IMATH_HOSTDEVICE constexpr bool operator!= (const Vec2<S>& v) const IMATH_NOEXCEPT;
161 
162  /// Compare two matrices and test if they are "approximately equal":
163  /// @return True if the coefficients of this and `m` are the same
164  /// with an absolute error of no more than e, i.e., for all i, j:
165  ///
166  /// abs (this[i][j] - m[i][j]) <= e
167  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError (const Vec2<T>& v, T e) const IMATH_NOEXCEPT;
168 
169  /// Compare two matrices and test if they are "approximately equal":
170  /// @return True if the coefficients of this and m are the same with
171  /// a relative error of no more than e, i.e., for all i, j:
172  ///
173  /// abs (this[i] - v[i][j]) <= e * abs (this[i][j])
174  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError (const Vec2<T>& v, T e) const IMATH_NOEXCEPT;
175 
176  /// Dot product
177  IMATH_HOSTDEVICE constexpr T dot (const Vec2& v) const IMATH_NOEXCEPT;
178 
179  /// Dot product
180  IMATH_HOSTDEVICE constexpr T operator^ (const Vec2& v) const IMATH_NOEXCEPT;
181 
182  /// Right-handed cross product, i.e. z component of
183  /// Vec3 (this->x, this->y, 0) % Vec3 (v.x, v.y, 0)
184  IMATH_HOSTDEVICE constexpr T cross (const Vec2& v) const IMATH_NOEXCEPT;
185 
186  /// Right-handed cross product, i.e. z component of
187  /// Vec3 (this->x, this->y, 0) % Vec3 (v.x, v.y, 0)
188  IMATH_HOSTDEVICE constexpr T operator% (const Vec2& v) const IMATH_NOEXCEPT;
189 
190  /// Component-wise addition
191  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator+= (const Vec2& v) IMATH_NOEXCEPT;
192 
193  /// Component-wise addition
194  IMATH_HOSTDEVICE constexpr Vec2 operator+ (const Vec2& v) const IMATH_NOEXCEPT;
195 
196  /// Component-wise subtraction
197  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator-= (const Vec2& v) IMATH_NOEXCEPT;
198 
199  /// Component-wise subtraction
200  IMATH_HOSTDEVICE constexpr Vec2 operator- (const Vec2& v) const IMATH_NOEXCEPT;
201 
202  /// Component-wise multiplication by -1
203  IMATH_HOSTDEVICE constexpr Vec2 operator-() const IMATH_NOEXCEPT;
204 
205  /// Component-wise multiplication by -1
206  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& negate() IMATH_NOEXCEPT;
207 
208  /// Component-wise multiplication
209  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator*= (const Vec2& v) IMATH_NOEXCEPT;
210 
211  /// Component-wise multiplication
212  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator*= (T a) IMATH_NOEXCEPT;
213 
214  /// Component-wise multiplication
215  IMATH_HOSTDEVICE constexpr Vec2 operator* (const Vec2& v) const IMATH_NOEXCEPT;
216 
217  /// Component-wise multiplication
218  IMATH_HOSTDEVICE constexpr Vec2 operator* (T a) const IMATH_NOEXCEPT;
219 
220  /// Component-wise division
221  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator/= (const Vec2& v) IMATH_NOEXCEPT;
222 
223  /// Component-wise division
224  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator/= (T a) IMATH_NOEXCEPT;
225 
226  /// Component-wise division
227  IMATH_HOSTDEVICE constexpr Vec2 operator/ (const Vec2& v) const IMATH_NOEXCEPT;
228 
229  /// Component-wise division
230  IMATH_HOSTDEVICE constexpr Vec2 operator/ (T a) const IMATH_NOEXCEPT;
231 
232  /// @}
233 
234  /// @{
235  /// @name Query and Manipulation
236 
237  /// Return the Euclidean norm
238  IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT;
239 
240  /// Return the square of the Euclidean norm, i.e. the dot product
241  /// with itself.
242  IMATH_HOSTDEVICE constexpr T length2() const IMATH_NOEXCEPT;
243 
244  /// Normalize in place. If length()==0, return a null vector.
245  IMATH_HOSTDEVICE const Vec2& normalize() IMATH_NOEXCEPT;
246 
247  /// Normalize in place. If length()==0, throw an exception.
248  const Vec2& normalizeExc();
249 
250  /// Normalize without any checks for length()==0. Slightly faster
251  /// than the other normalization routines, but if v.length() is
252  /// 0.0, the result is undefined.
253  IMATH_HOSTDEVICE const Vec2& normalizeNonNull() IMATH_NOEXCEPT;
254 
255  /// Return a normalized vector. Does not modify *this.
256  IMATH_HOSTDEVICE Vec2<T> normalized() const IMATH_NOEXCEPT;
257 
258  /// Return a normalized vector. Does not modify *this. Throw an
259  /// exception if length()==0.
260  Vec2<T> normalizedExc() const;
261 
262  /// Return a normalized vector. Does not modify *this, and does
263  /// not check for length()==0. Slightly faster than the other
264  /// normalization routines, but if v.length() is 0.0, the result
265  /// is undefined.
266  IMATH_HOSTDEVICE Vec2<T> normalizedNonNull() const IMATH_NOEXCEPT;
267 
268  /// @}
269 
270  /// @{
271  /// @name Numeric Limits
272 
273  /// Largest possible negative value
274  IMATH_HOSTDEVICE constexpr static T baseTypeLowest() IMATH_NOEXCEPT { return std::numeric_limits<T>::lowest(); }
275 
276  /// Largest possible positive value
277  IMATH_HOSTDEVICE constexpr static T baseTypeMax() IMATH_NOEXCEPT { return std::numeric_limits<T>::max(); }
278 
279  /// Smallest possible positive value
280  IMATH_HOSTDEVICE constexpr static T baseTypeSmallest() IMATH_NOEXCEPT { return std::numeric_limits<T>::min(); }
281 
282  /// Smallest possible e for which 1+e != 1
283  IMATH_HOSTDEVICE constexpr static T baseTypeEpsilon() IMATH_NOEXCEPT { return std::numeric_limits<T>::epsilon(); }
284 
285  /// @}
286 
287  /// Return the number of dimensions, i.e. 2
288  IMATH_HOSTDEVICE constexpr static unsigned int dimensions() IMATH_NOEXCEPT { return 2; }
289 
290  /// The base type: In templates that accept a parameter `V`, you
291  /// can refer to `T` as `V::BaseType`
292  typedef T BaseType;
293 
294  private:
295 
296  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T lengthTiny() const IMATH_NOEXCEPT;
297 };
298 
299 ///
300 /// 3-element vector
301 ///
302 
304 {
305  public:
306 
307  /// @{
308  /// @name Direct access to elements
309 
310  T x, y, z;
311 
312  /// @}
313 
314  /// Element access by index.
315  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T& operator[] (int i) IMATH_NOEXCEPT;
316 
317  /// Element access by index.
318  IMATH_HOSTDEVICE constexpr const T& operator[] (int i) const IMATH_NOEXCEPT;
319 
320  /// @{
321  /// @name Constructors and Assignment
322 
323  /// Uninitialized by default
324  IMATH_HOSTDEVICE Vec3() IMATH_NOEXCEPT;
325 
326  /// Initialize to a scalar `(a,a,a)`
327  IMATH_HOSTDEVICE constexpr explicit Vec3 (T a) IMATH_NOEXCEPT;
328 
329  /// Initialize to given elements `(a,b,c)`
330  IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT;
331 
332  /// Copy constructor
333  IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT;
334 
335  /// Construct from Vec3 of another base type
336  template <class S> IMATH_HOSTDEVICE constexpr Vec3 (const Vec3<S>& v) IMATH_NOEXCEPT;
337 
338  /// Vec4 to Vec3 conversion: divide x, y and z by w, even if w is
339  /// 0. The result depends on how the environment handles
340  /// floating-point exceptions.
341  template <class S> IMATH_HOSTDEVICE explicit constexpr Vec3 (const Vec4<S>& v) IMATH_NOEXCEPT;
342 
343  /// Vec4 to Vec3 conversion: divide x, y and z by w. Throws an
344  /// exception if w is zero or if division by w would overflow.
345  template <class S>
346  explicit IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3 (const Vec4<S>& v, InfException);
347 
348  /// Assignment
349  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator= (const Vec3& v) IMATH_NOEXCEPT;
350 
351  /// Destructor
352  ~Vec3() IMATH_NOEXCEPT = default;
353 
354  /// @}
355 
356 #if IMATH_FOREIGN_VECTOR_INTEROP
357  /// @{
358  /// @name Interoperability with other vector types
359  ///
360  /// Construction and assignment are allowed from other classes that
361  /// appear to be equivalent vector types, provided that they have either
362  /// a subscripting operator, or data members .x, .y, .z, that are of the
363  /// same type as the elements of this vector, and their size appears to
364  /// be the right number of elements.
365  ///
366  /// This functionality is disabled for gcc 4.x, which seems to have a
367  /// compiler bug that results in spurious errors. It can also be
368  /// disabled by defining IMATH_FOREIGN_VECTOR_INTEROP to be 0 prior to
369  /// including any Imath header files.
370  ///
371 
373  IMATH_HOSTDEVICE explicit constexpr Vec3 (const V& v) IMATH_NOEXCEPT
374  : Vec3(T(v.x), T(v.y), T(v.z)) { }
375 
377  && !has_xyz<V,T>::value)>
378  IMATH_HOSTDEVICE explicit Vec3 (const V& v) : Vec3(T(v[0]), T(v[1]), T(v[2])) { }
379 
380  /// Interoperability assignment from another type that behaves as if it
381  /// were an equivalent vector.
383  IMATH_HOSTDEVICE const Vec3& operator= (const V& v) IMATH_NOEXCEPT {
384  x = T(v.x);
385  y = T(v.y);
386  z = T(v.z);
387  return *this;
388  }
389 
391  && !has_xyz<V,T>::value)>
392  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator= (const V& v) {
393  x = T(v[0]);
394  y = T(v[1]);
395  z = T(v[2]);
396  return *this;
397  }
398  /// @}
399 #endif
400 
401  /// @{
402  /// @name Compatibility with Sb
403 
404  /// Set the value
405  template <class S> IMATH_HOSTDEVICE void setValue (S a, S b, S c) IMATH_NOEXCEPT;
406 
407  /// Set the value
408  template <class S> IMATH_HOSTDEVICE void setValue (const Vec3<S>& v) IMATH_NOEXCEPT;
409 
410  /// Return the value in `a`, `b`, and `c`
411  template <class S> IMATH_HOSTDEVICE void getValue (S& a, S& b, S& c) const IMATH_NOEXCEPT;
412 
413  /// Return the value in `v`
414  template <class S> IMATH_HOSTDEVICE void getValue (Vec3<S>& v) const IMATH_NOEXCEPT;
415 
416  /// Return a raw pointer to the array of values
417  IMATH_HOSTDEVICE T* getValue() IMATH_NOEXCEPT;
418 
419  /// Return a raw pointer to the array of values
420  IMATH_HOSTDEVICE const T* getValue() const IMATH_NOEXCEPT;
421 
422  /// @}
423 
424  /// @{
425  /// @name Arithmetic and Comparison
426 
427  /// Equality
428  template <class S> IMATH_HOSTDEVICE constexpr bool operator== (const Vec3<S>& v) const IMATH_NOEXCEPT;
429 
430  /// Inequality
431  template <class S> IMATH_HOSTDEVICE constexpr bool operator!= (const Vec3<S>& v) const IMATH_NOEXCEPT;
432 
433  /// Compare two matrices and test if they are "approximately equal":
434  /// @return True if the coefficients of this and `m` are the same
435  /// with an absolute error of no more than e, i.e., for all i, j:
436  ///
437  /// abs (this[i][j] - m[i][j]) <= e
438  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError (const Vec3<T>& v, T e) const IMATH_NOEXCEPT;
439 
440  /// Compare two matrices and test if they are "approximately equal":
441  /// @return True if the coefficients of this and m are the same with
442  /// a relative error of no more than e, i.e., for all i, j:
443  ///
444  /// abs (this[i] - v[i][j]) <= e * abs (this[i][j])
445  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError (const Vec3<T>& v, T e) const IMATH_NOEXCEPT;
446 
447  /// Dot product
448  IMATH_HOSTDEVICE constexpr T dot (const Vec3& v) const IMATH_NOEXCEPT;
449 
450  /// Dot product
451  IMATH_HOSTDEVICE constexpr T operator^ (const Vec3& v) const IMATH_NOEXCEPT;
452 
453  /// Right-handed cross product
454  IMATH_HOSTDEVICE constexpr Vec3 cross (const Vec3& v) const IMATH_NOEXCEPT;
455 
456  /// Right-handed cross product
457  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator%= (const Vec3& v) IMATH_NOEXCEPT;
458 
459  /// Right-handed cross product
460  IMATH_HOSTDEVICE constexpr Vec3 operator% (const Vec3& v) const IMATH_NOEXCEPT;
461 
462  /// Component-wise addition
463  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator+= (const Vec3& v) IMATH_NOEXCEPT;
464 
465  /// Component-wise addition
466  IMATH_HOSTDEVICE constexpr Vec3 operator+ (const Vec3& v) const IMATH_NOEXCEPT;
467 
468  /// Component-wise subtraction
469  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator-= (const Vec3& v) IMATH_NOEXCEPT;
470 
471  /// Component-wise subtraction
472  IMATH_HOSTDEVICE constexpr Vec3 operator- (const Vec3& v) const IMATH_NOEXCEPT;
473 
474  /// Component-wise multiplication by -1
475  IMATH_HOSTDEVICE constexpr Vec3 operator-() const IMATH_NOEXCEPT;
476 
477  /// Component-wise multiplication by -1
478  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& negate() IMATH_NOEXCEPT;
479 
480  /// Component-wise multiplication
481  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator*= (const Vec3& v) IMATH_NOEXCEPT;
482 
483  /// Component-wise multiplication
484  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator*= (T a) IMATH_NOEXCEPT;
485 
486  /// Component-wise multiplication
487  IMATH_HOSTDEVICE constexpr Vec3 operator* (const Vec3& v) const IMATH_NOEXCEPT;
488 
489  /// Component-wise multiplication
490  IMATH_HOSTDEVICE constexpr Vec3 operator* (T a) const IMATH_NOEXCEPT;
491 
492  /// Component-wise division
493  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator/= (const Vec3& v) IMATH_NOEXCEPT;
494 
495  /// Component-wise division
496  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& operator/= (T a) IMATH_NOEXCEPT;
497 
498  /// Component-wise division
499  IMATH_HOSTDEVICE constexpr Vec3 operator/ (const Vec3& v) const IMATH_NOEXCEPT;
500 
501  /// Component-wise division
502  IMATH_HOSTDEVICE constexpr Vec3 operator/ (T a) const IMATH_NOEXCEPT;
503 
504  /// @}
505 
506  /// @{
507  /// @name Query and Manipulation
508 
509  /// Return the Euclidean norm
510  IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT;
511 
512  /// Return the square of the Euclidean norm, i.e. the dot product
513  /// with itself.
514  IMATH_HOSTDEVICE constexpr T length2() const IMATH_NOEXCEPT;
515 
516  /// Normalize in place. If length()==0, return a null vector.
517  IMATH_HOSTDEVICE const Vec3& normalize() IMATH_NOEXCEPT;
518 
519  /// Normalize in place. If length()==0, throw an exception.
520  const Vec3& normalizeExc();
521 
522  /// Normalize without any checks for length()==0. Slightly faster
523  /// than the other normalization routines, but if v.length() is
524  /// 0.0, the result is undefined.
525  IMATH_HOSTDEVICE const Vec3& normalizeNonNull() IMATH_NOEXCEPT;
526 
527  /// Return a normalized vector. Does not modify *this.
528  IMATH_HOSTDEVICE Vec3<T> normalized() const IMATH_NOEXCEPT; // does not modify *this
529 
530  /// Return a normalized vector. Does not modify *this. Throw an
531  /// exception if length()==0.
532  Vec3<T> normalizedExc() const;
533 
534  /// Return a normalized vector. Does not modify *this, and does
535  /// not check for length()==0. Slightly faster than the other
536  /// normalization routines, but if v.length() is 0.0, the result
537  /// is undefined.
538  IMATH_HOSTDEVICE Vec3<T> normalizedNonNull() const IMATH_NOEXCEPT;
539 
540  /// @}
541 
542  /// @{
543  /// @name Numeric Limits
544 
545  /// Largest possible negative value
546  IMATH_HOSTDEVICE constexpr static T baseTypeLowest() IMATH_NOEXCEPT { return std::numeric_limits<T>::lowest(); }
547 
548  /// Largest possible positive value
549  IMATH_HOSTDEVICE constexpr static T baseTypeMax() IMATH_NOEXCEPT { return std::numeric_limits<T>::max(); }
550 
551  /// Smallest possible positive value
552  IMATH_HOSTDEVICE constexpr static T baseTypeSmallest() IMATH_NOEXCEPT { return std::numeric_limits<T>::min(); }
553 
554  /// Smallest possible e for which 1+e != 1
555  IMATH_HOSTDEVICE constexpr static T baseTypeEpsilon() IMATH_NOEXCEPT { return std::numeric_limits<T>::epsilon(); }
556 
557  /// @}
558 
559  /// Return the number of dimensions, i.e. 3
560  IMATH_HOSTDEVICE constexpr static unsigned int dimensions() IMATH_NOEXCEPT { return 3; }
561 
562  /// The base type: In templates that accept a parameter `V`, you
563  /// can refer to `T` as `V::BaseType`
564  typedef T BaseType;
565 
566  private:
567  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T lengthTiny() const IMATH_NOEXCEPT;
568 };
569 
570 ///
571 /// 4-element vector
572 ///
573 
575 {
576  public:
577 
578  /// @{
579  /// @name Direct access to elements
580 
581  T x, y, z, w;
582 
583  /// @}
584 
585  /// Element access by index.
586  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T& operator[] (int i) IMATH_NOEXCEPT;
587 
588  /// Element access by index.
589  IMATH_HOSTDEVICE constexpr const T& operator[] (int i) const IMATH_NOEXCEPT;
590 
591  /// @{
592  /// @name Constructors and Assignment
593 
594  /// Uninitialized by default
595  IMATH_HOSTDEVICE Vec4() IMATH_NOEXCEPT; // no initialization
596 
597  /// Initialize to a scalar `(a,a,a,a)`
598  IMATH_HOSTDEVICE constexpr explicit Vec4 (T a) IMATH_NOEXCEPT;
599 
600  /// Initialize to given elements `(a,b,c,d)`
601  IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT;
602 
603  /// Copy constructor
604  IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT;
605 
606  /// Construct from Vec4 of another base type
607  template <class S> IMATH_HOSTDEVICE constexpr Vec4 (const Vec4<S>& v) IMATH_NOEXCEPT;
608 
609  /// Vec3 to Vec4 conversion, sets w to 1.
610  template <class S> IMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3<S>& v) IMATH_NOEXCEPT;
611 
612  /// Assignment
613  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator= (const Vec4& v) IMATH_NOEXCEPT;
614 
615  /// Destructor
616  ~Vec4() IMATH_NOEXCEPT = default;
617 
618  /// @}
619 
620 #if IMATH_FOREIGN_VECTOR_INTEROP
621  /// @{
622  /// @name Interoperability with other vector types
623  ///
624  /// Construction and assignment are allowed from other classes that
625  /// appear to be equivalent vector types, provided that they have either
626  /// a subscripting operator, or data members .x, .y, .z, .w that are of
627  /// the same type as the elements of this vector, and their size appears
628  /// to be the right number of elements.
629  ///
630  /// This functionality is disabled for gcc 4.x, which seems to have a
631  /// compiler bug that results in spurious errors. It can also be
632  /// disabled by defining IMATH_FOREIGN_VECTOR_INTEROP to be 0 prior to
633  /// including any Imath header files.
634  ///
635 
637  IMATH_HOSTDEVICE explicit constexpr Vec4 (const V& v) IMATH_NOEXCEPT
638  : Vec4(T(v.x), T(v.y), T(v.z), T(v.w)) { }
639 
642  IMATH_HOSTDEVICE explicit Vec4 (const V& v) : Vec4(T(v[0]), T(v[1]), T(v[2]), T(v[3])) { }
643 
645  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator= (const V& v) IMATH_NOEXCEPT {
646  x = T(v.x);
647  y = T(v.y);
648  z = T(v.z);
649  w = T(v.w);
650  return *this;
651  }
652 
655  IMATH_HOSTDEVICE const Vec4& operator= (const V& v) {
656  x = T(v[0]);
657  y = T(v[1]);
658  z = T(v[2]);
659  w = T(v[3]);
660  return *this;
661  }
662  /// @}
663 #endif
664 
665  /// @{
666  /// @name Arithmetic and Comparison
667 
668  /// Equality
669  template <class S> IMATH_HOSTDEVICE constexpr bool operator== (const Vec4<S>& v) const IMATH_NOEXCEPT;
670 
671  /// Inequality
672  template <class S> IMATH_HOSTDEVICE constexpr bool operator!= (const Vec4<S>& v) const IMATH_NOEXCEPT;
673 
674  /// Compare two matrices and test if they are "approximately equal":
675  /// @return True if the coefficients of this and `m` are the same
676  /// with an absolute error of no more than e, i.e., for all i, j:
677  ///
678  /// abs (this[i][j] - m[i][j]) <= e
679  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError (const Vec4<T>& v, T e) const IMATH_NOEXCEPT;
680 
681  /// Compare two matrices and test if they are "approximately equal":
682  /// @return True if the coefficients of this and m are the same with
683  /// a relative error of no more than e, i.e., for all i, j:
684  ///
685  /// abs (this[i] - v[i][j]) <= e * abs (this[i][j])
686  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError (const Vec4<T>& v, T e) const IMATH_NOEXCEPT;
687 
688  /// Dot product
689  IMATH_HOSTDEVICE constexpr T dot (const Vec4& v) const IMATH_NOEXCEPT;
690 
691  /// Dot product
692  IMATH_HOSTDEVICE constexpr T operator^ (const Vec4& v) const IMATH_NOEXCEPT;
693 
694  /// Component-wise addition
695  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator+= (const Vec4& v) IMATH_NOEXCEPT;
696 
697  /// Component-wise addition
698  IMATH_HOSTDEVICE constexpr Vec4 operator+ (const Vec4& v) const IMATH_NOEXCEPT;
699 
700  /// Component-wise subtraction
701  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator-= (const Vec4& v) IMATH_NOEXCEPT;
702 
703  /// Component-wise subtraction
704  IMATH_HOSTDEVICE constexpr Vec4 operator- (const Vec4& v) const IMATH_NOEXCEPT;
705 
706  /// Component-wise multiplication by -1
707  IMATH_HOSTDEVICE constexpr Vec4 operator-() const IMATH_NOEXCEPT;
708 
709  /// Component-wise multiplication by -1
710  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& negate() IMATH_NOEXCEPT;
711 
712  /// Component-wise multiplication
713  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator*= (const Vec4& v) IMATH_NOEXCEPT;
714 
715  /// Component-wise multiplication
716  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator*= (T a) IMATH_NOEXCEPT;
717 
718  /// Component-wise multiplication
719  IMATH_HOSTDEVICE constexpr Vec4 operator* (const Vec4& v) const IMATH_NOEXCEPT;
720 
721  /// Component-wise multiplication
722  IMATH_HOSTDEVICE constexpr Vec4 operator* (T a) const IMATH_NOEXCEPT;
723 
724  /// Component-wise division
725  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator/= (const Vec4& v) IMATH_NOEXCEPT;
726 
727  /// Component-wise division
728  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& operator/= (T a) IMATH_NOEXCEPT;
729 
730  /// Component-wise division
731  IMATH_HOSTDEVICE constexpr Vec4 operator/ (const Vec4& v) const IMATH_NOEXCEPT;
732 
733  /// Component-wise division
734  IMATH_HOSTDEVICE constexpr Vec4 operator/ (T a) const IMATH_NOEXCEPT;
735 
736  /// @}
737 
738  /// @{
739  /// @name Query and Manipulation
740 
741  /// Return the Euclidean norm
742  IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT;
743 
744  /// Return the square of the Euclidean norm, i.e. the dot product
745  /// with itself.
746  IMATH_HOSTDEVICE constexpr T length2() const IMATH_NOEXCEPT;
747 
748  /// Normalize in place. If length()==0, return a null vector.
749  IMATH_HOSTDEVICE const Vec4& normalize() IMATH_NOEXCEPT; // modifies *this
750 
751  /// Normalize in place. If length()==0, throw an exception.
752  const Vec4& normalizeExc();
753 
754  /// Normalize without any checks for length()==0. Slightly faster
755  /// than the other normalization routines, but if v.length() is
756  /// 0.0, the result is undefined.
757  IMATH_HOSTDEVICE const Vec4& normalizeNonNull() IMATH_NOEXCEPT;
758 
759  /// Return a normalized vector. Does not modify *this.
760  IMATH_HOSTDEVICE Vec4<T> normalized() const IMATH_NOEXCEPT; // does not modify *this
761 
762  /// Return a normalized vector. Does not modify *this. Throw an
763  /// exception if length()==0.
764  Vec4<T> normalizedExc() const;
765 
766  /// Return a normalized vector. Does not modify *this, and does
767  /// not check for length()==0. Slightly faster than the other
768  /// normalization routines, but if v.length() is 0.0, the result
769  /// is undefined.
770  IMATH_HOSTDEVICE Vec4<T> normalizedNonNull() const IMATH_NOEXCEPT;
771 
772  /// @}
773 
774  /// @{
775  /// @name Numeric Limits
776 
777  /// Largest possible negative value
778  IMATH_HOSTDEVICE constexpr static T baseTypeLowest() IMATH_NOEXCEPT { return std::numeric_limits<T>::lowest(); }
779 
780  /// Largest possible positive value
781  IMATH_HOSTDEVICE constexpr static T baseTypeMax() IMATH_NOEXCEPT { return std::numeric_limits<T>::max(); }
782 
783  /// Smallest possible positive value
784  IMATH_HOSTDEVICE constexpr static T baseTypeSmallest() IMATH_NOEXCEPT { return std::numeric_limits<T>::min(); }
785 
786  /// Smallest possible e for which 1+e != 1
787  IMATH_HOSTDEVICE constexpr static T baseTypeEpsilon() IMATH_NOEXCEPT { return std::numeric_limits<T>::epsilon(); }
788 
789  /// @}
790 
791  /// Return the number of dimensions, i.e. 4
792  IMATH_HOSTDEVICE constexpr static unsigned int dimensions() IMATH_NOEXCEPT { return 4; }
793 
794  /// The base type: In templates that accept a parameter `V`, you
795  /// can refer to `T` as `V::BaseType`
796  typedef T BaseType;
797 
798  private:
799  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T lengthTiny() const IMATH_NOEXCEPT;
800 };
801 
802 /// Stream output, as "(x y)"
803 template <class T> std::ostream& operator<< (std::ostream& s, const Vec2<T>& v);
804 
805 /// Stream output, as "(x y z)"
806 template <class T> std::ostream& operator<< (std::ostream& s, const Vec3<T>& v);
807 
808 /// Stream output, as "(x y z w)"
809 template <class T> std::ostream& operator<< (std::ostream& s, const Vec4<T>& v);
810 
811 /// Reverse multiplication: S * Vec2<T>
812 template <class T> IMATH_HOSTDEVICE constexpr Vec2<T> operator* (T a, const Vec2<T>& v) IMATH_NOEXCEPT;
813 
814 /// Reverse multiplication: S * Vec3<T>
815 template <class T> IMATH_HOSTDEVICE constexpr Vec3<T> operator* (T a, const Vec3<T>& v) IMATH_NOEXCEPT;
816 
817 /// Reverse multiplication: S * Vec4<T>
818 template <class T> IMATH_HOSTDEVICE constexpr Vec4<T> operator* (T a, const Vec4<T>& v) IMATH_NOEXCEPT;
819 
820 //-------------------------
821 // Typedefs for convenience
822 //-------------------------
823 
824 /// Vec2 of short
825 typedef Vec2<short> V2s;
826 
827 /// Vec2 of integer
828 typedef Vec2<int> V2i;
829 
830 /// Vec2 of int64_t
831 typedef Vec2<int64_t> V2i64;
832 
833 /// Vec2 of float
834 typedef Vec2<float> V2f;
835 
836 /// Vec2 of double
837 typedef Vec2<double> V2d;
838 
839 /// Vec3 of short
840 typedef Vec3<short> V3s;
841 
842 /// Vec3 of integer
843 typedef Vec3<int> V3i;
844 
845 /// Vec3 of int64_t
846 typedef Vec3<int64_t> V3i64;
847 
848 /// Vec3 of float
849 typedef Vec3<float> V3f;
850 
851 /// Vec3 of double
852 typedef Vec3<double> V3d;
853 
854 /// Vec4 of short
855 typedef Vec4<short> V4s;
856 
857 /// Vec4 of integer
858 typedef Vec4<int> V4i;
859 
860 /// Vec4 of int64_t
861 typedef Vec4<int64_t> V4i64;
862 
863 /// Vec4 of float
864 typedef Vec4<float> V4f;
865 
866 /// Vec4 of double
867 typedef Vec4<double> V4d;
868 
869 //----------------------------------------------------------------------------
870 // Specializations for VecN<short>, VecN<int>
871 //
872 // Normalize and length don't make sense for integer vectors, so disable them.
873 //----------------------------------------------------------------------------
874 
875 /// @cond Doxygen_Suppress
876 
877 // Vec2<short>
878 template <> IMATH_HOSTDEVICE short Vec2<short>::length() const IMATH_NOEXCEPT = delete;
879 template <> IMATH_HOSTDEVICE const Vec2<short>& Vec2<short>::normalize() IMATH_NOEXCEPT = delete;
880 template <> const Vec2<short>& Vec2<short>::normalizeExc() = delete;
881 template <> IMATH_HOSTDEVICE const Vec2<short>& Vec2<short>::normalizeNonNull() IMATH_NOEXCEPT = delete;
882 template <> IMATH_HOSTDEVICE Vec2<short> Vec2<short>::normalized() const IMATH_NOEXCEPT = delete;
883 template <> Vec2<short> Vec2<short>::normalizedExc() const = delete;
884 template <> IMATH_HOSTDEVICE Vec2<short> Vec2<short>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
885 
886 // Vec2<int>
887 template <> IMATH_HOSTDEVICE int Vec2<int>::length() const IMATH_NOEXCEPT = delete;
888 template <> IMATH_HOSTDEVICE const Vec2<int>& Vec2<int>::normalize() IMATH_NOEXCEPT = delete;
889 template <> const Vec2<int>& Vec2<int>::normalizeExc() = delete;
890 template <> IMATH_HOSTDEVICE const Vec2<int>& Vec2<int>::normalizeNonNull() IMATH_NOEXCEPT = delete;
891 template <> IMATH_HOSTDEVICE Vec2<int> Vec2<int>::normalized() const IMATH_NOEXCEPT = delete;
892 template <> Vec2<int> Vec2<int>::normalizedExc() const = delete;
893 template <> IMATH_HOSTDEVICE Vec2<int> Vec2<int>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
894 
895 // Vec2<int64_t>
896 template <> IMATH_HOSTDEVICE int64_t Vec2<int64_t>::length() const IMATH_NOEXCEPT = delete;
897 template <> IMATH_HOSTDEVICE const Vec2<int64_t>& Vec2<int64_t>::normalize() IMATH_NOEXCEPT = delete;
898 template <> const Vec2<int64_t>& Vec2<int64_t>::normalizeExc() = delete;
899 template <> IMATH_HOSTDEVICE const Vec2<int64_t>& Vec2<int64_t>::normalizeNonNull() IMATH_NOEXCEPT = delete;
900 template <> IMATH_HOSTDEVICE Vec2<int64_t> Vec2<int64_t>::normalized() const IMATH_NOEXCEPT = delete;
901 template <> Vec2<int64_t> Vec2<int64_t>::normalizedExc() const = delete;
902 template <> IMATH_HOSTDEVICE Vec2<int64_t> Vec2<int64_t>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
903 
904 // Vec3<short>
905 template <> IMATH_HOSTDEVICE short Vec3<short>::length() const IMATH_NOEXCEPT = delete;
906 template <> IMATH_HOSTDEVICE const Vec3<short>& Vec3<short>::normalize() IMATH_NOEXCEPT = delete;
907 template <> const Vec3<short>& Vec3<short>::normalizeExc() = delete;
908 template <> IMATH_HOSTDEVICE const Vec3<short>& Vec3<short>::normalizeNonNull() IMATH_NOEXCEPT = delete;
909 template <> IMATH_HOSTDEVICE Vec3<short> Vec3<short>::normalized() const IMATH_NOEXCEPT = delete;
910 template <> Vec3<short> Vec3<short>::normalizedExc() const = delete;
911 template <> IMATH_HOSTDEVICE Vec3<short> Vec3<short>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
912 
913 // Vec3<int>
914 template <> IMATH_HOSTDEVICE int Vec3<int>::length() const IMATH_NOEXCEPT = delete;
915 template <> IMATH_HOSTDEVICE const Vec3<int>& Vec3<int>::normalize() IMATH_NOEXCEPT = delete;
916 template <> const Vec3<int>& Vec3<int>::normalizeExc() = delete;
917 template <> IMATH_HOSTDEVICE const Vec3<int>& Vec3<int>::normalizeNonNull() IMATH_NOEXCEPT = delete;
918 template <> IMATH_HOSTDEVICE Vec3<int> Vec3<int>::normalized() const IMATH_NOEXCEPT = delete;
919 template <> Vec3<int> Vec3<int>::normalizedExc() const = delete;
920 template <> IMATH_HOSTDEVICE Vec3<int> Vec3<int>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
921 
922 // Vec3<int64_t>
923 template <> IMATH_HOSTDEVICE int64_t Vec3<int64_t>::length() const IMATH_NOEXCEPT = delete;
924 template <> IMATH_HOSTDEVICE const Vec3<int64_t>& Vec3<int64_t>::normalize() IMATH_NOEXCEPT = delete;
925 template <> const Vec3<int64_t>& Vec3<int64_t>::normalizeExc() = delete;
926 template <> IMATH_HOSTDEVICE const Vec3<int64_t>& Vec3<int64_t>::normalizeNonNull() IMATH_NOEXCEPT = delete;
927 template <> IMATH_HOSTDEVICE Vec3<int64_t> Vec3<int64_t>::normalized() const IMATH_NOEXCEPT = delete;
928 template <> Vec3<int64_t> Vec3<int64_t>::normalizedExc() const = delete;
929 template <> IMATH_HOSTDEVICE Vec3<int64_t> Vec3<int64_t>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
930 
931 // Vec4<short>
932 template <> IMATH_HOSTDEVICE short Vec4<short>::length() const IMATH_NOEXCEPT = delete;
933 template <> IMATH_HOSTDEVICE const Vec4<short>& Vec4<short>::normalize() IMATH_NOEXCEPT = delete;
934 template <> const Vec4<short>& Vec4<short>::normalizeExc() = delete;
935 template <> IMATH_HOSTDEVICE const Vec4<short>& Vec4<short>::normalizeNonNull() IMATH_NOEXCEPT = delete;
936 template <> IMATH_HOSTDEVICE Vec4<short> Vec4<short>::normalized() const IMATH_NOEXCEPT = delete;
937 template <> Vec4<short> Vec4<short>::normalizedExc() const = delete;
938 template <> IMATH_HOSTDEVICE Vec4<short> Vec4<short>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
939 
940 // Vec4<int>
941 template <> IMATH_HOSTDEVICE int Vec4<int>::length() const IMATH_NOEXCEPT = delete;
942 template <> IMATH_HOSTDEVICE const Vec4<int>& Vec4<int>::normalize() IMATH_NOEXCEPT = delete;
943 template <> const Vec4<int>& Vec4<int>::normalizeExc() = delete;
944 template <> IMATH_HOSTDEVICE const Vec4<int>& Vec4<int>::normalizeNonNull() IMATH_NOEXCEPT = delete;
945 template <> IMATH_HOSTDEVICE Vec4<int> Vec4<int>::normalized() const IMATH_NOEXCEPT = delete;
946 template <> Vec4<int> Vec4<int>::normalizedExc() const = delete;
947 template <> IMATH_HOSTDEVICE Vec4<int> Vec4<int>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
948 
949 // Vec4<int64_t>
950 template <> IMATH_HOSTDEVICE int64_t Vec4<int64_t>::length() const IMATH_NOEXCEPT = delete;
951 template <> IMATH_HOSTDEVICE const Vec4<int64_t>& Vec4<int64_t>::normalize() IMATH_NOEXCEPT = delete;
952 template <> const Vec4<int64_t>& Vec4<int64_t>::normalizeExc() = delete;
953 template <> IMATH_HOSTDEVICE const Vec4<int64_t>& Vec4<int64_t>::normalizeNonNull() IMATH_NOEXCEPT = delete;
954 template <> IMATH_HOSTDEVICE Vec4<int64_t> Vec4<int64_t>::normalized() const IMATH_NOEXCEPT = delete;
955 template <> Vec4<int64_t> Vec4<int64_t>::normalizedExc() const = delete;
956 template <> IMATH_HOSTDEVICE Vec4<int64_t> Vec4<int64_t>::normalizedNonNull() const IMATH_NOEXCEPT = delete;
957 
958 /// @endcond Doxygen_Suppress
959 
960 //------------------------
961 // Implementation of Vec2:
962 //------------------------
963 
964 template <class T>
965 IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline T&
966 Vec2<T>::operator[] (int i) IMATH_NOEXCEPT
967 {
968  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
969 }
970 
971 template <class T>
972 constexpr IMATH_HOSTDEVICE inline const T&
973 Vec2<T>::operator[] (int i) const IMATH_NOEXCEPT
974 {
975  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
976 }
977 
978 template <class T> IMATH_HOSTDEVICE inline Vec2<T>::Vec2() IMATH_NOEXCEPT
979 {
980  // empty, and not constexpr because data is uninitialized.
981 }
982 
983 template <class T> IMATH_HOSTDEVICE constexpr inline Vec2<T>::Vec2 (T a) IMATH_NOEXCEPT
984  : x(a), y(a)
985 {
986 }
987 
988 template <class T> IMATH_HOSTDEVICE constexpr inline Vec2<T>::Vec2 (T a, T b) IMATH_NOEXCEPT
989  : x(a), y(b)
990 {
991 }
992 
993 template <class T> IMATH_HOSTDEVICE constexpr inline Vec2<T>::Vec2 (const Vec2& v) IMATH_NOEXCEPT
994  : x(v.x), y(v.y)
995 {
996 }
997 
998 template <class T> template <class S> IMATH_HOSTDEVICE constexpr inline Vec2<T>::Vec2 (const Vec2<S>& v) IMATH_NOEXCEPT
999  : x(T(v.x)), y(T(v.y))
1000 {
1001 }
1002 
1003 template <class T>
1004 IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline const Vec2<T>&
1005 Vec2<T>::operator= (const Vec2& v) IMATH_NOEXCEPT
1006 {
1007  x = v.x;
1008  y = v.y;
1009  return *this;
1010 }
1011 
1012 template <class T>
1013 template <class S>
1014 IMATH_HOSTDEVICE inline void
1015 Vec2<T>::setValue (S a, S b) IMATH_NOEXCEPT
1016 {
1017  x = T (a);
1018  y = T (b);
1019 }
1020 
1021 template <class T>
1022 template <class S>
1023 IMATH_HOSTDEVICE inline void
1024 Vec2<T>::setValue (const Vec2<S>& v) IMATH_NOEXCEPT
1025 {
1026  x = T (v.x);
1027  y = T (v.y);
1028 }
1029 
1030 template <class T>
1031 template <class S>
1032 IMATH_HOSTDEVICE inline void
1033 Vec2<T>::getValue (S& a, S& b) const IMATH_NOEXCEPT
1034 {
1035  a = S (x);
1036  b = S (y);
1037 }
1038 
1039 template <class T>
1040 template <class S>
1041 IMATH_HOSTDEVICE inline void
1042 Vec2<T>::getValue (Vec2<S>& v) const IMATH_NOEXCEPT
1043 {
1044  v.x = S (x);
1045  v.y = S (y);
1046 }
1047 
1048 template <class T>
1049 IMATH_HOSTDEVICE inline T*
1050 Vec2<T>::getValue() IMATH_NOEXCEPT
1051 {
1052  return (T*) &x;
1053 }
1054 
1055 template <class T>
1056 IMATH_HOSTDEVICE inline const T*
1057 Vec2<T>::getValue() const IMATH_NOEXCEPT
1058 {
1059  return (const T*) &x;
1060 }
1061 
1062 template <class T>
1063 template <class S>
1064 IMATH_HOSTDEVICE constexpr inline bool
1065 Vec2<T>::operator== (const Vec2<S>& v) const IMATH_NOEXCEPT
1066 {
1067  return x == v.x && y == v.y;
1068 }
1069 
1070 template <class T>
1071 template <class S>
1072 IMATH_HOSTDEVICE constexpr inline bool
1073 Vec2<T>::operator!= (const Vec2<S>& v) const IMATH_NOEXCEPT
1074 {
1075  return x != v.x || y != v.y;
1076 }
1077 
1078 template <class T>
1079 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
1080 Vec2<T>::equalWithAbsError (const Vec2<T>& v, T e) const IMATH_NOEXCEPT
1081 {
1082  for (int i = 0; i < 2; i++)
1083  if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e))
1084  return false;
1085 
1086  return true;
1087 }
1088 
1089 template <class T>
1090 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
1091 Vec2<T>::equalWithRelError (const Vec2<T>& v, T e) const IMATH_NOEXCEPT
1092 {
1093  for (int i = 0; i < 2; i++)
1094  if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e))
1095  return false;
1096 
1097  return true;
1098 }
1099 
1100 template <class T>
1101 IMATH_HOSTDEVICE constexpr inline T
1102 Vec2<T>::dot (const Vec2& v) const IMATH_NOEXCEPT
1103 {
1104  return x * v.x + y * v.y;
1105 }
1106 
1107 template <class T>
1108 IMATH_HOSTDEVICE constexpr inline T
1109 Vec2<T>::operator^ (const Vec2& v) const IMATH_NOEXCEPT
1110 {
1111  return dot (v);
1112 }
1113 
1114 template <class T>
1115 IMATH_HOSTDEVICE constexpr inline T
1116 Vec2<T>::cross (const Vec2& v) const IMATH_NOEXCEPT
1117 {
1118  return x * v.y - y * v.x;
1119 }
1120 
1121 template <class T>
1122 IMATH_HOSTDEVICE constexpr inline T
1123 Vec2<T>::operator% (const Vec2& v) const IMATH_NOEXCEPT
1124 {
1125  return x * v.y - y * v.x;
1126 }
1127 
1128 template <class T>
1129 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec2<T>&
1130 Vec2<T>::operator+= (const Vec2& v) IMATH_NOEXCEPT
1131 {
1132  x += v.x;
1133  y += v.y;
1134  return *this;
1135 }
1136 
1137 template <class T>
1138 IMATH_HOSTDEVICE constexpr inline Vec2<T>
1139 Vec2<T>::operator+ (const Vec2& v) const IMATH_NOEXCEPT
1140 {
1141  return Vec2 (x + v.x, y + v.y);
1142 }
1143 
1144 template <class T>
1145 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec2<T>&
1146 Vec2<T>::operator-= (const Vec2& v) IMATH_NOEXCEPT
1147 {
1148  x -= v.x;
1149  y -= v.y;
1150  return *this;
1151 }
1152 
1153 template <class T>
1154 IMATH_HOSTDEVICE constexpr inline Vec2<T>
1155 Vec2<T>::operator- (const Vec2& v) const IMATH_NOEXCEPT
1156 {
1157  return Vec2 (x - v.x, y - v.y);
1158 }
1159 
1160 template <class T>
1161 IMATH_HOSTDEVICE constexpr inline Vec2<T>
1162 Vec2<T>::operator-() const IMATH_NOEXCEPT
1163 {
1164  return Vec2 (-x, -y);
1165 }
1166 
1167 template <class T>
1168 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec2<T>&
1169 Vec2<T>::negate() IMATH_NOEXCEPT
1170 {
1171  x = -x;
1172  y = -y;
1173  return *this;
1174 }
1175 
1176 template <class T>
1177 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec2<T>&
1178 Vec2<T>::operator*= (const Vec2& v) IMATH_NOEXCEPT
1179 {
1180  x *= v.x;
1181  y *= v.y;
1182  return *this;
1183 }
1184 
1185 template <class T>
1186 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec2<T>&
1187 Vec2<T>::operator*= (T a) IMATH_NOEXCEPT
1188 {
1189  x *= a;
1190  y *= a;
1191  return *this;
1192 }
1193 
1194 template <class T>
1195 IMATH_HOSTDEVICE constexpr inline Vec2<T>
1196 Vec2<T>::operator* (const Vec2& v) const IMATH_NOEXCEPT
1197 {
1198  return Vec2 (x * v.x, y * v.y);
1199 }
1200 
1201 template <class T>
1202 IMATH_HOSTDEVICE constexpr inline Vec2<T>
1203 Vec2<T>::operator* (T a) const IMATH_NOEXCEPT
1204 {
1205  return Vec2 (x * a, y * a);
1206 }
1207 
1208 template <class T>
1209 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec2<T>&
1210 Vec2<T>::operator/= (const Vec2& v) IMATH_NOEXCEPT
1211 {
1212  x /= v.x;
1213  y /= v.y;
1214  return *this;
1215 }
1216 
1217 template <class T>
1218 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec2<T>&
1219 Vec2<T>::operator/= (T a) IMATH_NOEXCEPT
1220 {
1221  x /= a;
1222  y /= a;
1223  return *this;
1224 }
1225 
1226 template <class T>
1227 IMATH_HOSTDEVICE constexpr inline Vec2<T>
1228 Vec2<T>::operator/ (const Vec2& v) const IMATH_NOEXCEPT
1229 {
1230  return Vec2 (x / v.x, y / v.y);
1231 }
1232 
1233 template <class T>
1234 IMATH_HOSTDEVICE constexpr inline Vec2<T>
1235 Vec2<T>::operator/ (T a) const IMATH_NOEXCEPT
1236 {
1237  return Vec2 (x / a, y / a);
1238 }
1239 
1240 template <class T>
1241 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline T
1242 Vec2<T>::lengthTiny() const IMATH_NOEXCEPT
1243 {
1244  T absX = std::abs(x);
1245  T absY = std::abs(y);
1246 
1247  T max = absX;
1248 
1249  if (max < absY)
1250  max = absY;
1251 
1252  if (IMATH_UNLIKELY(max == T (0)))
1253  return T (0);
1254 
1255  //
1256  // Do not replace the divisions by max with multiplications by 1/max.
1257  // Computing 1/max can overflow but the divisions below will always
1258  // produce results less than or equal to 1.
1259  //
1260 
1261  absX /= max;
1262  absY /= max;
1263 
1264  return max * std::sqrt (absX * absX + absY * absY);
1265 }
1266 
1267 template <class T>
1268 IMATH_HOSTDEVICE inline T
1269 Vec2<T>::length() const IMATH_NOEXCEPT
1270 {
1271  T length2 = dot (*this);
1272 
1273  if (IMATH_UNLIKELY(length2 < T (2) * std::numeric_limits<T>::min()))
1274  return lengthTiny();
1275 
1276  return std::sqrt (length2);
1277 }
1278 
1279 template <class T>
1280 IMATH_HOSTDEVICE constexpr inline T
1281 Vec2<T>::length2() const IMATH_NOEXCEPT
1282 {
1283  return dot (*this);
1284 }
1285 
1286 template <class T>
1287 IMATH_HOSTDEVICE inline const Vec2<T>&
1288 Vec2<T>::normalize() IMATH_NOEXCEPT
1289 {
1290  T l = length();
1291 
1292  if (IMATH_LIKELY(l != T (0)))
1293  {
1294  //
1295  // Do not replace the divisions by l with multiplications by 1/l.
1296  // Computing 1/l can overflow but the divisions below will always
1297  // produce results less than or equal to 1.
1298  //
1299 
1300  x /= l;
1301  y /= l;
1302  }
1303 
1304  return *this;
1305 }
1306 
1307 template <class T>
1308 inline const Vec2<T>&
1310 {
1311  T l = length();
1312 
1313  if (IMATH_UNLIKELY(l == T (0)))
1314  throw std::domain_error ("Cannot normalize null vector.");
1315 
1316  x /= l;
1317  y /= l;
1318  return *this;
1319 }
1320 
1321 template <class T>
1322 IMATH_HOSTDEVICE inline const Vec2<T>&
1324 {
1325  T l = length();
1326  x /= l;
1327  y /= l;
1328  return *this;
1329 }
1330 
1331 template <class T>
1333 Vec2<T>::normalized() const IMATH_NOEXCEPT
1334 {
1335  T l = length();
1336 
1337  if (IMATH_UNLIKELY(l == T (0)))
1338  return Vec2 (T (0));
1339 
1340  return Vec2 (x / l, y / l);
1341 }
1342 
1343 template <class T>
1344 inline Vec2<T>
1346 {
1347  T l = length();
1348 
1349  if (IMATH_UNLIKELY(l == T (0)))
1350  throw std::domain_error ("Cannot normalize null vector.");
1351 
1352  return Vec2 (x / l, y / l);
1353 }
1354 
1355 template <class T>
1358 {
1359  T l = length();
1360  return Vec2 (x / l, y / l);
1361 }
1362 
1363 //-----------------------
1364 // Implementation of Vec3
1365 //-----------------------
1366 
1367 template <class T>
1369 IMATH_CONSTEXPR14 inline T&
1370 Vec3<T>::operator[] (int i) IMATH_NOEXCEPT
1371 {
1372  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1373 }
1374 
1375 template <class T>
1376 IMATH_HOSTDEVICE constexpr inline const T&
1377 Vec3<T>::operator[] (int i) const IMATH_NOEXCEPT
1378 {
1379  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1380 }
1381 
1382 template <class T> IMATH_HOSTDEVICE inline Vec3<T>::Vec3() IMATH_NOEXCEPT
1383 {
1384  // empty, and not constexpr because data is uninitialized.
1385 }
1386 
1387 template <class T> IMATH_HOSTDEVICE constexpr inline Vec3<T>::Vec3 (T a) IMATH_NOEXCEPT
1388  : x(a), y(a), z(a)
1389 {
1390 }
1391 
1392 template <class T> IMATH_HOSTDEVICE constexpr inline Vec3<T>::Vec3 (T a, T b, T c) IMATH_NOEXCEPT
1393  : x(a), y(b), z(c)
1394 {
1395 }
1396 
1397 template <class T> IMATH_HOSTDEVICE constexpr inline Vec3<T>::Vec3 (const Vec3& v) IMATH_NOEXCEPT
1398  : x(v.x), y(v.y), z(v.z)
1399 {
1400 }
1401 
1402 template <class T> template <class S>
1403 IMATH_HOSTDEVICE constexpr inline Vec3<T>::Vec3 (const Vec3<S>& v) IMATH_NOEXCEPT
1404  : x(T(v.x)), y(T(v.y)), z(T(v.z))
1405 {
1406 }
1407 
1408 template <class T>
1409 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1410 Vec3<T>::operator= (const Vec3& v) IMATH_NOEXCEPT
1411 {
1412  x = v.x;
1413  y = v.y;
1414  z = v.z;
1415  return *this;
1416 }
1417 
1418 template <class T> template <class S>
1419 IMATH_HOSTDEVICE constexpr inline Vec3<T>::Vec3 (const Vec4<S>& v) IMATH_NOEXCEPT
1420  : x(T(v.x/v.w)), y(T(v.y/v.w)), z(T(v.z/v.w))
1421 {
1422 }
1423 
1424 template <class T>
1425 template <class S>
1426 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Vec3<T>::Vec3 (const Vec4<S>& v, InfException)
1427 {
1428  T vx = T (v.x);
1429  T vy = T (v.y);
1430  T vz = T (v.z);
1431  T vw = T (v.w);
1432 
1433  T absW = (vw >= T (0)) ? vw : -vw;
1434 
1435  if (absW < 1)
1436  {
1437  T m = baseTypeMax() * absW;
1438 
1439  if (vx <= -m || vx >= m || vy <= -m || vy >= m || vz <= -m || vz >= m)
1440  throw std::domain_error ("Cannot normalize point at infinity.");
1441  }
1442 
1443  x = vx / vw;
1444  y = vy / vw;
1445  z = vz / vw;
1446 }
1447 
1448 template <class T>
1449 template <class S>
1450 IMATH_HOSTDEVICE inline void
1451 Vec3<T>::setValue (S a, S b, S c) IMATH_NOEXCEPT
1452 {
1453  x = T (a);
1454  y = T (b);
1455  z = T (c);
1456 }
1457 
1458 template <class T>
1459 template <class S>
1460 IMATH_HOSTDEVICE inline void
1461 Vec3<T>::setValue (const Vec3<S>& v) IMATH_NOEXCEPT
1462 {
1463  x = T (v.x);
1464  y = T (v.y);
1465  z = T (v.z);
1466 }
1467 
1468 template <class T>
1469 template <class S>
1470 IMATH_HOSTDEVICE inline void
1471 Vec3<T>::getValue (S& a, S& b, S& c) const IMATH_NOEXCEPT
1472 {
1473  a = S (x);
1474  b = S (y);
1475  c = S (z);
1476 }
1477 
1478 template <class T>
1479 template <class S>
1480 IMATH_HOSTDEVICE inline void
1481 Vec3<T>::getValue (Vec3<S>& v) const IMATH_NOEXCEPT
1482 {
1483  v.x = S (x);
1484  v.y = S (y);
1485  v.z = S (z);
1486 }
1487 
1488 template <class T>
1489 IMATH_HOSTDEVICE inline T*
1490 Vec3<T>::getValue() IMATH_NOEXCEPT
1491 {
1492  return (T*) &x;
1493 }
1494 
1495 template <class T>
1496 IMATH_HOSTDEVICE inline const T*
1497 Vec3<T>::getValue() const IMATH_NOEXCEPT
1498 {
1499  return (const T*) &x;
1500 }
1501 
1502 template <class T>
1503 template <class S>
1504 IMATH_HOSTDEVICE constexpr inline bool
1505 Vec3<T>::operator== (const Vec3<S>& v) const IMATH_NOEXCEPT
1506 {
1507  return x == v.x && y == v.y && z == v.z;
1508 }
1509 
1510 template <class T>
1511 template <class S>
1512 IMATH_HOSTDEVICE constexpr inline bool
1513 Vec3<T>::operator!= (const Vec3<S>& v) const IMATH_NOEXCEPT
1514 {
1515  return x != v.x || y != v.y || z != v.z;
1516 }
1517 
1518 template <class T>
1519 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
1520 Vec3<T>::equalWithAbsError (const Vec3<T>& v, T e) const IMATH_NOEXCEPT
1521 {
1522  for (int i = 0; i < 3; i++)
1523  if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e))
1524  return false;
1525 
1526  return true;
1527 }
1528 
1529 template <class T>
1530 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
1531 Vec3<T>::equalWithRelError (const Vec3<T>& v, T e) const IMATH_NOEXCEPT
1532 {
1533  for (int i = 0; i < 3; i++)
1534  if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e))
1535  return false;
1536 
1537  return true;
1538 }
1539 
1540 template <class T>
1541 IMATH_HOSTDEVICE constexpr inline T
1542 Vec3<T>::dot (const Vec3& v) const IMATH_NOEXCEPT
1543 {
1544  return x * v.x + y * v.y + z * v.z;
1545 }
1546 
1547 template <class T>
1548 IMATH_HOSTDEVICE constexpr inline T
1549 Vec3<T>::operator^ (const Vec3& v) const IMATH_NOEXCEPT
1550 {
1551  return dot (v);
1552 }
1553 
1554 template <class T>
1555 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1556 Vec3<T>::cross (const Vec3& v) const IMATH_NOEXCEPT
1557 {
1558  return Vec3 (y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
1559 }
1560 
1561 template <class T>
1562 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1563 Vec3<T>::operator%= (const Vec3& v) IMATH_NOEXCEPT
1564 {
1565  T a = y * v.z - z * v.y;
1566  T b = z * v.x - x * v.z;
1567  T c = x * v.y - y * v.x;
1568  x = a;
1569  y = b;
1570  z = c;
1571  return *this;
1572 }
1573 
1574 template <class T>
1575 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1576 Vec3<T>::operator% (const Vec3& v) const IMATH_NOEXCEPT
1577 {
1578  return Vec3 (y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
1579 }
1580 
1581 template <class T>
1582 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1583 Vec3<T>::operator+= (const Vec3& v) IMATH_NOEXCEPT
1584 {
1585  x += v.x;
1586  y += v.y;
1587  z += v.z;
1588  return *this;
1589 }
1590 
1591 template <class T>
1592 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1593 Vec3<T>::operator+ (const Vec3& v) const IMATH_NOEXCEPT
1594 {
1595  return Vec3 (x + v.x, y + v.y, z + v.z);
1596 }
1597 
1598 template <class T>
1599 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1600 Vec3<T>::operator-= (const Vec3& v) IMATH_NOEXCEPT
1601 {
1602  x -= v.x;
1603  y -= v.y;
1604  z -= v.z;
1605  return *this;
1606 }
1607 
1608 template <class T>
1609 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1610 Vec3<T>::operator- (const Vec3& v) const IMATH_NOEXCEPT
1611 {
1612  return Vec3 (x - v.x, y - v.y, z - v.z);
1613 }
1614 
1615 template <class T>
1616 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1617 Vec3<T>::operator-() const IMATH_NOEXCEPT
1618 {
1619  return Vec3 (-x, -y, -z);
1620 }
1621 
1622 template <class T>
1623 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1624 Vec3<T>::negate() IMATH_NOEXCEPT
1625 {
1626  x = -x;
1627  y = -y;
1628  z = -z;
1629  return *this;
1630 }
1631 
1632 template <class T>
1633 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1634 Vec3<T>::operator*= (const Vec3& v) IMATH_NOEXCEPT
1635 {
1636  x *= v.x;
1637  y *= v.y;
1638  z *= v.z;
1639  return *this;
1640 }
1641 
1642 template <class T>
1643 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1644 Vec3<T>::operator*= (T a) IMATH_NOEXCEPT
1645 {
1646  x *= a;
1647  y *= a;
1648  z *= a;
1649  return *this;
1650 }
1651 
1652 template <class T>
1653 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1654 Vec3<T>::operator* (const Vec3& v) const IMATH_NOEXCEPT
1655 {
1656  return Vec3 (x * v.x, y * v.y, z * v.z);
1657 }
1658 
1659 template <class T>
1660 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1661 Vec3<T>::operator* (T a) const IMATH_NOEXCEPT
1662 {
1663  return Vec3 (x * a, y * a, z * a);
1664 }
1665 
1666 template <class T>
1667 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1668 Vec3<T>::operator/= (const Vec3& v) IMATH_NOEXCEPT
1669 {
1670  x /= v.x;
1671  y /= v.y;
1672  z /= v.z;
1673  return *this;
1674 }
1675 
1676 template <class T>
1677 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3<T>&
1678 Vec3<T>::operator/= (T a) IMATH_NOEXCEPT
1679 {
1680  x /= a;
1681  y /= a;
1682  z /= a;
1683  return *this;
1684 }
1685 
1686 template <class T>
1687 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1688 Vec3<T>::operator/ (const Vec3& v) const IMATH_NOEXCEPT
1689 {
1690  return Vec3 (x / v.x, y / v.y, z / v.z);
1691 }
1692 
1693 template <class T>
1694 IMATH_HOSTDEVICE constexpr inline Vec3<T>
1695 Vec3<T>::operator/ (T a) const IMATH_NOEXCEPT
1696 {
1697  return Vec3 (x / a, y / a, z / a);
1698 }
1699 
1700 template <class T>
1701 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline T
1702 Vec3<T>::lengthTiny() const IMATH_NOEXCEPT
1703 {
1704  T absX = (x >= T (0)) ? x : -x;
1705  T absY = (y >= T (0)) ? y : -y;
1706  T absZ = (z >= T (0)) ? z : -z;
1707 
1708  T max = absX;
1709 
1710  if (max < absY)
1711  max = absY;
1712 
1713  if (max < absZ)
1714  max = absZ;
1715 
1716  if (IMATH_UNLIKELY(max == T (0)))
1717  return T (0);
1718 
1719  //
1720  // Do not replace the divisions by max with multiplications by 1/max.
1721  // Computing 1/max can overflow but the divisions below will always
1722  // produce results less than or equal to 1.
1723  //
1724 
1725  absX /= max;
1726  absY /= max;
1727  absZ /= max;
1728 
1729  return max * std::sqrt (absX * absX + absY * absY + absZ * absZ);
1730 }
1731 
1732 template <class T>
1733 IMATH_HOSTDEVICE inline T
1734 Vec3<T>::length() const IMATH_NOEXCEPT
1735 {
1736  T length2 = dot (*this);
1737 
1738  if (IMATH_UNLIKELY(length2 < T (2) * std::numeric_limits<T>::min()))
1739  return lengthTiny();
1740 
1741  return std::sqrt (length2);
1742 }
1743 
1744 template <class T>
1745 IMATH_HOSTDEVICE constexpr inline T
1746 Vec3<T>::length2() const IMATH_NOEXCEPT
1747 {
1748  return dot (*this);
1749 }
1750 
1751 template <class T>
1752 IMATH_HOSTDEVICE inline const Vec3<T>&
1753 Vec3<T>::normalize() IMATH_NOEXCEPT
1754 {
1755  T l = length();
1756 
1757  if (IMATH_LIKELY(l != T (0)))
1758  {
1759  //
1760  // Do not replace the divisions by l with multiplications by 1/l.
1761  // Computing 1/l can overflow but the divisions below will always
1762  // produce results less than or equal to 1.
1763  //
1764 
1765  x /= l;
1766  y /= l;
1767  z /= l;
1768  }
1769 
1770  return *this;
1771 }
1772 
1773 template <class T>
1774 inline const Vec3<T>&
1776 {
1777  T l = length();
1778 
1779  if (IMATH_UNLIKELY(l == T (0)))
1780  throw std::domain_error ("Cannot normalize null vector.");
1781 
1782  x /= l;
1783  y /= l;
1784  z /= l;
1785  return *this;
1786 }
1787 
1788 template <class T>
1789 IMATH_HOSTDEVICE inline const Vec3<T>&
1791 {
1792  T l = length();
1793  x /= l;
1794  y /= l;
1795  z /= l;
1796  return *this;
1797 }
1798 
1799 template <class T>
1801 Vec3<T>::normalized() const IMATH_NOEXCEPT
1802 {
1803  T l = length();
1804 
1805  if (IMATH_UNLIKELY((l == T (0))))
1806  return Vec3 (T (0));
1807 
1808  return Vec3 (x / l, y / l, z / l);
1809 }
1810 
1811 template <class T>
1812 inline Vec3<T>
1814 {
1815  T l = length();
1816 
1817  if (IMATH_UNLIKELY(l == T (0)))
1818  throw std::domain_error ("Cannot normalize null vector.");
1819 
1820  return Vec3 (x / l, y / l, z / l);
1821 }
1822 
1823 template <class T>
1826 {
1827  T l = length();
1828  return Vec3 (x / l, y / l, z / l);
1829 }
1830 
1831 //-----------------------
1832 // Implementation of Vec4
1833 //-----------------------
1834 
1835 template <class T>
1837 IMATH_CONSTEXPR14 inline T&
1838 Vec4<T>::operator[] (int i) IMATH_NOEXCEPT
1839 {
1840  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1841 }
1842 
1843 template <class T>
1844 IMATH_HOSTDEVICE constexpr inline const T&
1845 Vec4<T>::operator[] (int i) const IMATH_NOEXCEPT
1846 {
1847  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1848 }
1849 
1850 template <class T> IMATH_HOSTDEVICE inline Vec4<T>::Vec4() IMATH_NOEXCEPT
1851 {
1852  // empty, and not constexpr because data is uninitialized.
1853 }
1854 
1855 template <class T> IMATH_HOSTDEVICE constexpr inline Vec4<T>::Vec4 (T a) IMATH_NOEXCEPT
1856  : x(a), y(a), z(a), w(a)
1857 {
1858 }
1859 
1860 template <class T> IMATH_HOSTDEVICE constexpr inline Vec4<T>::Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT
1861  : x(a), y(b), z(c), w(d)
1862 {
1863 }
1864 
1865 template <class T> IMATH_HOSTDEVICE constexpr inline Vec4<T>::Vec4 (const Vec4& v) IMATH_NOEXCEPT
1866  : x(v.x), y(v.y), z(v.z), w(v.w)
1867 {
1868 }
1869 
1870 template <class T> template <class S>
1871 IMATH_HOSTDEVICE constexpr inline Vec4<T>::Vec4 (const Vec4<S>& v) IMATH_NOEXCEPT
1872  : x(T(v.x)), y(T(v.y)), z(T(v.z)), w(T(v.w))
1873 {
1874 }
1875 
1876 template <class T>
1877 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
1878 Vec4<T>::operator= (const Vec4& v) IMATH_NOEXCEPT
1879 {
1880  x = v.x;
1881  y = v.y;
1882  z = v.z;
1883  w = v.w;
1884  return *this;
1885 }
1886 
1887 template <class T> template <class S>
1888 IMATH_HOSTDEVICE constexpr inline Vec4<T>::Vec4 (const Vec3<S>& v) IMATH_NOEXCEPT
1889  : x(T(v.x)), y(T(v.y)), z(T(v.z)), w(T(1))
1890 {
1891 }
1892 
1893 template <class T>
1894 template <class S>
1895 IMATH_HOSTDEVICE constexpr inline bool
1896 Vec4<T>::operator== (const Vec4<S>& v) const IMATH_NOEXCEPT
1897 {
1898  return x == v.x && y == v.y && z == v.z && w == v.w;
1899 }
1900 
1901 template <class T>
1902 template <class S>
1903 IMATH_HOSTDEVICE constexpr inline bool
1904 Vec4<T>::operator!= (const Vec4<S>& v) const IMATH_NOEXCEPT
1905 {
1906  return x != v.x || y != v.y || z != v.z || w != v.w;
1907 }
1908 
1909 template <class T>
1910 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
1911 Vec4<T>::equalWithAbsError (const Vec4<T>& v, T e) const IMATH_NOEXCEPT
1912 {
1913  for (int i = 0; i < 4; i++)
1914  if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e))
1915  return false;
1916 
1917  return true;
1918 }
1919 
1920 template <class T>
1921 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
1922 Vec4<T>::equalWithRelError (const Vec4<T>& v, T e) const IMATH_NOEXCEPT
1923 {
1924  for (int i = 0; i < 4; i++)
1925  if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e))
1926  return false;
1927 
1928  return true;
1929 }
1930 
1931 template <class T>
1932 IMATH_HOSTDEVICE constexpr inline T
1933 Vec4<T>::dot (const Vec4& v) const IMATH_NOEXCEPT
1934 {
1935  return x * v.x + y * v.y + z * v.z + w * v.w;
1936 }
1937 
1938 template <class T>
1939 IMATH_HOSTDEVICE constexpr inline T
1940 Vec4<T>::operator^ (const Vec4& v) const IMATH_NOEXCEPT
1941 {
1942  return dot (v);
1943 }
1944 
1945 template <class T>
1946 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
1947 Vec4<T>::operator+= (const Vec4& v) IMATH_NOEXCEPT
1948 {
1949  x += v.x;
1950  y += v.y;
1951  z += v.z;
1952  w += v.w;
1953  return *this;
1954 }
1955 
1956 template <class T>
1957 IMATH_HOSTDEVICE constexpr inline Vec4<T>
1958 Vec4<T>::operator+ (const Vec4& v) const IMATH_NOEXCEPT
1959 {
1960  return Vec4 (x + v.x, y + v.y, z + v.z, w + v.w);
1961 }
1962 
1963 template <class T>
1964 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
1965 Vec4<T>::operator-= (const Vec4& v) IMATH_NOEXCEPT
1966 {
1967  x -= v.x;
1968  y -= v.y;
1969  z -= v.z;
1970  w -= v.w;
1971  return *this;
1972 }
1973 
1974 template <class T>
1975 IMATH_HOSTDEVICE constexpr inline Vec4<T>
1976 Vec4<T>::operator- (const Vec4& v) const IMATH_NOEXCEPT
1977 {
1978  return Vec4 (x - v.x, y - v.y, z - v.z, w - v.w);
1979 }
1980 
1981 template <class T>
1982 IMATH_HOSTDEVICE constexpr inline Vec4<T>
1983 Vec4<T>::operator-() const IMATH_NOEXCEPT
1984 {
1985  return Vec4 (-x, -y, -z, -w);
1986 }
1987 
1988 template <class T>
1989 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
1990 Vec4<T>::negate() IMATH_NOEXCEPT
1991 {
1992  x = -x;
1993  y = -y;
1994  z = -z;
1995  w = -w;
1996  return *this;
1997 }
1998 
1999 template <class T>
2000 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
2001 Vec4<T>::operator*= (const Vec4& v) IMATH_NOEXCEPT
2002 {
2003  x *= v.x;
2004  y *= v.y;
2005  z *= v.z;
2006  w *= v.w;
2007  return *this;
2008 }
2009 
2010 template <class T>
2011 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
2012 Vec4<T>::operator*= (T a) IMATH_NOEXCEPT
2013 {
2014  x *= a;
2015  y *= a;
2016  z *= a;
2017  w *= a;
2018  return *this;
2019 }
2020 
2021 template <class T>
2022 IMATH_HOSTDEVICE constexpr inline Vec4<T>
2023 Vec4<T>::operator* (const Vec4& v) const IMATH_NOEXCEPT
2024 {
2025  return Vec4 (x * v.x, y * v.y, z * v.z, w * v.w);
2026 }
2027 
2028 template <class T>
2029 IMATH_HOSTDEVICE constexpr inline Vec4<T>
2030 Vec4<T>::operator* (T a) const IMATH_NOEXCEPT
2031 {
2032  return Vec4 (x * a, y * a, z * a, w * a);
2033 }
2034 
2035 template <class T>
2036 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
2037 Vec4<T>::operator/= (const Vec4& v) IMATH_NOEXCEPT
2038 {
2039  x /= v.x;
2040  y /= v.y;
2041  z /= v.z;
2042  w /= v.w;
2043  return *this;
2044 }
2045 
2046 template <class T>
2047 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4<T>&
2048 Vec4<T>::operator/= (T a) IMATH_NOEXCEPT
2049 {
2050  x /= a;
2051  y /= a;
2052  z /= a;
2053  w /= a;
2054  return *this;
2055 }
2056 
2057 template <class T>
2058 IMATH_HOSTDEVICE constexpr inline Vec4<T>
2059 Vec4<T>::operator/ (const Vec4& v) const IMATH_NOEXCEPT
2060 {
2061  return Vec4 (x / v.x, y / v.y, z / v.z, w / v.w);
2062 }
2063 
2064 template <class T>
2065 IMATH_HOSTDEVICE constexpr inline Vec4<T>
2066 Vec4<T>::operator/ (T a) const IMATH_NOEXCEPT
2067 {
2068  return Vec4 (x / a, y / a, z / a, w / a);
2069 }
2070 
2071 template <class T>
2072 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline T
2073 Vec4<T>::lengthTiny() const IMATH_NOEXCEPT
2074 {
2075  T absX = (x >= T (0)) ? x : -x;
2076  T absY = (y >= T (0)) ? y : -y;
2077  T absZ = (z >= T (0)) ? z : -z;
2078  T absW = (w >= T (0)) ? w : -w;
2079 
2080  T max = absX;
2081 
2082  if (max < absY)
2083  max = absY;
2084 
2085  if (max < absZ)
2086  max = absZ;
2087 
2088  if (max < absW)
2089  max = absW;
2090 
2091  if (IMATH_UNLIKELY(max == T (0)))
2092  return T (0);
2093 
2094  //
2095  // Do not replace the divisions by max with multiplications by 1/max.
2096  // Computing 1/max can overflow but the divisions below will always
2097  // produce results less than or equal to 1.
2098  //
2099 
2100  absX /= max;
2101  absY /= max;
2102  absZ /= max;
2103  absW /= max;
2104 
2105  return max * std::sqrt (absX * absX + absY * absY + absZ * absZ + absW * absW);
2106 }
2107 
2108 template <class T>
2109 IMATH_HOSTDEVICE inline T
2110 Vec4<T>::length() const IMATH_NOEXCEPT
2111 {
2112  T length2 = dot (*this);
2113 
2114  if (IMATH_UNLIKELY(length2 < T (2) * std::numeric_limits<T>::min()))
2115  return lengthTiny();
2116 
2117  return std::sqrt (length2);
2118 }
2119 
2120 template <class T>
2121 IMATH_HOSTDEVICE constexpr inline T
2122 Vec4<T>::length2() const IMATH_NOEXCEPT
2123 {
2124  return dot (*this);
2125 }
2126 
2127 template <class T>
2128 IMATH_HOSTDEVICE const inline Vec4<T>&
2129 Vec4<T>::normalize() IMATH_NOEXCEPT
2130 {
2131  T l = length();
2132 
2133  if (IMATH_LIKELY(l != T (0)))
2134  {
2135  //
2136  // Do not replace the divisions by l with multiplications by 1/l.
2137  // Computing 1/l can overflow but the divisions below will always
2138  // produce results less than or equal to 1.
2139  //
2140 
2141  x /= l;
2142  y /= l;
2143  z /= l;
2144  w /= l;
2145  }
2146 
2147  return *this;
2148 }
2149 
2150 template <class T>
2151 const inline Vec4<T>&
2153 {
2154  T l = length();
2155 
2156  if (IMATH_UNLIKELY(l == T (0)))
2157  throw std::domain_error ("Cannot normalize null vector.");
2158 
2159  x /= l;
2160  y /= l;
2161  z /= l;
2162  w /= l;
2163  return *this;
2164 }
2165 
2166 template <class T>
2167 IMATH_HOSTDEVICE inline const Vec4<T>&
2169 {
2170  T l = length();
2171  x /= l;
2172  y /= l;
2173  z /= l;
2174  w /= l;
2175  return *this;
2176 }
2177 
2178 template <class T>
2180 Vec4<T>::normalized() const IMATH_NOEXCEPT
2181 {
2182  T l = length();
2183 
2184  if (IMATH_UNLIKELY(l == T (0)))
2185  return Vec4 (T (0));
2186 
2187  return Vec4 (x / l, y / l, z / l, w / l);
2188 }
2189 
2190 template <class T>
2191 inline Vec4<T>
2193 {
2194  T l = length();
2195 
2196  if (IMATH_UNLIKELY(l == T (0)))
2197  throw std::domain_error ("Cannot normalize null vector.");
2198 
2199  return Vec4 (x / l, y / l, z / l, w / l);
2200 }
2201 
2202 template <class T>
2205 {
2206  T l = length();
2207  return Vec4 (x / l, y / l, z / l, w / l);
2208 }
2209 
2210 //-----------------------------
2211 // Stream output implementation
2212 //-----------------------------
2213 
2214 template <class T>
2215 std::ostream&
2216 operator<< (std::ostream& s, const Vec2<T>& v)
2217 {
2218  return s << '(' << v.x << ' ' << v.y << ')';
2219 }
2220 
2221 template <class T>
2222 std::ostream&
2223 operator<< (std::ostream& s, const Vec3<T>& v)
2224 {
2225  return s << '(' << v.x << ' ' << v.y << ' ' << v.z << ')';
2226 }
2227 
2228 template <class T>
2229 std::ostream&
2230 operator<< (std::ostream& s, const Vec4<T>& v)
2231 {
2232  return s << '(' << v.x << ' ' << v.y << ' ' << v.z << ' ' << v.w << ')';
2233 }
2234 
2235 //-----------------------------------------
2236 // Implementation of reverse multiplication
2237 //-----------------------------------------
2238 
2239 template <class T>
2240 IMATH_HOSTDEVICE constexpr inline Vec2<T>
2241 operator* (T a, const Vec2<T>& v) IMATH_NOEXCEPT
2242 {
2243  return Vec2<T> (a * v.x, a * v.y);
2244 }
2245 
2246 template <class T>
2247 IMATH_HOSTDEVICE constexpr inline Vec3<T>
2248 operator* (T a, const Vec3<T>& v) IMATH_NOEXCEPT
2249 {
2250  return Vec3<T> (a * v.x, a * v.y, a * v.z);
2251 }
2252 
2253 template <class T>
2254 IMATH_HOSTDEVICE constexpr inline Vec4<T>
2255 operator* (T a, const Vec4<T>& v) IMATH_NOEXCEPT
2256 {
2257  return Vec4<T> (a * v.x, a * v.y, a * v.z, a * v.w);
2258 }
2259 
2260 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
2261 # pragma warning(pop)
2262 #endif
2263 
2264 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
2265 
2266 #endif // INCLUDED_IMATHVEC_H
IMATH_HOSTDEVICE static constexpr T baseTypeMax() IMATH_NOEXCEPT
Largest possible positive value.
Definition: ImathVec.h:781
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError(T x1, T x2, T e) IMATH_NOEXCEPT
Definition: ImathMath.h:152
T BaseType
Definition: ImathVec.h:796
IMATH_HOSTDEVICE Vec4(const V &v)
Definition: ImathVec.h:642
IMATH_HOSTDEVICE T * getValue() IMATH_NOEXCEPT
Return a raw pointer to the array of values.
Definition: ImathVec.h:1050
IMATH_HOSTDEVICE Vec4< T > normalized() const IMATH_NOEXCEPT
Return a normalized vector. Does not modify *this.
Definition: ImathVec.h:2180
IMATH_HOSTDEVICE constexpr T length2() const IMATH_NOEXCEPT
Definition: ImathVec.h:1746
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4 & negate() IMATH_NOEXCEPT
Component-wise multiplication by -1.
Definition: ImathVec.h:1990
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2 & operator+=(const Vec2 &v) IMATH_NOEXCEPT
Component-wise addition.
Definition: ImathVec.h:1130
T z
Definition: ImathVec.h:310
IMATH_HOSTDEVICE static constexpr T baseTypeSmallest() IMATH_NOEXCEPT
Smallest possible positive value.
Definition: ImathVec.h:552
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2 & operator*=(const Vec2 &v) IMATH_NOEXCEPT
Component-wise multiplication.
Definition: ImathVec.h:1178
Vec4< T > normalizedExc() const
Definition: ImathVec.h:2192
IMATH_HOSTDEVICE constexpr bool operator==(const Vec4< S > &v) const IMATH_NOEXCEPT
Equality.
Definition: ImathVec.h:1896
#define IMATH_NOEXCEPT
Definition: ImathConfig.h:72
IMATH_HOSTDEVICE const Vec4 & normalizeNonNull() IMATH_NOEXCEPT
Definition: ImathVec.h:2168
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError(const Vec3< T > &v, T e) const IMATH_NOEXCEPT
Definition: ImathVec.h:1531
Definition: ImathVec.h:32
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2 & operator-=(const Vec2 &v) IMATH_NOEXCEPT
Component-wise subtraction.
Definition: ImathVec.h:1146
IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT
Return the Euclidean norm.
Definition: ImathVec.h:1734
const GLdouble * v
Definition: glcorearb.h:837
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError(T x1, T x2, T e) IMATH_NOEXCEPT
Definition: ImathMath.h:165
GLsizei const GLfloat * value
Definition: glcorearb.h:824
IMATH_HOSTDEVICE const Vec3 & normalizeNonNull() IMATH_NOEXCEPT
Definition: ImathVec.h:1790
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4 & operator+=(const Vec4 &v) IMATH_NOEXCEPT
Component-wise addition.
Definition: ImathVec.h:1947
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2 & negate() IMATH_NOEXCEPT
Component-wise multiplication by -1.
Definition: ImathVec.h:1169
IMATH_HOSTDEVICE constexpr T dot(const Vec4 &v) const IMATH_NOEXCEPT
Dot product.
Definition: ImathVec.h:1933
vfloat4 sqrt(const vfloat4 &a)
Definition: simd.h:7481
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
IMATH_HOSTDEVICE constexpr Plane3< T > operator-(const Plane3< T > &plane) IMATH_NOEXCEPT
Reflect the pla.
Definition: ImathPlane.h:253
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3 & operator*=(const Vec3 &v) IMATH_NOEXCEPT
Component-wise multiplication.
Definition: ImathVec.h:1634
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4 & operator*=(const Vec4 &v) IMATH_NOEXCEPT
Component-wise multiplication.
Definition: ImathVec.h:2001
IMATH_HOSTDEVICE constexpr T operator^(const Vec4 &v) const IMATH_NOEXCEPT
Dot product.
Definition: ImathVec.h:1940
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError(const Vec4< T > &v, T e) const IMATH_NOEXCEPT
Definition: ImathVec.h:1922
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
IMATH_HOSTDEVICE Vec3< T > normalized() const IMATH_NOEXCEPT
Return a normalized vector. Does not modify *this.
Definition: ImathVec.h:1801
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
IMATH_HOSTDEVICE constexpr T dot(const Vec3 &v) const IMATH_NOEXCEPT
Dot product.
Definition: ImathVec.h:1542
IMATH_HOSTDEVICE constexpr T length2() const IMATH_NOEXCEPT
Definition: ImathVec.h:2122
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLint y
Definition: glcorearb.h:103
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3 & operator+=(const Vec3 &v) IMATH_NOEXCEPT
Component-wise addition.
Definition: ImathVec.h:1583
IMATH_HOSTDEVICE constexpr Vec2 operator-() const IMATH_NOEXCEPT
Component-wise multiplication by -1.
Definition: ImathVec.h:1162
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4 & operator=(const Vec4 &v) IMATH_NOEXCEPT
Assignment.
Definition: ImathVec.h:1878
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2 & operator=(const Vec2 &v) IMATH_NOEXCEPT
Assignment.
Definition: ImathVec.h:1005
IMATH_HOSTDEVICE Vec2< T > normalizedNonNull() const IMATH_NOEXCEPT
Definition: ImathVec.h:1357
IMATH_HOSTDEVICE static constexpr T baseTypeEpsilon() IMATH_NOEXCEPT
Smallest possible e for which 1+e != 1.
Definition: ImathVec.h:283
#define IMATH_HOSTDEVICE
Definition: ImathConfig.h:102
IMATH_HOSTDEVICE Vec3(const V &v)
Definition: ImathVec.h:378
IMATH_HOSTDEVICE constexpr Vec2< T > operator*(T a, const Vec2< T > &v) IMATH_NOEXCEPT
Reverse multiplication: S * Vec2<T>
Definition: ImathVec.h:2241
IMATH_HOSTDEVICE Vec2(const V &v)
Definition: ImathVec.h:111
IMATH_HOSTDEVICE static constexpr T baseTypeSmallest() IMATH_NOEXCEPT
Smallest possible positive value.
Definition: ImathVec.h:784
Vec3< T > normalizedExc() const
Definition: ImathVec.h:1813
IMATH_HOSTDEVICE Vec2< T > normalized() const IMATH_NOEXCEPT
Return a normalized vector. Does not modify *this.
Definition: ImathVec.h:1333
IMATH_HOSTDEVICE Vec2() IMATH_NOEXCEPT
Uninitialized by default.
Definition: ImathVec.h:978
IMATH_HOSTDEVICE constexpr bool operator!=(const Vec4< S > &v) const IMATH_NOEXCEPT
Inequality.
Definition: ImathVec.h:1904
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError(const Vec4< T > &v, T e) const IMATH_NOEXCEPT
Definition: ImathVec.h:1911
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
IMATH_HOSTDEVICE constexpr Vec4 operator-() const IMATH_NOEXCEPT
Component-wise multiplication by -1.
Definition: ImathVec.h:1983
T BaseType
Definition: ImathVec.h:564
T z
Definition: ImathVec.h:581
IMATH_HOSTDEVICE constexpr Vec3 operator-() const IMATH_NOEXCEPT
Component-wise multiplication by -1.
Definition: ImathVec.h:1617
T x
Definition: ImathVec.h:52
IMATH_HOSTDEVICE static constexpr unsigned int dimensions() IMATH_NOEXCEPT
Return the number of dimensions, i.e. 4.
Definition: ImathVec.h:792
T x
Definition: ImathVec.h:310
IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT
Return the Euclidean norm.
Definition: ImathVec.h:2110
IMATH_HOSTDEVICE constexpr T dot(const Vec2 &v) const IMATH_NOEXCEPT
Dot product.
Definition: ImathVec.h:1102
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4369
const Vec4 & normalizeExc()
Normalize in place. If length()==0, throw an exception.
Definition: ImathVec.h:2152
IMATH_HOSTDEVICE void setValue(S a, S b, S c) IMATH_NOEXCEPT
Set the value.
Definition: ImathVec.h:1451
T y
Definition: ImathVec.h:52
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:130
const Vec3 & normalizeExc()
Normalize in place. If length()==0, throw an exception.
Definition: ImathVec.h:1775
IMATH_HOSTDEVICE constexpr bool operator==(const Vec3< S > &v) const IMATH_NOEXCEPT
Equality.
Definition: ImathVec.h:1505
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T & operator[](int i) IMATH_NOEXCEPT
Element access by index.
Definition: ImathVec.h:966
IMATH_HOSTDEVICE constexpr Vec3 operator+(const Vec3 &v) const IMATH_NOEXCEPT
Component-wise addition.
Definition: ImathVec.h:1593
#define IMATH_EXPORT_ENUM
Definition: ImathExport.h:59
IMATH_HOSTDEVICE constexpr Vec4 operator*(const Vec4 &v) const IMATH_NOEXCEPT
Component-wise multiplication.
Definition: ImathVec.h:2023
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3 & negate() IMATH_NOEXCEPT
Component-wise multiplication by -1.
Definition: ImathVec.h:1624
IMATH_HOSTDEVICE constexpr T length2() const IMATH_NOEXCEPT
Definition: ImathVec.h:1281
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2 & operator/=(const Vec2 &v) IMATH_NOEXCEPT
Component-wise division.
Definition: ImathVec.h:1210
IMATH_HOSTDEVICE Vec3< T > normalizedNonNull() const IMATH_NOEXCEPT
Definition: ImathVec.h:1825
IMATH_HOSTDEVICE constexpr T operator^(const Vec3 &v) const IMATH_NOEXCEPT
Dot product.
Definition: ImathVec.h:1549
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3 & operator%=(const Vec3 &v) IMATH_NOEXCEPT
Right-handed cross product.
Definition: ImathVec.h:1563
GLint GLenum GLboolean normalized
Definition: glcorearb.h:872
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
IMATH_HOSTDEVICE constexpr Quat< T > operator+(const Quat< T > &q1, const Quat< T > &q2) IMATH_NOEXCEPT
Quaterion addition.
Definition: ImathQuat.h:905
IMATH_HOSTDEVICE static constexpr unsigned int dimensions() IMATH_NOEXCEPT
Return the number of dimensions, i.e. 2.
Definition: ImathVec.h:288
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4 & operator-=(const Vec4 &v) IMATH_NOEXCEPT
Component-wise subtraction.
Definition: ImathVec.h:1965
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError(const Vec2< T > &v, T e) const IMATH_NOEXCEPT
Definition: ImathVec.h:1091
IMATH_HOSTDEVICE static constexpr T baseTypeMax() IMATH_NOEXCEPT
Largest possible positive value.
Definition: ImathVec.h:277
IMATH_HOSTDEVICE static constexpr unsigned int dimensions() IMATH_NOEXCEPT
Return the number of dimensions, i.e. 3.
Definition: ImathVec.h:560
IMATH_HOSTDEVICE static constexpr T baseTypeMax() IMATH_NOEXCEPT
Largest possible positive value.
Definition: ImathVec.h:549
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3 & operator-=(const Vec3 &v) IMATH_NOEXCEPT
Component-wise subtraction.
Definition: ImathVec.h:1600
IMATH_HOSTDEVICE constexpr Vec4 operator+(const Vec4 &v) const IMATH_NOEXCEPT
Component-wise addition.
Definition: ImathVec.h:1958
IMATH_HOSTDEVICE Vec4< T > normalizedNonNull() const IMATH_NOEXCEPT
Definition: ImathVec.h:2204
IMATH_HOSTDEVICE constexpr bool operator!=(const Vec2< S > &v) const IMATH_NOEXCEPT
Inequality.
Definition: ImathVec.h:1073
IMATH_HOSTDEVICE constexpr bool operator==(const Vec2< S > &v) const IMATH_NOEXCEPT
Equality.
Definition: ImathVec.h:1065
IMATH_HOSTDEVICE constexpr Vec2 operator*(const Vec2 &v) const IMATH_NOEXCEPT
Component-wise multiplication.
Definition: ImathVec.h:1196
IMATH_HOSTDEVICE static constexpr T baseTypeEpsilon() IMATH_NOEXCEPT
Smallest possible e for which 1+e != 1.
Definition: ImathVec.h:787
IMATH_HOSTDEVICE T * getValue() IMATH_NOEXCEPT
Return a raw pointer to the array of values.
Definition: ImathVec.h:1490
IMATH_HOSTDEVICE constexpr Vec2 operator/(const Vec2 &v) const IMATH_NOEXCEPT
Component-wise division.
Definition: ImathVec.h:1228
#define IMATH_UNLIKELY(x)
Definition: ImathConfig.h:129
Definition: ImathVec.h:31
T x
Definition: ImathVec.h:581
IMATH_HOSTDEVICE constexpr bool operator!=(const Vec3< S > &v) const IMATH_NOEXCEPT
Inequality.
Definition: ImathVec.h:1513
IMATH_HOSTDEVICE static constexpr T baseTypeEpsilon() IMATH_NOEXCEPT
Smallest possible e for which 1+e != 1.
Definition: ImathVec.h:555
#define IMATH_EXPORT_TEMPLATE_TYPE
Definition: ImathExport.h:60
IMATH_HOSTDEVICE const Vec2 & normalizeNonNull() IMATH_NOEXCEPT
Definition: ImathVec.h:1323
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
IMATH_HOSTDEVICE constexpr Vec4 operator/(const Vec4 &v) const IMATH_NOEXCEPT
Component-wise division.
Definition: ImathVec.h:2059
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4 & operator/=(const Vec4 &v) IMATH_NOEXCEPT
Component-wise division.
Definition: ImathVec.h:2037
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError(const Vec3< T > &v, T e) const IMATH_NOEXCEPT
Definition: ImathVec.h:1520
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Definition: simd.h:4392
IMATH_HOSTDEVICE constexpr Vec2 operator+(const Vec2 &v) const IMATH_NOEXCEPT
Component-wise addition.
Definition: ImathVec.h:1139
IMATH_HOSTDEVICE constexpr T cross(const Vec2 &v) const IMATH_NOEXCEPT
Definition: ImathVec.h:1116
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T & operator[](int i) IMATH_NOEXCEPT
Element access by index.
Definition: ImathVec.h:1370
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
Definition: ImathFun.h:26
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
#define const
Definition: zconf.h:214
const Vec2 & normalizeExc()
Normalize in place. If length()==0, throw an exception.
Definition: ImathVec.h:1309
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError(const Vec2< T > &v, T e) const IMATH_NOEXCEPT
Definition: ImathVec.h:1080
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3 & operator=(const Vec3 &v) IMATH_NOEXCEPT
Assignment.
Definition: ImathVec.h:1410
IMATH_HOSTDEVICE Vec4() IMATH_NOEXCEPT
Uninitialized by default.
Definition: ImathVec.h:1850
#define IMATH_LIKELY(x)
Definition: ImathConfig.h:128
IMATH_HOSTDEVICE constexpr T operator%(const Vec2 &v) const IMATH_NOEXCEPT
Definition: ImathVec.h:1123
Definition: ImathVec.h:33
IMATH_HOSTDEVICE constexpr T operator^(const Vec2 &v) const IMATH_NOEXCEPT
Dot product.
Definition: ImathVec.h:1109
T BaseType
Definition: ImathVec.h:292
T w
Definition: ImathVec.h:581
enum IMATH_EXPORT_ENUM InfException
Enum for the Vec4 to Vec3 conversion constructor.
Definition: ImathVec.h:36
IMATH_HOSTDEVICE constexpr Vec3 operator%(const Vec3 &v) const IMATH_NOEXCEPT
Right-handed cross product.
Definition: ImathVec.h:1576
IMATH_HOSTDEVICE static constexpr T baseTypeSmallest() IMATH_NOEXCEPT
Smallest possible positive value.
Definition: ImathVec.h:280
T y
Definition: ImathVec.h:581
IMATH_HOSTDEVICE constexpr Vec3 cross(const Vec3 &v) const IMATH_NOEXCEPT
Right-handed cross product.
Definition: ImathVec.h:1556
IMATH_HOSTDEVICE const Vec3 & normalize() IMATH_NOEXCEPT
Normalize in place. If length()==0, return a null vector.
Definition: ImathVec.h:1753
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3 & operator/=(const Vec3 &v) IMATH_NOEXCEPT
Component-wise division.
Definition: ImathVec.h:1668
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
Vec2< T > normalizedExc() const
Definition: ImathVec.h:1345
IMATH_HOSTDEVICE void setValue(S a, S b) IMATH_NOEXCEPT
Set the value.
Definition: ImathVec.h:1015
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T & operator[](int i) IMATH_NOEXCEPT
Element access by index.
Definition: ImathVec.h:1838
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept
IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT
Return the Euclidean norm.
Definition: ImathVec.h:1269
IMATH_HOSTDEVICE constexpr Vec3 operator*(const Vec3 &v) const IMATH_NOEXCEPT
Component-wise multiplication.
Definition: ImathVec.h:1654
IMATH_HOSTDEVICE const Vec2 & normalize() IMATH_NOEXCEPT
Normalize in place. If length()==0, return a null vector.
Definition: ImathVec.h:1288
IMATH_HOSTDEVICE Vec3() IMATH_NOEXCEPT
Uninitialized by default.
Definition: ImathVec.h:1382
IMATH_HOSTDEVICE const Vec4 & normalize() IMATH_NOEXCEPT
Normalize in place. If length()==0, return a null vector.
Definition: ImathVec.h:2129
IMATH_HOSTDEVICE constexpr Vec3 operator/(const Vec3 &v) const IMATH_NOEXCEPT
Component-wise division.
Definition: ImathVec.h:1688
const TypeMask operator^(const TypeMask &m1, const TypeMask &m2)
Definition: GA_PrimCompat.h:90