Atoms Crowd  7.0.0
ImathVec.h
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_ATOMSMATHVEC_H
11 #define INCLUDED_ATOMSMATHVEC_H
12 
13 #include <AtomsMath/ImathMath.h>
14 #include <AtomsMath/ImathNamespace.h>
15 
16 #include <iostream>
17 #include <limits>
18 #include <stdexcept>
19 
20 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
21 // suppress exception specification warnings
22 # pragma warning(push)
23 # pragma warning(disable : 4290)
24 #endif
25 
26 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_ENTER
27 
28 template <class T> class Vec2;
29 template <class T> class Vec3;
30 template <class T> class Vec4;
31 
33 enum InfException
34 {
35  INF_EXCEPTION
36 };
37 
41 
42 template <class T> class Vec2
43 {
44  public:
45 
48 
49  T x, y;
50 
52 
54  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T& operator[] (int i) noexcept;
55 
57  ATOMSMATH_HOSTDEVICE constexpr const T& operator[] (int i) const noexcept;
58 
61 
63  ATOMSMATH_HOSTDEVICE Vec2() noexcept;
64 
66  ATOMSMATH_HOSTDEVICE constexpr explicit Vec2 (T a) noexcept;
67 
69  ATOMSMATH_HOSTDEVICE constexpr Vec2 (T a, T b) noexcept;
70 
72  ATOMSMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) noexcept;
73 
75  template <class S> ATOMSMATH_HOSTDEVICE constexpr Vec2 (const Vec2<S>& v) noexcept;
76 
78  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& operator= (const Vec2& v) noexcept;
79 
81  ~Vec2() noexcept = default;
82 
84 
87 
89  template <class S> ATOMSMATH_HOSTDEVICE void setValue (S a, S b) noexcept;
90 
92  template <class S> ATOMSMATH_HOSTDEVICE void setValue (const Vec2<S>& v) noexcept;
93 
95  template <class S> ATOMSMATH_HOSTDEVICE void getValue (S& a, S& b) const noexcept;
96 
98  template <class S> ATOMSMATH_HOSTDEVICE void getValue (Vec2<S>& v) const noexcept;
99 
101  ATOMSMATH_HOSTDEVICE T* getValue() noexcept;
102 
104  ATOMSMATH_HOSTDEVICE const T* getValue() const noexcept;
105 
107 
110 
112  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator== (const Vec2<S>& v) const noexcept;
113 
114 
116  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator!= (const Vec2<S>& v) const noexcept;
117 
123  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError (const Vec2<T>& v, T e) const noexcept;
124 
130  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError (const Vec2<T>& v, T e) const noexcept;
131 
133  ATOMSMATH_HOSTDEVICE constexpr T dot (const Vec2& v) const noexcept;
134 
136  ATOMSMATH_HOSTDEVICE constexpr T operator^ (const Vec2& v) const noexcept;
137 
140  ATOMSMATH_HOSTDEVICE constexpr T cross (const Vec2& v) const noexcept;
141 
144  ATOMSMATH_HOSTDEVICE constexpr T operator% (const Vec2& v) const noexcept;
145 
147  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& operator+= (const Vec2& v) noexcept;
148 
150  ATOMSMATH_HOSTDEVICE constexpr Vec2 operator+ (const Vec2& v) const noexcept;
151 
153  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& operator-= (const Vec2& v) noexcept;
154 
156  ATOMSMATH_HOSTDEVICE constexpr Vec2 operator- (const Vec2& v) const noexcept;
157 
159  ATOMSMATH_HOSTDEVICE constexpr Vec2 operator-() const noexcept;
160 
162  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& negate() noexcept;
163 
165  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& operator*= (const Vec2& v) noexcept;
166 
168  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& operator*= (T a) noexcept;
169 
171  ATOMSMATH_HOSTDEVICE constexpr Vec2 operator* (const Vec2& v) const noexcept;
172 
174  ATOMSMATH_HOSTDEVICE constexpr Vec2 operator* (T a) const noexcept;
175 
177  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& operator/= (const Vec2& v) noexcept;
178 
180  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2& operator/= (T a) noexcept;
181 
183  ATOMSMATH_HOSTDEVICE constexpr Vec2 operator/ (const Vec2& v) const noexcept;
184 
186  ATOMSMATH_HOSTDEVICE constexpr Vec2 operator/ (T a) const noexcept;
187 
189 
192 
194  ATOMSMATH_HOSTDEVICE T length() const noexcept;
195 
198  ATOMSMATH_HOSTDEVICE constexpr T length2() const noexcept;
199 
201  ATOMSMATH_HOSTDEVICE const Vec2& normalize() noexcept;
202 
204  const Vec2& normalizeExc();
205 
209  ATOMSMATH_HOSTDEVICE const Vec2& normalizeNonNull() noexcept;
210 
212  ATOMSMATH_HOSTDEVICE Vec2<T> normalized() const noexcept;
213 
216  Vec2<T> normalizedExc() const;
217 
222  ATOMSMATH_HOSTDEVICE Vec2<T> normalizedNonNull() const noexcept;
223 
225 
228 
230  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeLowest() noexcept { return std::numeric_limits<T>::lowest(); }
231 
233  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeMax() noexcept { return std::numeric_limits<T>::max(); }
234 
236  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeSmallest() noexcept { return std::numeric_limits<T>::min(); }
237 
239  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeEpsilon() noexcept { return std::numeric_limits<T>::epsilon(); }
240 
242 
244  ATOMSMATH_HOSTDEVICE constexpr static unsigned int dimensions() noexcept { return 2; }
245 
248  typedef T BaseType;
249 
250  private:
251 
252  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T lengthTiny() const noexcept;
253 };
254 
258 
259 template <class T> class Vec3
260 {
261  public:
262 
265 
266  T x, y, z;
267 
269 
271  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T& operator[] (int i) noexcept;
272 
274  ATOMSMATH_HOSTDEVICE constexpr const T& operator[] (int i) const noexcept;
275 
278 
280  ATOMSMATH_HOSTDEVICE Vec3() noexcept;
281 
283  ATOMSMATH_HOSTDEVICE constexpr explicit Vec3 (T a) noexcept;
284 
286  ATOMSMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) noexcept;
287 
289  ATOMSMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) noexcept;
290 
292  template <class S> ATOMSMATH_HOSTDEVICE constexpr Vec3 (const Vec3<S>& v) noexcept;
293 
297  template <class S> ATOMSMATH_HOSTDEVICE explicit constexpr Vec3 (const Vec4<S>& v) noexcept;
298 
301  template <class S>
302  explicit ATOMSMATH_CONSTEXPR14 Vec3 (const Vec4<S>& v, InfException);
303 
305  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator= (const Vec3& v) noexcept;
306 
308  ~Vec3() noexcept = default;
309 
311 
314 
316  template <class S> ATOMSMATH_HOSTDEVICE void setValue (S a, S b, S c) noexcept;
317 
319  template <class S> ATOMSMATH_HOSTDEVICE void setValue (const Vec3<S>& v) noexcept;
320 
322  template <class S> ATOMSMATH_HOSTDEVICE void getValue (S& a, S& b, S& c) const noexcept;
323 
325  template <class S> ATOMSMATH_HOSTDEVICE void getValue (Vec3<S>& v) const noexcept;
326 
328  ATOMSMATH_HOSTDEVICE T* getValue() noexcept;
329 
331  ATOMSMATH_HOSTDEVICE const T* getValue() const noexcept;
332 
334 
337 
339  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator== (const Vec3<S>& v) const noexcept;
340 
342  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator!= (const Vec3<S>& v) const noexcept;
343 
349  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError (const Vec3<T>& v, T e) const noexcept;
350 
356  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError (const Vec3<T>& v, T e) const noexcept;
357 
359  ATOMSMATH_HOSTDEVICE constexpr T dot (const Vec3& v) const noexcept;
360 
362  ATOMSMATH_HOSTDEVICE constexpr T operator^ (const Vec3& v) const noexcept;
363 
365  ATOMSMATH_HOSTDEVICE constexpr Vec3 cross (const Vec3& v) const noexcept;
366 
368  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator%= (const Vec3& v) noexcept;
369 
371  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator% (const Vec3& v) const noexcept;
372 
374  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator+= (const Vec3& v) noexcept;
375 
377  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator+ (const Vec3& v) const noexcept;
378 
380  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator-= (const Vec3& v) noexcept;
381 
383  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator- (const Vec3& v) const noexcept;
384 
386  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator-() const noexcept;
387 
389  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& negate() noexcept;
390 
392  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator*= (const Vec3& v) noexcept;
393 
395  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator*= (T a) noexcept;
396 
398  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator* (const Vec3& v) const noexcept;
399 
401  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator* (T a) const noexcept;
402 
404  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator/= (const Vec3& v) noexcept;
405 
407  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3& operator/= (T a) noexcept;
408 
410  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator/ (const Vec3& v) const noexcept;
411 
413  ATOMSMATH_HOSTDEVICE constexpr Vec3 operator/ (T a) const noexcept;
414 
416 
419 
421  ATOMSMATH_HOSTDEVICE T length() const noexcept;
422 
425  ATOMSMATH_HOSTDEVICE constexpr T length2() const noexcept;
426 
428  ATOMSMATH_HOSTDEVICE const Vec3& normalize() noexcept;
429 
431  const Vec3& normalizeExc();
432 
436  ATOMSMATH_HOSTDEVICE const Vec3& normalizeNonNull() noexcept;
437 
439  ATOMSMATH_HOSTDEVICE Vec3<T> normalized() const noexcept; // does not modify *this
440 
443  Vec3<T> normalizedExc() const;
444 
449  ATOMSMATH_HOSTDEVICE Vec3<T> normalizedNonNull() const noexcept;
450 
452 
455 
457  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeLowest() noexcept { return std::numeric_limits<T>::lowest(); }
458 
460  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeMax() noexcept { return std::numeric_limits<T>::max(); }
461 
463  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeSmallest() noexcept { return std::numeric_limits<T>::min(); }
464 
466  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeEpsilon() noexcept { return std::numeric_limits<T>::epsilon(); }
467 
469 
471  ATOMSMATH_HOSTDEVICE constexpr static unsigned int dimensions() noexcept { return 3; }
472 
475  typedef T BaseType;
476 
477  private:
478  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T lengthTiny() const noexcept;
479 };
480 
484 
485 template <class T> class Vec4
486 {
487  public:
488 
491 
492  T x, y, z, w;
493 
495 
497  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T& operator[] (int i) noexcept;
498 
500  ATOMSMATH_HOSTDEVICE constexpr const T& operator[] (int i) const noexcept;
501 
504 
506  ATOMSMATH_HOSTDEVICE Vec4() noexcept; // no initialization
507 
509  ATOMSMATH_HOSTDEVICE constexpr explicit Vec4 (T a) noexcept;
510 
512  ATOMSMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) noexcept;
513 
515  ATOMSMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) noexcept;
516 
518  template <class S> ATOMSMATH_HOSTDEVICE constexpr Vec4 (const Vec4<S>& v) noexcept;
519 
521  template <class S> ATOMSMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3<S>& v) noexcept;
522 
524  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& operator= (const Vec4& v) noexcept;
525 
527  ~Vec4() noexcept = default;
528 
530 
533 
535  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator== (const Vec4<S>& v) const noexcept;
536 
538  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator!= (const Vec4<S>& v) const noexcept;
539 
545  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError (const Vec4<T>& v, T e) const noexcept;
546 
552  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError (const Vec4<T>& v, T e) const noexcept;
553 
555  ATOMSMATH_HOSTDEVICE constexpr T dot (const Vec4& v) const noexcept;
556 
558  ATOMSMATH_HOSTDEVICE constexpr T operator^ (const Vec4& v) const noexcept;
559 
561  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& operator+= (const Vec4& v) noexcept;
562 
564  ATOMSMATH_HOSTDEVICE constexpr Vec4 operator+ (const Vec4& v) const noexcept;
565 
567  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& operator-= (const Vec4& v) noexcept;
568 
570  ATOMSMATH_HOSTDEVICE constexpr Vec4 operator- (const Vec4& v) const noexcept;
571 
573  ATOMSMATH_HOSTDEVICE constexpr Vec4 operator-() const noexcept;
574 
576  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& negate() noexcept;
577 
579  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& operator*= (const Vec4& v) noexcept;
580 
582  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& operator*= (T a) noexcept;
583 
585  ATOMSMATH_HOSTDEVICE constexpr Vec4 operator* (const Vec4& v) const noexcept;
586 
588  ATOMSMATH_HOSTDEVICE constexpr Vec4 operator* (T a) const noexcept;
589 
591  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& operator/= (const Vec4& v) noexcept;
592 
594  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4& operator/= (T a) noexcept;
595 
597  ATOMSMATH_HOSTDEVICE constexpr Vec4 operator/ (const Vec4& v) const noexcept;
598 
600  ATOMSMATH_HOSTDEVICE constexpr Vec4 operator/ (T a) const noexcept;
601 
603 
606 
608  ATOMSMATH_HOSTDEVICE T length() const noexcept;
609 
612  ATOMSMATH_HOSTDEVICE constexpr T length2() const noexcept;
613 
615  ATOMSMATH_HOSTDEVICE const Vec4& normalize() noexcept; // modifies *this
616 
618  const Vec4& normalizeExc();
619 
623  ATOMSMATH_HOSTDEVICE const Vec4& normalizeNonNull() noexcept;
624 
626  ATOMSMATH_HOSTDEVICE Vec4<T> normalized() const noexcept; // does not modify *this
627 
630  Vec4<T> normalizedExc() const;
631 
636  ATOMSMATH_HOSTDEVICE Vec4<T> normalizedNonNull() const noexcept;
637 
639 
642 
644  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeLowest() noexcept { return std::numeric_limits<T>::lowest(); }
645 
647  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeMax() noexcept { return std::numeric_limits<T>::max(); }
648 
650  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeSmallest() noexcept { return std::numeric_limits<T>::min(); }
651 
653  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeEpsilon() noexcept { return std::numeric_limits<T>::epsilon(); }
654 
656 
658  ATOMSMATH_HOSTDEVICE constexpr static unsigned int dimensions() noexcept { return 4; }
659 
662  typedef T BaseType;
663 
664  private:
665  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T lengthTiny() const noexcept;
666 };
667 
669 template <class T> std::ostream& operator<< (std::ostream& s, const Vec2<T>& v);
670 
672 template <class T> std::ostream& operator<< (std::ostream& s, const Vec3<T>& v);
673 
675 template <class T> std::ostream& operator<< (std::ostream& s, const Vec4<T>& v);
676 
678 template <class T> ATOMSMATH_HOSTDEVICE constexpr Vec2<T> operator* (T a, const Vec2<T>& v) noexcept;
679 
681 template <class T> ATOMSMATH_HOSTDEVICE constexpr Vec3<T> operator* (T a, const Vec3<T>& v) noexcept;
682 
684 template <class T> ATOMSMATH_HOSTDEVICE constexpr Vec4<T> operator* (T a, const Vec4<T>& v) noexcept;
685 
686 //-------------------------
687 // Typedefs for convenience
688 //-------------------------
689 
691 typedef Vec2<short> V2s;
692 
694 typedef Vec2<int> V2i;
695 typedef Vec2<int64_t> V2i64;
696 
698 typedef Vec2<float> V2f;
699 
701 typedef Vec2<double> V2d;
702 
704 typedef Vec3<short> V3s;
705 
707 typedef Vec3<int> V3i;
708 typedef Vec3<int64_t> V3i64;
709 
711 typedef Vec3<float> V3f;
712 
714 typedef Vec3<double> V3d;
715 
717 typedef Vec4<short> V4s;
718 
720 typedef Vec4<int> V4i;
721 typedef Vec4<int64_t> V4i64;
722 
724 typedef Vec4<float> V4f;
725 
727 typedef Vec4<double> V4d;
728 
729 //----------------------------------------------------------------------------
730 // Specializations for VecN<short>, VecN<int>
731 //
732 // Normalize and length don't make sense for integer vectors, so disable them.
733 //----------------------------------------------------------------------------
734 
735 // Vec2<short>
736 template <> short Vec2<short>::length() const noexcept = delete;
737 template <> const Vec2<short>& Vec2<short>::normalize() noexcept = delete;
738 template <> const Vec2<short>& Vec2<short>::normalizeExc() = delete;
739 template <> const Vec2<short>& Vec2<short>::normalizeNonNull() noexcept = delete;
740 template <> Vec2<short> Vec2<short>::normalized() const noexcept = delete;
741 template <> Vec2<short> Vec2<short>::normalizedExc() const = delete;
742 template <> Vec2<short> Vec2<short>::normalizedNonNull() const noexcept = delete;
743 
744 // Vec2<int>
745 template <> int Vec2<int>::length() const noexcept = delete;
746 template <> const Vec2<int>& Vec2<int>::normalize() noexcept = delete;
747 template <> const Vec2<int>& Vec2<int>::normalizeExc() = delete;
748 template <> const Vec2<int>& Vec2<int>::normalizeNonNull() noexcept = delete;
749 template <> Vec2<int> Vec2<int>::normalized() const noexcept = delete;
750 template <> Vec2<int> Vec2<int>::normalizedExc() const = delete;
751 template <> Vec2<int> Vec2<int>::normalizedNonNull() const noexcept = delete;
752 
753 // Vec3<short>
754 template <> short Vec3<short>::length() const noexcept = delete;
755 template <> const Vec3<short>& Vec3<short>::normalize() noexcept = delete;
756 template <> const Vec3<short>& Vec3<short>::normalizeExc() = delete;
757 template <> const Vec3<short>& Vec3<short>::normalizeNonNull() noexcept = delete;
758 template <> Vec3<short> Vec3<short>::normalized() const noexcept = delete;
759 template <> Vec3<short> Vec3<short>::normalizedExc() const = delete;
760 template <> Vec3<short> Vec3<short>::normalizedNonNull() const noexcept = delete;
761 
762 // Vec3<int>
763 template <> int Vec3<int>::length() const noexcept = delete;
764 template <> const Vec3<int>& Vec3<int>::normalize() noexcept = delete;
765 template <> const Vec3<int>& Vec3<int>::normalizeExc() = delete;
766 template <> const Vec3<int>& Vec3<int>::normalizeNonNull() noexcept = delete;
767 template <> Vec3<int> Vec3<int>::normalized() const noexcept = delete;
768 template <> Vec3<int> Vec3<int>::normalizedExc() const = delete;
769 template <> Vec3<int> Vec3<int>::normalizedNonNull() const noexcept = delete;
770 
771 // Vec4<short>
772 template <> short Vec4<short>::length() const noexcept = delete;
773 template <> const Vec4<short>& Vec4<short>::normalize() noexcept = delete;
774 template <> const Vec4<short>& Vec4<short>::normalizeExc() = delete;
775 template <> const Vec4<short>& Vec4<short>::normalizeNonNull() noexcept = delete;
776 template <> Vec4<short> Vec4<short>::normalized() const noexcept = delete;
777 template <> Vec4<short> Vec4<short>::normalizedExc() const = delete;
778 template <> Vec4<short> Vec4<short>::normalizedNonNull() const noexcept = delete;
779 
780 // Vec4<int>
781 template <> int Vec4<int>::length() const noexcept = delete;
782 template <> const Vec4<int>& Vec4<int>::normalize() noexcept = delete;
783 template <> const Vec4<int>& Vec4<int>::normalizeExc() = delete;
784 template <> const Vec4<int>& Vec4<int>::normalizeNonNull() noexcept = delete;
785 template <> Vec4<int> Vec4<int>::normalized() const noexcept = delete;
786 template <> Vec4<int> Vec4<int>::normalizedExc() const = delete;
787 template <> Vec4<int> Vec4<int>::normalizedNonNull() const noexcept = delete;
788 
789 //------------------------
790 // Implementation of Vec2:
791 //------------------------
792 
793 template <class T>
794 ATOMSMATH_CONSTEXPR14 inline T&
795 Vec2<T>::operator[] (int i) noexcept
796 {
797  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
798 }
799 
800 template <class T>
801 constexpr inline const T&
802 Vec2<T>::operator[] (int i) const noexcept
803 {
804  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
805 }
806 
807 template <class T> inline Vec2<T>::Vec2() noexcept
808 {
809  // empty, and not constexpr because data is uninitialized.
810 }
811 
812 template <class T> constexpr inline Vec2<T>::Vec2 (T a) noexcept
813  : x(a), y(a)
814 {
815 }
816 
817 template <class T> constexpr inline Vec2<T>::Vec2 (T a, T b) noexcept
818  : x(a), y(b)
819 {
820 }
821 
822 template <class T> constexpr inline Vec2<T>::Vec2 (const Vec2& v) noexcept
823  : x(v.x), y(v.y)
824 {
825 }
826 
827 template <class T> template <class S> constexpr inline Vec2<T>::Vec2 (const Vec2<S>& v) noexcept
828  : x(T(v.x)), y(T(v.y))
829 {
830 }
831 
832 template <class T>
833 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
834 Vec2<T>::operator= (const Vec2& v) noexcept
835 {
836  x = v.x;
837  y = v.y;
838  return *this;
839 }
840 
841 template <class T>
842 template <class S>
843 inline void
844 Vec2<T>::setValue (S a, S b) noexcept
845 {
846  x = T (a);
847  y = T (b);
848 }
849 
850 template <class T>
851 template <class S>
852 inline void
853 Vec2<T>::setValue (const Vec2<S>& v) noexcept
854 {
855  x = T (v.x);
856  y = T (v.y);
857 }
858 
859 template <class T>
860 template <class S>
861 inline void
862 Vec2<T>::getValue (S& a, S& b) const noexcept
863 {
864  a = S (x);
865  b = S (y);
866 }
867 
868 template <class T>
869 template <class S>
870 inline void
871 Vec2<T>::getValue (Vec2<S>& v) const noexcept
872 {
873  v.x = S (x);
874  v.y = S (y);
875 }
876 
877 template <class T>
878 inline T*
880 {
881  return (T*) &x;
882 }
883 
884 template <class T>
885 inline const T*
886 Vec2<T>::getValue() const noexcept
887 {
888  return (const T*) &x;
889 }
890 
891 template <class T>
892 template <class S>
893 constexpr inline bool
894 Vec2<T>::operator== (const Vec2<S>& v) const noexcept
895 {
896  return x == v.x && y == v.y;
897 }
898 
899 template <class T>
900 template <class S>
901 constexpr inline bool
902 Vec2<T>::operator!= (const Vec2<S>& v) const noexcept
903 {
904  return x != v.x || y != v.y;
905 }
906 
907 template <class T>
908 ATOMSMATH_CONSTEXPR14 inline bool
909 Vec2<T>::equalWithAbsError (const Vec2<T>& v, T e) const noexcept
910 {
911  for (int i = 0; i < 2; i++)
912  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e))
913  return false;
914 
915  return true;
916 }
917 
918 template <class T>
919 ATOMSMATH_CONSTEXPR14 inline bool
920 Vec2<T>::equalWithRelError (const Vec2<T>& v, T e) const noexcept
921 {
922  for (int i = 0; i < 2; i++)
923  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e))
924  return false;
925 
926  return true;
927 }
928 
929 template <class T>
930 constexpr inline T
931 Vec2<T>::dot (const Vec2& v) const noexcept
932 {
933  return x * v.x + y * v.y;
934 }
935 
936 template <class T>
937 constexpr inline T
938 Vec2<T>::operator^ (const Vec2& v) const noexcept
939 {
940  return dot (v);
941 }
942 
943 template <class T>
944 constexpr inline T
945 Vec2<T>::cross (const Vec2& v) const noexcept
946 {
947  return x * v.y - y * v.x;
948 }
949 
950 template <class T>
951 constexpr inline T
952 Vec2<T>::operator% (const Vec2& v) const noexcept
953 {
954  return x * v.y - y * v.x;
955 }
956 
957 template <class T>
958 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
959 Vec2<T>::operator+= (const Vec2& v) noexcept
960 {
961  x += v.x;
962  y += v.y;
963  return *this;
964 }
965 
966 template <class T>
967 constexpr inline Vec2<T>
968 Vec2<T>::operator+ (const Vec2& v) const noexcept
969 {
970  return Vec2 (x + v.x, y + v.y);
971 }
972 
973 template <class T>
974 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
975 Vec2<T>::operator-= (const Vec2& v) noexcept
976 {
977  x -= v.x;
978  y -= v.y;
979  return *this;
980 }
981 
982 template <class T>
983 constexpr inline Vec2<T>
984 Vec2<T>::operator- (const Vec2& v) const noexcept
985 {
986  return Vec2 (x - v.x, y - v.y);
987 }
988 
989 template <class T>
990 constexpr inline Vec2<T>
991 Vec2<T>::operator-() const noexcept
992 {
993  return Vec2 (-x, -y);
994 }
995 
996 template <class T>
997 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
998 Vec2<T>::negate() noexcept
999 {
1000  x = -x;
1001  y = -y;
1002  return *this;
1003 }
1004 
1005 template <class T>
1006 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
1007 Vec2<T>::operator*= (const Vec2& v) noexcept
1008 {
1009  x *= v.x;
1010  y *= v.y;
1011  return *this;
1012 }
1013 
1014 template <class T>
1015 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
1017 {
1018  x *= a;
1019  y *= a;
1020  return *this;
1021 }
1022 
1023 template <class T>
1024 constexpr inline Vec2<T>
1025 Vec2<T>::operator* (const Vec2& v) const noexcept
1026 {
1027  return Vec2 (x * v.x, y * v.y);
1028 }
1029 
1030 template <class T>
1031 constexpr inline Vec2<T>
1032 Vec2<T>::operator* (T a) const noexcept
1033 {
1034  return Vec2 (x * a, y * a);
1035 }
1036 
1037 template <class T>
1038 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
1039 Vec2<T>::operator/= (const Vec2& v) noexcept
1040 {
1041  x /= v.x;
1042  y /= v.y;
1043  return *this;
1044 }
1045 
1046 template <class T>
1047 ATOMSMATH_CONSTEXPR14 inline const Vec2<T>&
1049 {
1050  x /= a;
1051  y /= a;
1052  return *this;
1053 }
1054 
1055 template <class T>
1056 constexpr inline Vec2<T>
1057 Vec2<T>::operator/ (const Vec2& v) const noexcept
1058 {
1059  return Vec2 (x / v.x, y / v.y);
1060 }
1061 
1062 template <class T>
1063 constexpr inline Vec2<T>
1064 Vec2<T>::operator/ (T a) const noexcept
1065 {
1066  return Vec2 (x / a, y / a);
1067 }
1068 
1069 template <class T>
1070 ATOMSMATH_CONSTEXPR14 inline T
1071 Vec2<T>::lengthTiny() const noexcept
1072 {
1073  T absX = std::abs(x);
1074  T absY = std::abs(y);
1075 
1076  T max = absX;
1077 
1078  if (max < absY)
1079  max = absY;
1080 
1081  if (ATOMSMATH_UNLIKELY(max == T (0)))
1082  return T (0);
1083 
1084  //
1085  // Do not replace the divisions by max with multiplications by 1/max.
1086  // Computing 1/max can overflow but the divisions below will always
1087  // produce results less than or equal to 1.
1088  //
1089 
1090  absX /= max;
1091  absY /= max;
1092 
1093  return max * std::sqrt (absX * absX + absY * absY);
1094 }
1095 
1096 template <class T>
1097 inline T
1098 Vec2<T>::length() const noexcept
1099 {
1100  T length2 = dot (*this);
1101 
1102  if (ATOMSMATH_UNLIKELY(length2 < T (2) * std::numeric_limits<T>::min()))
1103  return lengthTiny();
1104 
1105  return std::sqrt (length2);
1106 }
1107 
1108 template <class T>
1109 constexpr inline T
1110 Vec2<T>::length2() const noexcept
1111 {
1112  return dot (*this);
1113 }
1114 
1115 template <class T>
1116 inline const Vec2<T>&
1118 {
1119  T l = length();
1120 
1121  if (ATOMSMATH_LIKELY(l != T (0)))
1122  {
1123  //
1124  // Do not replace the divisions by l with multiplications by 1/l.
1125  // Computing 1/l can overflow but the divisions below will always
1126  // produce results less than or equal to 1.
1127  //
1128 
1129  x /= l;
1130  y /= l;
1131  }
1132 
1133  return *this;
1134 }
1135 
1136 template <class T>
1137 inline const Vec2<T>&
1139 {
1140  T l = length();
1141 
1142  #ifdef ATOMS_USE_EXCEPTIONS
1143  if (ATOMSMATH_UNLIKELY(l == T (0)))
1144  throw std::domain_error ("Cannot normalize null vector.");
1145  #endif
1146  x /= l;
1147  y /= l;
1148  return *this;
1149 }
1150 
1151 template <class T>
1152 inline const Vec2<T>&
1154 {
1155  T l = length();
1156  x /= l;
1157  y /= l;
1158  return *this;
1159 }
1160 
1161 template <class T>
1162 inline Vec2<T>
1163 Vec2<T>::normalized() const noexcept
1164 {
1165  T l = length();
1166 
1167  if (ATOMSMATH_UNLIKELY(l == T (0)))
1168  return Vec2 (T (0));
1169 
1170  return Vec2 (x / l, y / l);
1171 }
1172 
1173 template <class T>
1174 inline Vec2<T>
1176 {
1177  T l = length();
1178  #ifdef ATOMS_USE_EXCEPTIONS
1179  if (ATOMSMATH_UNLIKELY(l == T (0)))
1180  throw std::domain_error ("Cannot normalize null vector.");
1181  #endif
1182  return Vec2 (x / l, y / l);
1183 }
1184 
1185 template <class T>
1186 inline Vec2<T>
1188 {
1189  T l = length();
1190  return Vec2 (x / l, y / l);
1191 }
1192 
1193 //-----------------------
1194 // Implementation of Vec3
1195 //-----------------------
1196 
1197 template <class T>
1198 ATOMSMATH_CONSTEXPR14 inline T&
1199 Vec3<T>::operator[] (int i) noexcept
1200 {
1201  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1202 }
1203 
1204 template <class T>
1205 constexpr inline const T&
1206 Vec3<T>::operator[] (int i) const noexcept
1207 {
1208  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1209 }
1210 
1211 template <class T> inline Vec3<T>::Vec3() noexcept
1212 {
1213  // empty, and not constexpr because data is uninitialized.
1214 }
1215 
1216 template <class T> constexpr inline Vec3<T>::Vec3 (T a) noexcept
1217  : x(a), y(a), z(a)
1218 {
1219 }
1220 
1221 template <class T> constexpr inline Vec3<T>::Vec3 (T a, T b, T c) noexcept
1222  : x(a), y(b), z(c)
1223 {
1224 }
1225 
1226 template <class T> constexpr inline Vec3<T>::Vec3 (const Vec3& v) noexcept
1227  : x(v.x), y(v.y), z(v.z)
1228 {
1229 }
1230 
1231 template <class T> template <class S> constexpr inline Vec3<T>::Vec3 (const Vec3<S>& v) noexcept
1232  : x(T(v.x)), y(T(v.y)), z(T(v.z))
1233 {
1234 }
1235 
1236 template <class T>
1237 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1238 Vec3<T>::operator= (const Vec3& v) noexcept
1239 {
1240  x = v.x;
1241  y = v.y;
1242  z = v.z;
1243  return *this;
1244 }
1245 
1246 template <class T> template <class S> constexpr inline Vec3<T>::Vec3 (const Vec4<S>& v) noexcept
1247  : x(T(v.x/v.w)), y(T(v.y/v.w)), z(T(v.z/v.w))
1248 {
1249 }
1250 
1251 template <class T>
1252 template <class S>
1253 ATOMSMATH_CONSTEXPR14 inline Vec3<T>::Vec3 (const Vec4<S>& v, InfException)
1254 {
1255  T vx = T (v.x);
1256  T vy = T (v.y);
1257  T vz = T (v.z);
1258  T vw = T (v.w);
1259 
1260  T absW = (vw >= T (0)) ? vw : -vw;
1261 
1262  if (absW < 1)
1263  {
1264  T m = baseTypeMax() * absW;
1265 #ifdef ATOMS_USE_EXCEPTIONS
1266  if (vx <= -m || vx >= m || vy <= -m || vy >= m || vz <= -m || vz >= m)
1267  throw std::domain_error ("Cannot normalize point at infinity.");
1268 #endif
1269  }
1270 
1271  x = vx / vw;
1272  y = vy / vw;
1273  z = vz / vw;
1274 }
1275 
1276 template <class T>
1277 template <class S>
1278 inline void
1279 Vec3<T>::setValue (S a, S b, S c) noexcept
1280 {
1281  x = T (a);
1282  y = T (b);
1283  z = T (c);
1284 }
1285 
1286 template <class T>
1287 template <class S>
1288 inline void
1289 Vec3<T>::setValue (const Vec3<S>& v) noexcept
1290 {
1291  x = T (v.x);
1292  y = T (v.y);
1293  z = T (v.z);
1294 }
1295 
1296 template <class T>
1297 template <class S>
1298 inline void
1299 Vec3<T>::getValue (S& a, S& b, S& c) const noexcept
1300 {
1301  a = S (x);
1302  b = S (y);
1303  c = S (z);
1304 }
1305 
1306 template <class T>
1307 template <class S>
1308 inline void
1309 Vec3<T>::getValue (Vec3<S>& v) const noexcept
1310 {
1311  v.x = S (x);
1312  v.y = S (y);
1313  v.z = S (z);
1314 }
1315 
1316 template <class T>
1317 inline T*
1319 {
1320  return (T*) &x;
1321 }
1322 
1323 template <class T>
1324 inline const T*
1325 Vec3<T>::getValue() const noexcept
1326 {
1327  return (const T*) &x;
1328 }
1329 
1330 template <class T>
1331 template <class S>
1332 constexpr inline bool
1333 Vec3<T>::operator== (const Vec3<S>& v) const noexcept
1334 {
1335  return x == v.x && y == v.y && z == v.z;
1336 }
1337 
1338 template <class T>
1339 template <class S>
1340 constexpr inline bool
1341 Vec3<T>::operator!= (const Vec3<S>& v) const noexcept
1342 {
1343  return x != v.x || y != v.y || z != v.z;
1344 }
1345 
1346 template <class T>
1347 ATOMSMATH_CONSTEXPR14 inline bool
1348 Vec3<T>::equalWithAbsError (const Vec3<T>& v, T e) const noexcept
1349 {
1350  for (int i = 0; i < 3; i++)
1351  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e))
1352  return false;
1353 
1354  return true;
1355 }
1356 
1357 template <class T>
1358 ATOMSMATH_CONSTEXPR14 inline bool
1359 Vec3<T>::equalWithRelError (const Vec3<T>& v, T e) const noexcept
1360 {
1361  for (int i = 0; i < 3; i++)
1362  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e))
1363  return false;
1364 
1365  return true;
1366 }
1367 
1368 template <class T>
1369 constexpr inline T
1370 Vec3<T>::dot (const Vec3& v) const noexcept
1371 {
1372  return x * v.x + y * v.y + z * v.z;
1373 }
1374 
1375 template <class T>
1376 constexpr inline T
1377 Vec3<T>::operator^ (const Vec3& v) const noexcept
1378 {
1379  return dot (v);
1380 }
1381 
1382 template <class T>
1383 constexpr inline Vec3<T>
1384 Vec3<T>::cross (const Vec3& v) const noexcept
1385 {
1386  return Vec3 (y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
1387 }
1388 
1389 template <class T>
1390 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1391 Vec3<T>::operator%= (const Vec3& v) noexcept
1392 {
1393  T a = y * v.z - z * v.y;
1394  T b = z * v.x - x * v.z;
1395  T c = x * v.y - y * v.x;
1396  x = a;
1397  y = b;
1398  z = c;
1399  return *this;
1400 }
1401 
1402 template <class T>
1403 constexpr inline Vec3<T>
1404 Vec3<T>::operator% (const Vec3& v) const noexcept
1405 {
1406  return Vec3 (y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
1407 }
1408 
1409 template <class T>
1410 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1411 Vec3<T>::operator+= (const Vec3& v) noexcept
1412 {
1413  x += v.x;
1414  y += v.y;
1415  z += v.z;
1416  return *this;
1417 }
1418 
1419 template <class T>
1420 constexpr inline Vec3<T>
1421 Vec3<T>::operator+ (const Vec3& v) const noexcept
1422 {
1423  return Vec3 (x + v.x, y + v.y, z + v.z);
1424 }
1425 
1426 template <class T>
1427 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1428 Vec3<T>::operator-= (const Vec3& v) noexcept
1429 {
1430  x -= v.x;
1431  y -= v.y;
1432  z -= v.z;
1433  return *this;
1434 }
1435 
1436 template <class T>
1437 constexpr inline Vec3<T>
1438 Vec3<T>::operator- (const Vec3& v) const noexcept
1439 {
1440  return Vec3 (x - v.x, y - v.y, z - v.z);
1441 }
1442 
1443 template <class T>
1444 constexpr inline Vec3<T>
1445 Vec3<T>::operator-() const noexcept
1446 {
1447  return Vec3 (-x, -y, -z);
1448 }
1449 
1450 template <class T>
1451 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1453 {
1454  x = -x;
1455  y = -y;
1456  z = -z;
1457  return *this;
1458 }
1459 
1460 template <class T>
1461 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1462 Vec3<T>::operator*= (const Vec3& v) noexcept
1463 {
1464  x *= v.x;
1465  y *= v.y;
1466  z *= v.z;
1467  return *this;
1468 }
1469 
1470 template <class T>
1471 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1473 {
1474  x *= a;
1475  y *= a;
1476  z *= a;
1477  return *this;
1478 }
1479 
1480 template <class T>
1481 constexpr inline Vec3<T>
1482 Vec3<T>::operator* (const Vec3& v) const noexcept
1483 {
1484  return Vec3 (x * v.x, y * v.y, z * v.z);
1485 }
1486 
1487 template <class T>
1488 constexpr inline Vec3<T>
1489 Vec3<T>::operator* (T a) const noexcept
1490 {
1491  return Vec3 (x * a, y * a, z * a);
1492 }
1493 
1494 template <class T>
1495 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1496 Vec3<T>::operator/= (const Vec3& v) noexcept
1497 {
1498  x /= v.x;
1499  y /= v.y;
1500  z /= v.z;
1501  return *this;
1502 }
1503 
1504 template <class T>
1505 ATOMSMATH_CONSTEXPR14 inline const Vec3<T>&
1507 {
1508  x /= a;
1509  y /= a;
1510  z /= a;
1511  return *this;
1512 }
1513 
1514 template <class T>
1515 constexpr inline Vec3<T>
1516 Vec3<T>::operator/ (const Vec3& v) const noexcept
1517 {
1518  return Vec3 (x / v.x, y / v.y, z / v.z);
1519 }
1520 
1521 template <class T>
1522 constexpr inline Vec3<T>
1523 Vec3<T>::operator/ (T a) const noexcept
1524 {
1525  return Vec3 (x / a, y / a, z / a);
1526 }
1527 
1528 template <class T>
1529 ATOMSMATH_CONSTEXPR14 inline T
1530 Vec3<T>::lengthTiny() const noexcept
1531 {
1532  T absX = (x >= T (0)) ? x : -x;
1533  T absY = (y >= T (0)) ? y : -y;
1534  T absZ = (z >= T (0)) ? z : -z;
1535 
1536  T max = absX;
1537 
1538  if (max < absY)
1539  max = absY;
1540 
1541  if (max < absZ)
1542  max = absZ;
1543 
1544  if (ATOMSMATH_UNLIKELY(max == T (0)))
1545  return T (0);
1546 
1547  //
1548  // Do not replace the divisions by max with multiplications by 1/max.
1549  // Computing 1/max can overflow but the divisions below will always
1550  // produce results less than or equal to 1.
1551  //
1552 
1553  absX /= max;
1554  absY /= max;
1555  absZ /= max;
1556 
1557  return max * std::sqrt (absX * absX + absY * absY + absZ * absZ);
1558 }
1559 
1560 template <class T>
1561 inline T
1562 Vec3<T>::length() const noexcept
1563 {
1564  T length2 = dot (*this);
1565 
1566  if (ATOMSMATH_UNLIKELY(length2 < T (2) * std::numeric_limits<T>::min()))
1567  return lengthTiny();
1568 
1569  return std::sqrt (length2);
1570 }
1571 
1572 template <class T>
1573 constexpr inline T
1574 Vec3<T>::length2() const noexcept
1575 {
1576  return dot (*this);
1577 }
1578 
1579 template <class T>
1580 inline const Vec3<T>&
1582 {
1583  T l = length();
1584 
1585  if (ATOMSMATH_LIKELY(l != T (0)))
1586  {
1587  //
1588  // Do not replace the divisions by l with multiplications by 1/l.
1589  // Computing 1/l can overflow but the divisions below will always
1590  // produce results less than or equal to 1.
1591  //
1592 
1593  x /= l;
1594  y /= l;
1595  z /= l;
1596  }
1597 
1598  return *this;
1599 }
1600 
1601 template <class T>
1602 inline const Vec3<T>&
1604 {
1605  T l = length();
1606 #ifdef ATOMS_USE_EXCEPTIONS
1607  if (ATOMSMATH_UNLIKELY(l == T (0)))
1608  throw std::domain_error ("Cannot normalize null vector.");
1609 #endif
1610  x /= l;
1611  y /= l;
1612  z /= l;
1613  return *this;
1614 }
1615 
1616 template <class T>
1617 inline const Vec3<T>&
1619 {
1620  T l = length();
1621  x /= l;
1622  y /= l;
1623  z /= l;
1624  return *this;
1625 }
1626 
1627 template <class T>
1628 inline Vec3<T>
1629 Vec3<T>::normalized() const noexcept
1630 {
1631  T l = length();
1632 
1633  if (ATOMSMATH_UNLIKELY((l == T (0))))
1634  return Vec3 (T (0));
1635 
1636  return Vec3 (x / l, y / l, z / l);
1637 }
1638 
1639 template <class T>
1640 inline Vec3<T>
1642 {
1643  T l = length();
1644 #ifdef ATOMS_USE_EXCEPTIONS
1645  if (ATOMSMATH_UNLIKELY(l == T (0)))
1646  throw std::domain_error ("Cannot normalize null vector.");
1647 #endif
1648  return Vec3 (x / l, y / l, z / l);
1649 }
1650 
1651 template <class T>
1652 inline Vec3<T>
1654 {
1655  T l = length();
1656  return Vec3 (x / l, y / l, z / l);
1657 }
1658 
1659 //-----------------------
1660 // Implementation of Vec4
1661 //-----------------------
1662 
1663 template <class T>
1664 ATOMSMATH_CONSTEXPR14 inline T&
1665 Vec4<T>::operator[] (int i) noexcept
1666 {
1667  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1668 }
1669 
1670 template <class T>
1671 constexpr inline const T&
1672 Vec4<T>::operator[] (int i) const noexcept
1673 {
1674  return (&x)[i]; // NOSONAR - suppress SonarCloud bug report.
1675 }
1676 
1677 template <class T> inline Vec4<T>::Vec4() noexcept
1678 {
1679  // empty, and not constexpr because data is uninitialized.
1680 }
1681 
1682 template <class T> constexpr inline Vec4<T>::Vec4 (T a) noexcept
1683  : x(a), y(a), z(a), w(a)
1684 {
1685 }
1686 
1687 template <class T> constexpr inline Vec4<T>::Vec4 (T a, T b, T c, T d) noexcept
1688  : x(a), y(b), z(c), w(d)
1689 {
1690 }
1691 
1692 template <class T> constexpr inline Vec4<T>::Vec4 (const Vec4& v) noexcept
1693  : x(v.x), y(v.y), z(v.z), w(v.w)
1694 {
1695 }
1696 
1697 template <class T> template <class S> constexpr inline Vec4<T>::Vec4 (const Vec4<S>& v) noexcept
1698  : x(T(v.x)), y(T(v.y)), z(T(v.z)), w(T(v.w))
1699 {
1700 }
1701 
1702 template <class T>
1703 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1704 Vec4<T>::operator= (const Vec4& v) noexcept
1705 {
1706  x = v.x;
1707  y = v.y;
1708  z = v.z;
1709  w = v.w;
1710  return *this;
1711 }
1712 
1713 template <class T> template <class S> constexpr inline Vec4<T>::Vec4 (const Vec3<S>& v) noexcept
1714  : x(T(v.x)), y(T(v.y)), z(T(v.z)), w(T(1))
1715 {
1716 }
1717 
1718 template <class T>
1719 template <class S>
1720 constexpr inline bool
1721 Vec4<T>::operator== (const Vec4<S>& v) const noexcept
1722 {
1723  return x == v.x && y == v.y && z == v.z && w == v.w;
1724 }
1725 
1726 template <class T>
1727 template <class S>
1728 constexpr inline bool
1729 Vec4<T>::operator!= (const Vec4<S>& v) const noexcept
1730 {
1731  return x != v.x || y != v.y || z != v.z || w != v.w;
1732 }
1733 
1734 template <class T>
1735 ATOMSMATH_CONSTEXPR14 inline bool
1736 Vec4<T>::equalWithAbsError (const Vec4<T>& v, T e) const noexcept
1737 {
1738  for (int i = 0; i < 4; i++)
1739  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e))
1740  return false;
1741 
1742  return true;
1743 }
1744 
1745 template <class T>
1746 ATOMSMATH_CONSTEXPR14 inline bool
1747 Vec4<T>::equalWithRelError (const Vec4<T>& v, T e) const noexcept
1748 {
1749  for (int i = 0; i < 4; i++)
1750  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e))
1751  return false;
1752 
1753  return true;
1754 }
1755 
1756 template <class T>
1757 constexpr inline T
1758 Vec4<T>::dot (const Vec4& v) const noexcept
1759 {
1760  return x * v.x + y * v.y + z * v.z + w * v.w;
1761 }
1762 
1763 template <class T>
1764 constexpr inline T
1765 Vec4<T>::operator^ (const Vec4& v) const noexcept
1766 {
1767  return dot (v);
1768 }
1769 
1770 template <class T>
1771 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1772 Vec4<T>::operator+= (const Vec4& v) noexcept
1773 {
1774  x += v.x;
1775  y += v.y;
1776  z += v.z;
1777  w += v.w;
1778  return *this;
1779 }
1780 
1781 template <class T>
1782 constexpr inline Vec4<T>
1783 Vec4<T>::operator+ (const Vec4& v) const noexcept
1784 {
1785  return Vec4 (x + v.x, y + v.y, z + v.z, w + v.w);
1786 }
1787 
1788 template <class T>
1789 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1790 Vec4<T>::operator-= (const Vec4& v) noexcept
1791 {
1792  x -= v.x;
1793  y -= v.y;
1794  z -= v.z;
1795  w -= v.w;
1796  return *this;
1797 }
1798 
1799 template <class T>
1800 constexpr inline Vec4<T>
1801 Vec4<T>::operator- (const Vec4& v) const noexcept
1802 {
1803  return Vec4 (x - v.x, y - v.y, z - v.z, w - v.w);
1804 }
1805 
1806 template <class T>
1807 constexpr inline Vec4<T>
1808 Vec4<T>::operator-() const noexcept
1809 {
1810  return Vec4 (-x, -y, -z, -w);
1811 }
1812 
1813 template <class T>
1814 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1816 {
1817  x = -x;
1818  y = -y;
1819  z = -z;
1820  w = -w;
1821  return *this;
1822 }
1823 
1824 template <class T>
1825 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1826 Vec4<T>::operator*= (const Vec4& v) noexcept
1827 {
1828  x *= v.x;
1829  y *= v.y;
1830  z *= v.z;
1831  w *= v.w;
1832  return *this;
1833 }
1834 
1835 template <class T>
1836 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1838 {
1839  x *= a;
1840  y *= a;
1841  z *= a;
1842  w *= a;
1843  return *this;
1844 }
1845 
1846 template <class T>
1847 constexpr inline Vec4<T>
1848 Vec4<T>::operator* (const Vec4& v) const noexcept
1849 {
1850  return Vec4 (x * v.x, y * v.y, z * v.z, w * v.w);
1851 }
1852 
1853 template <class T>
1854 constexpr inline Vec4<T>
1855 Vec4<T>::operator* (T a) const noexcept
1856 {
1857  return Vec4 (x * a, y * a, z * a, w * a);
1858 }
1859 
1860 template <class T>
1861 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1862 Vec4<T>::operator/= (const Vec4& v) noexcept
1863 {
1864  x /= v.x;
1865  y /= v.y;
1866  z /= v.z;
1867  w /= v.w;
1868  return *this;
1869 }
1870 
1871 template <class T>
1872 ATOMSMATH_CONSTEXPR14 inline const Vec4<T>&
1874 {
1875  x /= a;
1876  y /= a;
1877  z /= a;
1878  w /= a;
1879  return *this;
1880 }
1881 
1882 template <class T>
1883 constexpr inline Vec4<T>
1884 Vec4<T>::operator/ (const Vec4& v) const noexcept
1885 {
1886  return Vec4 (x / v.x, y / v.y, z / v.z, w / v.w);
1887 }
1888 
1889 template <class T>
1890 constexpr inline Vec4<T>
1891 Vec4<T>::operator/ (T a) const noexcept
1892 {
1893  return Vec4 (x / a, y / a, z / a, w / a);
1894 }
1895 
1896 template <class T>
1897 ATOMSMATH_CONSTEXPR14 inline T
1898 Vec4<T>::lengthTiny() const noexcept
1899 {
1900  T absX = (x >= T (0)) ? x : -x;
1901  T absY = (y >= T (0)) ? y : -y;
1902  T absZ = (z >= T (0)) ? z : -z;
1903  T absW = (w >= T (0)) ? w : -w;
1904 
1905  T max = absX;
1906 
1907  if (max < absY)
1908  max = absY;
1909 
1910  if (max < absZ)
1911  max = absZ;
1912 
1913  if (max < absW)
1914  max = absW;
1915 
1916  if (ATOMSMATH_UNLIKELY(max == T (0)))
1917  return T (0);
1918 
1919  //
1920  // Do not replace the divisions by max with multiplications by 1/max.
1921  // Computing 1/max can overflow but the divisions below will always
1922  // produce results less than or equal to 1.
1923  //
1924 
1925  absX /= max;
1926  absY /= max;
1927  absZ /= max;
1928  absW /= max;
1929 
1930  return max * std::sqrt (absX * absX + absY * absY + absZ * absZ + absW * absW);
1931 }
1932 
1933 template <class T>
1934 inline T
1935 Vec4<T>::length() const noexcept
1936 {
1937  T length2 = dot (*this);
1938 
1939  if (ATOMSMATH_UNLIKELY(length2 < T (2) * std::numeric_limits<T>::min()))
1940  return lengthTiny();
1941 
1942  return std::sqrt (length2);
1943 }
1944 
1945 template <class T>
1946 constexpr inline T
1947 Vec4<T>::length2() const noexcept
1948 {
1949  return dot (*this);
1950 }
1951 
1952 template <class T>
1953 const inline Vec4<T>&
1955 {
1956  T l = length();
1957 
1958  if (ATOMSMATH_LIKELY(l != T (0)))
1959  {
1960  //
1961  // Do not replace the divisions by l with multiplications by 1/l.
1962  // Computing 1/l can overflow but the divisions below will always
1963  // produce results less than or equal to 1.
1964  //
1965 
1966  x /= l;
1967  y /= l;
1968  z /= l;
1969  w /= l;
1970  }
1971 
1972  return *this;
1973 }
1974 
1975 template <class T>
1976 const inline Vec4<T>&
1978 {
1979  T l = length();
1980 #ifdef ATOMS_USE_EXCEPTIONS
1981  if (ATOMSMATH_UNLIKELY(l == T (0)))
1982  throw std::domain_error ("Cannot normalize null vector.");
1983 #endif
1984  x /= l;
1985  y /= l;
1986  z /= l;
1987  w /= l;
1988  return *this;
1989 }
1990 
1991 template <class T>
1992 inline const Vec4<T>&
1994 {
1995  T l = length();
1996  x /= l;
1997  y /= l;
1998  z /= l;
1999  w /= l;
2000  return *this;
2001 }
2002 
2003 template <class T>
2004 inline Vec4<T>
2005 Vec4<T>::normalized() const noexcept
2006 {
2007  T l = length();
2008 
2009  if (ATOMSMATH_UNLIKELY(l == T (0)))
2010  return Vec4 (T (0));
2011 
2012  return Vec4 (x / l, y / l, z / l, w / l);
2013 }
2014 
2015 template <class T>
2016 inline Vec4<T>
2018 {
2019  T l = length();
2020 #ifdef ATOMS_USE_EXCEPTIONS
2021  if (ATOMSMATH_UNLIKELY(l == T (0)))
2022  throw std::domain_error ("Cannot normalize null vector.");
2023 #endif
2024  return Vec4 (x / l, y / l, z / l, w / l);
2025 }
2026 
2027 template <class T>
2028 inline Vec4<T>
2030 {
2031  T l = length();
2032  return Vec4 (x / l, y / l, z / l, w / l);
2033 }
2034 
2035 //-----------------------------
2036 // Stream output implementation
2037 //-----------------------------
2038 
2039 template <class T>
2040 std::ostream&
2041 operator<< (std::ostream& s, const Vec2<T>& v)
2042 {
2043  return s << '(' << v.x << ", " << v.y << ')';
2044 }
2045 
2046 template <class T>
2047 std::ostream&
2048 operator<< (std::ostream& s, const Vec3<T>& v)
2049 {
2050  return s << '(' << v.x << ", " << v.y << ", " << v.z << ')';
2051 }
2052 
2053 template <class T>
2054 std::ostream&
2055 operator<< (std::ostream& s, const Vec4<T>& v)
2056 {
2057  return s << '(' << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ')';
2058 }
2059 
2060 //-----------------------------------------
2061 // Implementation of reverse multiplication
2062 //-----------------------------------------
2063 
2064 template <class T>
2065 constexpr inline Vec2<T>
2066 operator* (T a, const Vec2<T>& v) noexcept
2067 {
2068  return Vec2<T> (a * v.x, a * v.y);
2069 }
2070 
2071 template <class T>
2072 constexpr inline Vec3<T>
2073 operator* (T a, const Vec3<T>& v) noexcept
2074 {
2075  return Vec3<T> (a * v.x, a * v.y, a * v.z);
2076 }
2077 
2078 template <class T>
2079 constexpr inline Vec4<T>
2080 operator* (T a, const Vec4<T>& v) noexcept
2081 {
2082  return Vec4<T> (a * v.x, a * v.y, a * v.z, a * v.w);
2083 }
2084 
2085 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
2086 # pragma warning(pop)
2087 #endif
2088 
2089 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_EXIT
2090 
2091 #endif // INCLUDED_ATOMSMATHVEC_H
Definition: ImathVec.h:43
constexpr ATOMSMATH_HOSTDEVICE T dot(const Vec2 &v) const noexcept
Dot product.
Definition: ImathVec.h:931
ATOMSMATH_HOSTDEVICE const Vec2 & normalize() noexcept
Normalize in place. If length()==0, return a null vector.
Definition: ImathVec.h:1117
constexpr ATOMSMATH_HOSTDEVICE T operator^(const Vec2 &v) const noexcept
Dot product.
Definition: ImathVec.h:938
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError(const Vec2< T > &v, T e) const noexcept
Definition: ImathVec.h:920
ATOMSMATH_HOSTDEVICE Vec2< T > normalizedNonNull() const noexcept
Definition: ImathVec.h:1187
ATOMSMATH_HOSTDEVICE const Vec2 & normalizeNonNull() noexcept
Definition: ImathVec.h:1153
ATOMSMATH_HOSTDEVICE Vec2< T > normalized() const noexcept
Return a normalized vector. Does not modify *this.
Definition: ImathVec.h:1163
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2 & operator=(const Vec2 &v) noexcept
Assignment.
Definition: ImathVec.h:834
constexpr ATOMSMATH_HOSTDEVICE T length2() const noexcept
Definition: ImathVec.h:1110
constexpr ATOMSMATH_HOSTDEVICE T cross(const Vec2 &v) const noexcept
Definition: ImathVec.h:945
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError(const Vec2< T > &v, T e) const noexcept
Definition: ImathVec.h:909
T BaseType
Definition: ImathVec.h:248
Vec2< T > normalizedExc() const
Definition: ImathVec.h:1175
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2 & operator-=(const Vec2 &v) noexcept
Component-wise subtraction.
Definition: ImathVec.h:975
constexpr ATOMSMATH_HOSTDEVICE Vec2 operator*(const Vec2 &v) const noexcept
Component-wise multiplication.
Definition: ImathVec.h:1025
~Vec2() noexcept=default
Destructor.
constexpr ATOMSMATH_HOSTDEVICE Vec2 operator-() const noexcept
Component-wise multiplication by -1.
Definition: ImathVec.h:991
constexpr ATOMSMATH_HOSTDEVICE bool operator==(const Vec2< S > &v) const noexcept
Equality.
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2 & operator*=(const Vec2 &v) noexcept
Component-wise multiplication.
Definition: ImathVec.h:1007
constexpr ATOMSMATH_HOSTDEVICE Vec2 operator+(const Vec2 &v) const noexcept
Component-wise addition.
Definition: ImathVec.h:968
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeLowest() noexcept
Largest possible negative value.
Definition: ImathVec.h:230
ATOMSMATH_HOSTDEVICE T length() const noexcept
Return the Euclidean norm.
Definition: ImathVec.h:1098
constexpr ATOMSMATH_HOSTDEVICE bool operator!=(const Vec2< S > &v) const noexcept
Inequality.
constexpr static ATOMSMATH_HOSTDEVICE unsigned int dimensions() noexcept
Return the number of dimensions, i.e. 2.
Definition: ImathVec.h:244
constexpr ATOMSMATH_HOSTDEVICE Vec2(const Vec2< S > &v) noexcept
Construct from Vec2 of another base type.
constexpr ATOMSMATH_HOSTDEVICE Vec2 operator/(const Vec2 &v) const noexcept
Component-wise division.
Definition: ImathVec.h:1057
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeMax() noexcept
Largest possible positive value.
Definition: ImathVec.h:233
ATOMSMATH_HOSTDEVICE Vec2() noexcept
Uninitialized by default.
Definition: ImathVec.h:807
ATOMSMATH_HOSTDEVICE T * getValue() noexcept
Return a raw pointer to the array of values.
Definition: ImathVec.h:879
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2 & negate() noexcept
Component-wise multiplication by -1.
Definition: ImathVec.h:998
constexpr ATOMSMATH_HOSTDEVICE T operator%(const Vec2 &v) const noexcept
Definition: ImathVec.h:952
const Vec2 & normalizeExc()
Normalize in place. If length()==0, throw an exception.
Definition: ImathVec.h:1138
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2 & operator/=(const Vec2 &v) noexcept
Component-wise division.
Definition: ImathVec.h:1039
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T & operator[](int i) noexcept
Element access by index.
Definition: ImathVec.h:795
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeEpsilon() noexcept
Smallest possible e for which 1+e != 1.
Definition: ImathVec.h:239
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec2 & operator+=(const Vec2 &v) noexcept
Component-wise addition.
Definition: ImathVec.h:959
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeSmallest() noexcept
Smallest possible positive value.
Definition: ImathVec.h:236
ATOMSMATH_HOSTDEVICE void setValue(S a, S b) noexcept
Set the value.
Definition: ImathVec.h:260
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3 & operator=(const Vec3 &v) noexcept
Assignment.
Definition: ImathVec.h:1238
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError(const Vec3< T > &v, T e) const noexcept
Definition: ImathVec.h:1359
constexpr ATOMSMATH_HOSTDEVICE Vec3 operator%(const Vec3 &v) const noexcept
Right-handed cross product.
Definition: ImathVec.h:1404
~Vec3() noexcept=default
Destructor.
constexpr ATOMSMATH_HOSTDEVICE Vec3 operator+(const Vec3 &v) const noexcept
Component-wise addition.
Definition: ImathVec.h:1421
constexpr ATOMSMATH_HOSTDEVICE T operator^(const Vec3 &v) const noexcept
Dot product.
Definition: ImathVec.h:1377
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeSmallest() noexcept
Smallest possible positive value.
Definition: ImathVec.h:463
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T & operator[](int i) noexcept
Element access by index.
Definition: ImathVec.h:1199
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError(const Vec3< T > &v, T e) const noexcept
Definition: ImathVec.h:1348
T BaseType
Definition: ImathVec.h:475
constexpr ATOMSMATH_HOSTDEVICE Vec3 operator/(const Vec3 &v) const noexcept
Component-wise division.
Definition: ImathVec.h:1516
ATOMSMATH_HOSTDEVICE T * getValue() noexcept
Return a raw pointer to the array of values.
Definition: ImathVec.h:1318
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3 & operator/=(const Vec3 &v) noexcept
Component-wise division.
Definition: ImathVec.h:1496
constexpr ATOMSMATH_HOSTDEVICE Vec3 cross(const Vec3 &v) const noexcept
Right-handed cross product.
Definition: ImathVec.h:1384
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3 & operator+=(const Vec3 &v) noexcept
Component-wise addition.
Definition: ImathVec.h:1411
constexpr ATOMSMATH_HOSTDEVICE bool operator==(const Vec3< S > &v) const noexcept
Equality.
ATOMSMATH_HOSTDEVICE Vec3() noexcept
Uninitialized by default.
Definition: ImathVec.h:1211
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3 & negate() noexcept
Component-wise multiplication by -1.
Definition: ImathVec.h:1452
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3 & operator*=(const Vec3 &v) noexcept
Component-wise multiplication.
Definition: ImathVec.h:1462
constexpr ATOMSMATH_HOSTDEVICE T dot(const Vec3 &v) const noexcept
Dot product.
Definition: ImathVec.h:1370
constexpr ATOMSMATH_HOSTDEVICE T length2() const noexcept
Definition: ImathVec.h:1574
ATOMSMATH_HOSTDEVICE Vec3< T > normalized() const noexcept
Return a normalized vector. Does not modify *this.
Definition: ImathVec.h:1629
ATOMSMATH_HOSTDEVICE T length() const noexcept
Return the Euclidean norm.
Definition: ImathVec.h:1562
constexpr ATOMSMATH_HOSTDEVICE bool operator!=(const Vec3< S > &v) const noexcept
Inequality.
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeMax() noexcept
Largest possible positive value.
Definition: ImathVec.h:460
constexpr static ATOMSMATH_HOSTDEVICE unsigned int dimensions() noexcept
Return the number of dimensions, i.e. 3.
Definition: ImathVec.h:471
ATOMSMATH_HOSTDEVICE const Vec3 & normalize() noexcept
Normalize in place. If length()==0, return a null vector.
Definition: ImathVec.h:1581
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeEpsilon() noexcept
Smallest possible e for which 1+e != 1.
Definition: ImathVec.h:466
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3 & operator-=(const Vec3 &v) noexcept
Component-wise subtraction.
Definition: ImathVec.h:1428
Vec3< T > normalizedExc() const
Definition: ImathVec.h:1641
constexpr ATOMSMATH_HOSTDEVICE Vec3 operator-() const noexcept
Component-wise multiplication by -1.
Definition: ImathVec.h:1445
constexpr ATOMSMATH_HOSTDEVICE Vec3(const Vec3< S > &v) noexcept
Construct from Vec3 of another base type.
ATOMSMATH_HOSTDEVICE Vec3< T > normalizedNonNull() const noexcept
Definition: ImathVec.h:1653
constexpr ATOMSMATH_HOSTDEVICE Vec3(const Vec4< S > &v) noexcept
constexpr ATOMSMATH_HOSTDEVICE Vec3 operator*(const Vec3 &v) const noexcept
Component-wise multiplication.
Definition: ImathVec.h:1482
ATOMSMATH_HOSTDEVICE void setValue(S a, S b, S c) noexcept
Set the value.
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec3 & operator%=(const Vec3 &v) noexcept
Right-handed cross product.
Definition: ImathVec.h:1391
const Vec3 & normalizeExc()
Normalize in place. If length()==0, throw an exception.
Definition: ImathVec.h:1603
ATOMSMATH_HOSTDEVICE const Vec3 & normalizeNonNull() noexcept
Definition: ImathVec.h:1618
Definition: ImathVec.h:486
constexpr ATOMSMATH_HOSTDEVICE bool operator!=(const Vec4< S > &v) const noexcept
Inequality.
~Vec4() noexcept=default
Destructor.
constexpr ATOMSMATH_HOSTDEVICE Vec4 operator-() const noexcept
Component-wise multiplication by -1.
Definition: ImathVec.h:1808
constexpr ATOMSMATH_HOSTDEVICE T length2() const noexcept
Definition: ImathVec.h:1947
ATOMSMATH_HOSTDEVICE T length() const noexcept
Return the Euclidean norm.
Definition: ImathVec.h:1935
constexpr static ATOMSMATH_HOSTDEVICE unsigned int dimensions() noexcept
Return the number of dimensions, i.e. 4.
Definition: ImathVec.h:658
constexpr ATOMSMATH_HOSTDEVICE Vec4 operator*(const Vec4 &v) const noexcept
Component-wise multiplication.
Definition: ImathVec.h:1848
Vec4< T > normalizedExc() const
Definition: ImathVec.h:2017
ATOMSMATH_HOSTDEVICE Vec4() noexcept
Uninitialized by default.
Definition: ImathVec.h:1677
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4 & operator+=(const Vec4 &v) noexcept
Component-wise addition.
Definition: ImathVec.h:1772
ATOMSMATH_HOSTDEVICE Vec4< T > normalizedNonNull() const noexcept
Definition: ImathVec.h:2029
ATOMSMATH_HOSTDEVICE const Vec4 & normalize() noexcept
Normalize in place. If length()==0, return a null vector.
Definition: ImathVec.h:1954
constexpr ATOMSMATH_HOSTDEVICE Vec4 operator+(const Vec4 &v) const noexcept
Component-wise addition.
Definition: ImathVec.h:1783
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4 & operator=(const Vec4 &v) noexcept
Assignment.
Definition: ImathVec.h:1704
constexpr ATOMSMATH_HOSTDEVICE T dot(const Vec4 &v) const noexcept
Dot product.
Definition: ImathVec.h:1758
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4 & operator*=(const Vec4 &v) noexcept
Component-wise multiplication.
Definition: ImathVec.h:1826
constexpr ATOMSMATH_HOSTDEVICE Vec4 operator/(const Vec4 &v) const noexcept
Component-wise division.
Definition: ImathVec.h:1884
constexpr ATOMSMATH_HOSTDEVICE Vec4(const Vec3< S > &v) noexcept
Vec3 to Vec4 conversion, sets w to 1.
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError(const Vec4< T > &v, T e) const noexcept
Definition: ImathVec.h:1736
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T & operator[](int i) noexcept
Element access by index.
Definition: ImathVec.h:1665
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4 & operator-=(const Vec4 &v) noexcept
Component-wise subtraction.
Definition: ImathVec.h:1790
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeMax() noexcept
Largest possible positive value.
Definition: ImathVec.h:647
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeEpsilon() noexcept
Smallest possible e for which 1+e != 1.
Definition: ImathVec.h:653
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4 & operator/=(const Vec4 &v) noexcept
Component-wise division.
Definition: ImathVec.h:1862
constexpr ATOMSMATH_HOSTDEVICE bool operator==(const Vec4< S > &v) const noexcept
Equality.
ATOMSMATH_HOSTDEVICE const Vec4 & normalizeNonNull() noexcept
Definition: ImathVec.h:1993
T BaseType
Definition: ImathVec.h:662
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeSmallest() noexcept
Smallest possible positive value.
Definition: ImathVec.h:650
const Vec4 & normalizeExc()
Normalize in place. If length()==0, throw an exception.
Definition: ImathVec.h:1977
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Vec4 & negate() noexcept
Component-wise multiplication by -1.
Definition: ImathVec.h:1815
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError(const Vec4< T > &v, T e) const noexcept
Definition: ImathVec.h:1747
ATOMSMATH_HOSTDEVICE Vec4< T > normalized() const noexcept
Return a normalized vector. Does not modify *this.
Definition: ImathVec.h:2005
constexpr ATOMSMATH_HOSTDEVICE Vec4(const Vec4< S > &v) noexcept
Construct from Vec4 of another base type.
constexpr ATOMSMATH_HOSTDEVICE T operator^(const Vec4 &v) const noexcept
Dot product.
Definition: ImathVec.h:1765