Jet  v1.3.3
point3.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_POINT3_H_
8 #define INCLUDE_JET_POINT3_H_
9 
10 #include <jet/point2.h>
11 #include <algorithm> // just make cpplint happy..
12 
13 namespace jet {
14 
22 template <typename T>
23 class Point<T, 3> {
24  public:
25  static_assert(std::is_arithmetic<T>::value,
26  "Point only can be instantiated with arithematic types");
27 
29  T x;
30 
32  T y;
33 
35  T z;
36 
37  // MARK: Constructors
38 
40  constexpr Point() : x(0), y(0), z(0) {}
41 
43  constexpr Point(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}
44 
46  constexpr Point(const Point2<T>& v, T z_) : x(v.x), y(v.y), z(z_) {}
47 
49  template <typename U>
50  Point(const std::initializer_list<U>& lst);
51 
53  constexpr Point(const Point& v) : x(v.x), y(v.y), z(v.z) {}
54 
55  // MARK: Basic setters
56 
58  void set(T s);
59 
61  void set(T x, T y, T z);
62 
64  void set(const Point2<T>& pt, T z);
65 
67  template <typename U>
68  void set(const std::initializer_list<U>& lst);
69 
71  void set(const Point& v);
72 
74  void setZero();
75 
76  // MARK: Binary operations: new instance = this (+) v
77 
79  Point add(T v) const;
80 
82  Point add(const Point& v) const;
83 
85  Point sub(T v) const;
86 
88  Point sub(const Point& v) const;
89 
91  Point mul(T v) const;
92 
94  Point mul(const Point& v) const;
96  Point div(T v) const;
97 
99  Point div(const Point& v) const;
100 
101  // MARK: Binary operations: new instance = v (+) this
102 
104  Point rsub(T v) const;
105 
107  Point rsub(const Point& v) const;
108 
110  Point rdiv(T v) const;
111 
113  Point rdiv(const Point& v) const;
114 
115  // MARK: Augmented operations: this (+)= v
116 
118  void iadd(T v);
119 
121  void iadd(const Point& v);
122 
124  void isub(T v);
125 
127  void isub(const Point& v);
128 
130  void imul(T v);
131 
133  void imul(const Point& v);
134 
136  void idiv(T v);
137 
139  void idiv(const Point& v);
140 
141  // MARK: Basic getters
142 
144  const T& at(size_t i) const;
145 
147  T& at(size_t i);
148 
150  T sum() const;
151 
153  T min() const;
154 
156  T max() const;
157 
159  T absmin() const;
160 
162  T absmax() const;
163 
165  size_t dominantAxis() const;
166 
168  size_t subminantAxis() const;
169 
171  template <typename U>
173 
175  bool isEqual(const Point& other) const;
176 
177  // MARK: Operators
178 
180  T& operator[](size_t i);
181 
183  const T& operator[](size_t i) const;
184 
186  Point& operator=(const std::initializer_list<T>& lst);
187 
189  Point& operator=(const Point& v);
190 
193 
195  Point& operator+=(const Point& v);
196 
199 
201  Point& operator-=(const Point& v);
202 
205 
207  Point& operator*=(const Point& v);
208 
211 
213  Point& operator/=(const Point& v);
214 
216  bool operator==(const Point& v) const;
217 
219  bool operator!=(const Point& v) const;
220 };
221 
223 template <typename T>
225 
227 template <typename T>
229 
231 template <typename T>
233 
235 template <typename T>
237 
239 template <typename T>
241 
243 template <typename T>
245 
247 template <typename T>
249 
251 template <typename T>
253 
255 template <typename T>
257 
259 template <typename T>
261 
263 template <typename T>
265 
267 template <typename T>
269 
271 template <typename T>
273 
275 template <typename T>
277 
279 template <typename T>
280 Point3<T> min(const Point3<T>& a, const Point3<T>& b);
281 
283 template <typename T>
284 Point3<T> max(const Point3<T>& a, const Point3<T>& b);
285 
287 template <typename T>
288 Point3<T> clamp(const Point3<T>& v, const Point3<T>& low,
289  const Point3<T>& high);
290 
292 template <typename T>
294 
296 template <typename T>
298 
301 
304 
307 
310 
311 } // namespace jet
312 
313 #include "detail/point3-inl.h"
314 
315 #endif // INCLUDE_JET_POINT3_H_
jet::Point< T, 3 >::Point
Point(const std::initializer_list< U > &lst)
Constructs point with initializer list.
jet::Point< T, 2 >
2-D point class.
Definition: point2.h:23
jet::Point3D
Point3< double > Point3D
Double-type 3D point.
Definition: point3.h:303
jet::Point< T, 3 >::operator!=
bool operator!=(const Point &v) const
Returns true if other is the not same as this point.
jet::Point< T, 3 >::rdiv
Point rdiv(T v) const
Computes (v, v, v) / this.
jet::ceil
Point2< T > ceil(const Point2< T > &a)
Returns element-wise ceiled point.
jet::Point< T, 3 >::sub
Point sub(T v) const
Computes this - (v, v, v).
jet::Point< T, 3 >::z
T z
Z (or the third) component of the point.
Definition: point3.h:35
jet::Point< T, 3 >::operator==
bool operator==(const Point &v) const
Returns true if other is the same as this point.
jet::Point< T, 3 >::add
Point add(T v) const
Computes this + (v, v, v).
jet::Point< T, 3 >::at
T & at(size_t i)
Returns reference to the i -th element of the point.
jet::Point< T, 3 >::operator=
Point & operator=(const std::initializer_list< T > &lst)
Set x, y, and z components with given initializer list.
jet::Point< T, 3 >::operator*=
Point & operator*=(const Point &v)
Computes this *= (v.x, v.y, v.z)
jet::Point< T, 3 >::div
Point div(const Point &v) const
Computes this / (v.x, v.y, v.z).
jet::Point< T, 3 >::max
T max() const
Returns the maximum value among x, y, and z.
jet::Point< T, 3 >::min
T min() const
Returns the minimum value among x, y, and z.
jet::Point3I
Point3< ssize_t > Point3I
Integer-type 3D point.
Definition: point3.h:306
jet::Point< T, 3 >::absmin
T absmin() const
Returns the absolute minimum value among x, y, and z.
jet::max
Point2< T > max(const Point2< T > &a, const Point2< T > &b)
Returns element-wise max point: (max(a.x, b.x), max(a.y, b.y)).
jet::Point< T, 3 >::rsub
Point rsub(T v) const
Computes (v, v, v) - this.
jet::Point< T, 3 >::imul
void imul(T v)
Computes this *= (v, v, v).
jet::Point< T, 3 >::operator-=
Point & operator-=(T v)
Computes this -= (v, v, v)
jet::Point< T, 3 >::Point
constexpr Point(const Point &v)
Copy constructor.
Definition: point3.h:53
jet::Point< T, 3 >::set
void set(const std::initializer_list< U > &lst)
Set x, y, and z components with given initializer list.
jet::Point< T, 3 >::operator-=
Point & operator-=(const Point &v)
Computes this -= (v.x, v.y, v.z)
jet::Point< T, 3 >::add
Point add(const Point &v) const
Computes this + (v.x, v.y, v.z).
jet::Point< T, 3 >::absmax
T absmax() const
Returns the absolute maximum value among x, y, and z.
jet::Point3F
Point3< float > Point3F
Float-type 3D point.
Definition: point3.h:300
jet::Point< T, 3 >::operator*=
Point & operator*=(T v)
Computes this *= (v, v, v)
jet::Point< T, 3 >::operator/=
Point & operator/=(T v)
Computes this /= (v, v, v)
jet::Point< T, 3 >::set
void set(const Point &v)
Set x, y, and z with other point pt.
jet::Point< T, 3 >::y
T y
Y (or the second) component of the point.
Definition: point3.h:32
jet
Definition: advection_solver2.h:18
jet::Point< T, 3 >::set
void set(T s)
Set all x, y, and z components to s.
jet::Point< T, 3 >::mul
Point mul(T v) const
Computes this * (v, v, v).
jet::Point< T, 3 >::at
const T & at(size_t i) const
Returns const reference to the i -th element of the point.
jet::Point< T, 3 >::sub
Point sub(const Point &v) const
Computes this - (v.x, v.y, v.z).
jet::Point< T, 3 >::x
T x
X (or the first) component of the point.
Definition: point3.h:26
jet::Point< T, 3 >::operator=
Point & operator=(const Point &v)
Set x, y, and z with other point pt.
jet::Point< T, 3 >::imul
void imul(const Point &v)
Computes this *= (v.x, v.y, v.z).
jet::Point< T, 3 >::idiv
void idiv(const Point &v)
Computes this /= (v.x, v.y, v.z).
jet::Point< T, 3 >::operator+=
Point & operator+=(T v)
Computes this += (v, v, v)
jet::Point< T, 3 >::div
Point div(T v) const
Computes this / (v, v, v).
jet::Point< T, 3 >::castTo
Point< U, 3 > castTo() const
Returns a point with different value type.
jet::clamp
T clamp(T val, T low, T high)
Returns the clamped value.
jet::Point< T, 3 >::iadd
void iadd(const Point &v)
Computes this += (v.x, v.y, v.z).
jet::operator+
Matrix2x2< T > operator+(const Matrix2x2< T > &a, const Matrix2x2< T > &b)
Returns a + b (element-size).
jet::Point< T, 3 >::isEqual
bool isEqual(const Point &other) const
Returns true if other is the same as this point.
jet::floor
Point2< T > floor(const Point2< T > &a)
Returns element-wise floored point.
jet::Point< T, 3 >::sum
T sum() const
Returns the sum of all the components (i.e. x + y).
jet::Point< T, 3 >::set
void set(T x, T y, T z)
Set x, y, and z components with given parameters.
jet::Point< T, 3 >
3-D point class.
Definition: point3.h:23
jet::Point< T, 3 >::dominantAxis
size_t dominantAxis() const
Returns the index of the dominant axis.
jet::Point< T, 3 >::operator[]
T & operator[](size_t i)
Returns reference to the i -th element of the point.
jet::Point< T, 3 >::set
void set(const Point2< T > &pt, T z)
Set x, y, and z components with given pt.x, pt.y, and z.
jet::Point3UI
Point3< size_t > Point3UI
Unsigned integer-type 3D point.
Definition: point3.h:309
jet::Point< T, 3 >::Point
constexpr Point()
Constructs default point (0, 0, 0).
Definition: point3.h:40
jet::Point< T, 3 >::rsub
Point rsub(const Point &v) const
Computes (v.x, v.y, v.z) - this.
jet::Point
Generic N-D point class.
Definition: point.h:23
jet::Point< T, 3 >::operator[]
const T & operator[](size_t i) const
Returns const reference to the i -th element of the point.
jet::Point< T, 3 >::idiv
void idiv(T v)
Computes this /= (v, v, v).
jet::Point< T, 3 >::setZero
void setZero()
Set both x, y, and z to zero.
jet::operator/
Matrix2x2< T > operator/(const Matrix2x2< T > &a, T b)
Returns a' / b, where every element of matrix a' is a.
jet::min
Point2< T > min(const Point2< T > &a, const Point2< T > &b)
Returns element-wise min point: (min(a.x, b.x), min(a.y, b.y)).
jet::Point< T, 3 >::mul
Point mul(const Point &v) const
Computes this * (v.x, v.y, v.z).
jet::operator-
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
jet::Point< T, 3 >::operator/=
Point & operator/=(const Point &v)
Computes this /= (v.x, v.y, v.z)
jet::Point< T, 3 >::isub
void isub(const Point &v)
Computes this -= (v.x, v.y, v.z).
jet::operator*
Matrix2x2< T > operator*(const Matrix2x2< T > &a, T b)
Returns a * b', where every element of matrix b' is b.
jet::Point< T, 3 >::rdiv
Point rdiv(const Point &v) const
Computes (v.x, v.y, v.z) / this.
jet::Point< T, 3 >::operator+=
Point & operator+=(const Point &v)
Computes this += (v.x, v.y, v.z)
jet::Point< T, 3 >::isub
void isub(T v)
Computes this -= (v, v, v).
jet::Point< T, 3 >::Point
constexpr Point(const Point2< T > &v, T z_)
Constructs point with a 2-D point and a scalar.
Definition: point3.h:46
jet::Point< T, 3 >::iadd
void iadd(T v)
Computes this += (v, v, v).
jet::Point< T, 3 >::subminantAxis
size_t subminantAxis() const
Returns the index of the subminant axis.
point2.h
jet::Point< T, 3 >::Point
constexpr Point(T x_, T y_, T z_)
Constructs point with given parameters x_, y_, and z_.
Definition: point3.h:43