Point3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Point3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D point class.
6 > Created Time: 2017/02/01
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_POINT3_H
10 #define CUBBYFLOW_POINT3_H
11 
12 #include <Core/Point/Point.h>
13 #include <Core/Point/Point2.h>
14 #include <Core/Utils/Constants.h>
15 
16 namespace CubbyFlow
17 {
25  template <typename T>
26  class Point<T, 3> final
27  {
28  public:
29  static_assert(std::is_arithmetic<T>::value, "Point only can be instantiated with arithmatic types");
30 
32  T x;
33 
35  T y;
36 
38  T z;
39 
40  // MARK: Constructors
42  constexpr Point() : x(0), y(0), z(0)
43  {
44  // Do nothing
45  }
46 
48  constexpr Point(T _x, T _y, T _z) : x(_x), y(_y), z(_z)
49  {
50  // Do nothing
51  }
52 
54  constexpr Point(const Point2<T>& pt, T _z) : x(pt.x), y(pt.y), z(_z)
55  {
56  // Do nothing
57  }
58 
60  template <typename U>
61  Point(const std::initializer_list<U>& list);
62 
64  constexpr Point(const Point& pt) : x(pt.x), y(pt.y), z(pt.z)
65  {
66  // Do nothing
67  }
68 
69  // MARK: Basic setters
71  void Set(T s);
72 
74  void Set(T x, T y, T z);
75 
77  void Set(const Point2<T>& pt, T z);
78 
80  template <typename U>
81  void Set(const std::initializer_list<U>& list);
82 
84  void Set(const Point& v);
85 
87  void SetZero();
88 
89  // MARK: Binary operations: new instance = this (+) v
91  Point Add(T v) const;
92 
94  Point Add(const Point& v) const;
95 
97  Point Sub(T v) const;
98 
100  Point Sub(const Point& v) const;
101 
103  Point Mul(T v) const;
104 
106  Point Mul(const Point& v) const;
107 
109  Point Div(T v) const;
110 
112  Point Div(const Point& v) const;
113 
114  // MARK: Binary operations: new instance = v (+) this
116  Point RAdd(T v) const;
117 
119  Point RAdd(const Point& v) const;
120 
122  Point RSub(T v) const;
123 
125  Point RSub(const Point& v) const;
126 
128  Point RMul(T v) const;
129 
131  Point RMul(const Point& v) const;
132 
134  Point RDiv(T v) const;
135 
137  Point RDiv(const Point& v) const;
138 
139  // MARK: Augmented operations: this (+)= v
141  void IAdd(T v);
142 
144  void IAdd(const Point& v);
145 
147  void ISub(T v);
148 
150  void ISub(const Point& v);
151 
153  void IMul(T v);
154 
156  void IMul(const Point& v);
157 
159  void IDiv(T v);
160 
162  void IDiv(const Point& v);
163 
164  // MARK: Basic getters
166  const T& At(size_t i) const;
167 
169  T& At(size_t i);
170 
172  T Sum() const;
173 
175  T Min() const;
176 
178  T Max() const;
179 
181  T AbsMin() const;
182 
184  T AbsMax() const;
185 
187  size_t DominantAxis() const;
188 
190  size_t SubdominantAxis() const;
191 
193  template <typename U>
194  Point<U, 3> CastTo() const;
195 
197  bool IsEqual(const Point& other) const;
198 
199  // MARK: Operators
201  T& operator[](size_t i);
202 
204  const T& operator[](size_t i) const;
205 
207  Point& operator=(const std::initializer_list<T>& list);
208 
210  Point& operator=(const Point& v);
211 
213  Point& operator+=(T v);
214 
216  Point& operator+=(const Point& v);
217 
219  Point& operator-=(T v);
220 
222  Point& operator-=(const Point& v);
223 
225  Point& operator*=(T v);
226 
228  Point& operator*=(const Point& v);
229 
231  Point& operator/=(T v);
232 
234  Point& operator/=(const Point& v);
235 
237  bool operator==(const Point& v) const;
238 
240  bool operator!=(const Point& v) const;
241  };
242 
244  template <typename T>
245  Point<T, 3> operator+(const Point<T, 3>& a);
246 
248  template <typename T>
249  Point<T, 3> operator-(const Point<T, 3>& a);
250 
252  template <typename T>
253  Point<T, 3> operator+(T a, const Point<T, 3>& b);
254 
256  template <typename T>
257  Point<T, 3> operator+(const Point<T, 3>& a, const Point<T, 3>& b);
258 
260  template <typename T>
261  Point<T, 3> operator-(const Point<T, 3>& a, T b);
262 
264  template <typename T>
265  Point<T, 3> operator-(T a, const Point<T, 3>& b);
266 
268  template <typename T>
269  Point<T, 3> operator-(const Point<T, 3>& a, const Point<T, 3>& b);
270 
272  template <typename T>
273  Point<T, 3> operator*(const Point<T, 3>& a, T b);
274 
276  template <typename T>
277  Point<T, 3> operator*(T a, const Point<T, 3>& b);
278 
280  template <typename T>
281  Point<T, 3> operator*(const Point<T, 3>& a, const Point<T, 3>& b);
282 
284  template <typename T>
285  Point<T, 3> operator/(const Point<T, 3>& a, T b);
286 
288  template <typename T>
289  Point<T, 3> operator/(T a, const Point<T, 3>& b);
290 
292  template <typename T>
293  Point<T, 3> operator/(const Point<T, 3>& a, const Point<T, 3>& b);
294 
296  template <typename T>
297  Point<T, 3> Min(const Point<T, 3>& a, const Point<T, 3>& b);
298 
300  template <typename T>
301  Point<T, 3> Max(const Point<T, 3>& a, const Point<T, 3>& b);
302 
304  template <typename T>
305  Point<T, 3> Clamp(const Point<T, 3>& v, const Point<T, 3>& low, const Point<T, 3>& high);
306 
308  template <typename T>
309  Point<T, 3> Ceil(const Point<T, 3>& a);
310 
312  template <typename T>
313  Point<T, 3> Floor(const Point<T, 3>& a);
314 
316  template <typename T> using Point3 = Point<T, 3>;
317 
320 
323 
326 
329 }
330 
331 #include <Core/Point/Point3-Impl.h>
332 
333 #endif
T AbsMin(T x, T y)
Returns the absolute minimum value among the two inputs.
Definition: MathUtils-Impl.h:39
Point< T, 2 > Ceil(const Point< T, 2 > &a)
Returns element-wise ceiled point.
Definition: Point2-Impl.h:492
Matrix< T, 2, 2 > operator+(const Matrix< T, 2, 2 > &a, const Matrix< T, 2, 2 > &b)
Returns a + b (element-size).
Definition: Matrix2x2-Impl.h:660
constexpr Point(T _x, T _y, T _z)
Constructs point with given parameters _x, _y, and _z.
Definition: Point3.h:48
void Set(const std::initializer_list< U > &list)
Set point instance with initializer list.
Definition: Point-Impl.h:57
2-D point class.
Definition: Point2.h:25
3-D point class.
Definition: Point3.h:26
constexpr Point(const Point &pt)
Copy constructor.
Definition: Point3.h:64
Point< T, 2 > Floor(const Point< T, 2 > &a)
Returns element-wise floored point.
Definition: Point2-Impl.h:498
constexpr Point(const Point2< T > &pt, T _z)
Constructs point with a 2-D point and a scalar.
Definition: Point3.h:54
Generic N-D point class.
Definition: Point.h:24
Matrix< T, 2, 2 > operator/(const Matrix< T, 2, 2 > &a, T b)
Definition: Matrix2x2-Impl.h:720
Definition: pybind11Utils.h:24
T Clamp(T val, T low, T high)
Returns the clamped value.
Definition: MathUtils-Impl.h:123
Point & operator=(const std::initializer_list< U > &list)
Set point instance with initializer list.
T z
Z (or the third) component of the point.
Definition: Point3.h:38
T y
Y (or the second) component of the point.
Definition: Point3.h:35
Matrix< T, 2, 2 > operator-(const Matrix< T, 2, 2 > &a)
Returns a matrix with opposite sign.
Definition: Matrix2x2-Impl.h:654
T x
X (or the first) component of the point.
Definition: Point3.h:29
Point< T, 2 > Max(const Point< T, 2 > &a, const Point< T, 2 > &b)
Returns element-wise max point: (max(a.x, b.x), max(a.y, b.y)).
Definition: Point2-Impl.h:480
const T & operator[](size_t i) const
Returns the const reference to the i -th element.
Definition: Point-Impl.h:91
Vector< T, 3 > operator*(const Quaternion< T > &q, const Vector< T, 3 > &v)
Returns quaternion q * vector v.
Definition: Quaternion-Impl.h:481
T AbsMax(T x, T y)
Returns the absolute maximum value among the two inputs.
Definition: MathUtils-Impl.h:45
Point()
Constructs a point with zeros.
Definition: Point-Impl.h:17
Point< T, 2 > Min(const Point< T, 2 > &a, const Point< T, 2 > &b)
Returns element-wise min point: (min(a.x, b.x), min(a.y, b.y)).
Definition: Point2-Impl.h:474
constexpr Point()
Constructs default point (0, 0, 0).
Definition: Point3.h:42