EBGeometry  1.0
EBGeometry_Vec.hpp
Go to the documentation of this file.
1 /* EBGeometry
2  * Copyright © 2022 Robert Marskar
3  * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory.
4  */
5 
13 #ifndef EBGeometry_Vec
14 #define EBGeometry_Vec
15 
16 // Std includes
17 #include <array>
18 #include <iostream>
19 
20 // Our includes
22 
29 template <typename T>
30 class Vec2T
31 {
32 public:
36  Vec2T();
37 
43  Vec2T(const Vec2T& u) noexcept;
44 
51  constexpr Vec2T(const T& a_x, const T& a_y);
52 
56  ~Vec2T() = default;
57 
61  T x;
62 
66  T y;
67 
71  inline static constexpr Vec2T<T>
72  zero() noexcept;
73 
77  inline static constexpr Vec2T<T>
78  one() noexcept;
79 
83  inline static constexpr Vec2T<T>
84  min() noexcept;
85 
89  inline static constexpr Vec2T<T>
90  max() noexcept;
91 
95  inline static constexpr Vec2T<T>
96  infinity() noexcept;
97 
102  inline constexpr Vec2T<T>&
103  operator=(const Vec2T& a_other) noexcept;
104 
111  inline constexpr Vec2T<T>
112  operator+(const Vec2T& a_other) const noexcept;
113 
120  inline constexpr Vec2T<T>
121  operator-(const Vec2T& a_other) const noexcept;
122 
126  inline constexpr Vec2T<T>
127  operator-() const noexcept;
128 
135  inline constexpr Vec2T<T>
136  operator*(const T& s) const noexcept;
137 
144  inline constexpr Vec2T<T>
145  operator/(const T& s) const noexcept;
146 
153  inline constexpr Vec2T<T>&
154  operator+=(const Vec2T& a_other) noexcept;
155 
162  inline constexpr Vec2T<T>&
163  operator-=(const Vec2T& a_other) noexcept;
164 
171  inline constexpr Vec2T<T>&
172  operator*=(const T& s) noexcept;
173 
180  inline constexpr Vec2T<T>&
181  operator/=(const T& s) noexcept;
182 
188  inline constexpr T
189  dot(const Vec2T& a_other) const noexcept;
190 
196  inline constexpr T
197  length() const noexcept;
198 
204  inline constexpr T
205  length2() const noexcept;
206 };
207 
216 template <typename T>
217 class Vec3T
218 {
219 public:
223  friend std::ostream&
224  operator<<(std::ostream& os, const Vec3T<T>& vec)
225  {
226  os << '(' << vec[0] << ',' << vec[1] << ',' << vec[2] << ')';
227 
228  return os;
229  }
230 
234  Vec3T() noexcept;
235 
241  Vec3T(const Vec3T<T>& a_u) noexcept;
242 
250  constexpr Vec3T(const T& a_x, const T& a_y, const T& a_z) noexcept;
251 
255  ~Vec3T() noexcept = default;
256 
260  inline static constexpr Vec3T<T>
261  zero() noexcept;
262 
266  inline static constexpr Vec3T<T>
267  one() noexcept;
268 
273  inline static constexpr Vec3T<T>
274  unit(const size_t a_dir) noexcept;
275 
279  inline static constexpr Vec3T<T>
280  min() noexcept;
281 
285  inline static constexpr Vec3T<T>
286  max() noexcept;
287 
291  inline static constexpr Vec3T<T>
292  infinity() noexcept;
293 
299  inline constexpr bool
300  lessLX(const Vec3T<T>& u) const noexcept;
301 
306  inline constexpr T&
307  operator[](size_t i) noexcept;
308 
313  inline constexpr const T&
314  operator[](size_t i) const noexcept;
315 
320  inline constexpr bool
321  operator==(const Vec3T<T>& u) const noexcept;
322 
327  inline constexpr bool
328  operator!=(const Vec3T<T>& u) const noexcept;
329 
336  inline constexpr bool
337  operator<(const Vec3T<T>& u) const noexcept;
338 
344  inline constexpr bool
345  operator>(const Vec3T<T>& u) const noexcept;
346 
353  inline constexpr bool
354  operator<=(const Vec3T<T>& u) const noexcept;
355 
362  inline constexpr bool
363  operator>=(const Vec3T<T>& u) const noexcept;
364 
370  inline constexpr Vec3T<T>&
371  operator=(const Vec3T<T>& u) noexcept;
372 
378  inline constexpr Vec3T<T>
379  operator+(const Vec3T<T>& u) const noexcept;
380 
386  inline constexpr Vec3T<T>
387  operator-(const Vec3T<T>& u) const noexcept;
388 
392  inline constexpr Vec3T<T>
393  operator-() const noexcept;
394 
401  inline constexpr Vec3T<T>
402  operator*(const T& s) const noexcept;
403 
410  inline constexpr Vec3T<T>
411  operator*(const Vec3T<T>& s) const noexcept;
412 
418  inline constexpr Vec3T<T>
419  operator/(const T& s) const noexcept;
420 
426  inline constexpr Vec3T<T>
427  operator/(const Vec3T<T>& v) const noexcept;
428 
435  inline constexpr Vec3T<T>&
436  operator+=(const Vec3T<T>& u) noexcept;
437 
444  inline constexpr Vec3T<T>&
445  operator-=(const Vec3T<T>& u) noexcept;
446 
453  inline constexpr Vec3T<T>&
454  operator*=(const T& s) noexcept;
455 
462  inline constexpr Vec3T<T>&
463  operator/=(const T& s) noexcept;
464 
472  inline constexpr Vec3T<T>
473  min(const Vec3T<T>& u) noexcept;
474 
482  inline constexpr Vec3T<T>
483  max(const Vec3T<T>& u) noexcept;
484 
490  inline constexpr Vec3T<T>
491  cross(const Vec3T<T>& u) const noexcept;
492 
498  inline constexpr T
499  dot(const Vec3T<T>& u) const noexcept;
500 
508  inline size_t
509  minDir(const bool a_doAbs) const noexcept;
510 
518  inline size_t
519  maxDir(const bool a_doAbs) const noexcept;
520 
526  inline constexpr T
527  length() const noexcept;
528 
534  inline constexpr T
535  length2() const noexcept;
536 
537 protected:
541  std::array<T, 3> m_X;
542 };
543 
550 template <typename T>
551 inline constexpr Vec2T<T>
552 operator*(const T& s, const Vec2T<T>& a_other) noexcept;
553 
561 template <typename T>
562 inline constexpr Vec2T<T>
563 operator/(const T& s, const Vec2T<T>& a_other) noexcept;
564 
571 template <typename T>
572 inline Vec2T<T>
573 min(const Vec2T<T>& u, const Vec2T<T>& v) noexcept;
574 
581 template <typename T>
582 inline Vec2T<T>
583 max(const Vec2T<T>& u, const Vec2T<T>& v) noexcept;
584 
590 template <typename T>
591 inline T
592 dot(const Vec2T<T>& u, const Vec2T<T>& v) noexcept;
593 
598 template <typename T>
599 inline T
600 length(const Vec2T<T>& v) noexcept;
601 
608 template <class R, typename T>
609 inline constexpr Vec3T<T>
610 operator*(const R& s, const Vec3T<T>& u) noexcept;
611 
618 template <typename T>
619 inline constexpr Vec3T<T>
620 operator*(const Vec3T<T>& u, const Vec3T<T>& v) noexcept;
621 
628 template <class R, typename T>
629 inline constexpr Vec3T<T>
630 operator/(const R& s, const Vec3T<T>& u) noexcept;
631 
639 template <typename T>
640 inline constexpr Vec3T<T>
641 min(const Vec3T<T>& u, const Vec3T<T>& v) noexcept;
642 
650 template <typename T>
651 inline constexpr Vec3T<T>
652 max(const Vec3T<T>& u, const Vec3T<T>& v) noexcept;
653 
659 template <typename T>
660 inline constexpr T
661 dot(const Vec3T<T>& u, const Vec3T<T>& v) noexcept;
662 
667 template <typename T>
668 inline constexpr T
669 length(const Vec3T<T>& v) noexcept;
670 
671 #include "EBGeometry_NamespaceFooter.hpp"
672 
673 #include "EBGeometry_VecImplem.hpp"
674 
675 #endif
Two-dimensional vector class with arithmetic operators.
Definition: EBGeometry_Vec.hpp:31
constexpr T length() const noexcept
Compute length of vector.
~Vec2T()=default
Destructor (does nothing)
constexpr T length2() const noexcept
Compute square of vector.
static constexpr Vec2T< T > max() noexcept
Return maximum possible representative vector.
Vec2T()
Default constructor. Sets the vector to the zero vector.
static constexpr Vec2T< T > zero() noexcept
Return av vector with x = y = 0.
T x
First component in the vector.
Definition: EBGeometry_Vec.hpp:61
constexpr Vec2T(const T &a_x, const T &a_y)
Full constructor.
T y
Second component in the vector.
Definition: EBGeometry_Vec.hpp:66
static constexpr Vec2T< T > min() noexcept
Return minimum possible representative vector.
constexpr T dot(const Vec2T &a_other) const noexcept
Dot product operator.
static constexpr Vec2T< T > infinity() noexcept
Return a vector with inf components.
static constexpr Vec2T< T > one() noexcept
Return av vector with x = y = 1.
Vec2T(const Vec2T &u) noexcept
Copy constructor.
Three-dimensional vector class with arithmetic operators.
Definition: EBGeometry_Vec.hpp:218
Vec3T() noexcept
Default constructor. Sets the vector to the zero vector.