Jet  v1.3.3
point2.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_POINT2_H_
8 #define INCLUDE_JET_POINT2_H_
9 
10 #include <jet/point.h>
11 #include <algorithm> // just make cpplint happy..
12 
13 namespace jet {
14 
22 template <typename T>
23 class Point<T, 2> {
24  public:
25  static_assert(std::is_arithmetic<T>::value,
26  "Point only can be instantiated with arithmetic types");
27 
29  T x;
30 
32  T y;
33 
34  // MARK: Constructors
35 
37  constexpr Point() : x(0), y(0) {}
38 
40  constexpr Point(T x_, T y_) : x(x_), y(y_) {}
41 
43  template <typename U>
44  Point(const std::initializer_list<U>& lst);
45 
47  constexpr Point(const Point& v) : x(v.x), y(v.y) {}
48 
49  // MARK: Basic setters
50 
52  void set(T s);
53 
55  void set(T x, T y);
56 
58  template <typename U>
59  void set(const std::initializer_list<U>& lst);
60 
62  void set(const Point& pt);
63 
65  void setZero();
66 
67  // MARK: Binary operations: new instance = this (+) v
68 
70  Point add(T v) const;
71 
73  Point add(const Point& v) const;
74 
76  Point sub(T v) const;
77 
79  Point sub(const Point& v) const;
80 
82  Point mul(T v) const;
83 
85  Point mul(const Point& v) const;
86 
88  Point div(T v) const;
89 
91  Point div(const Point& v) const;
92 
93  // MARK: Binary operations: new instance = v (+) this
94 
96  Point rsub(T v) const;
97 
99  Point rsub(const Point& v) const;
100 
102  Point rdiv(T v) const;
103 
105  Point rdiv(const Point& v) const;
106 
107  // MARK: Augmented operations: this (+)= v
108 
110  void iadd(T v);
111 
113  void iadd(const Point& v);
114 
116  void isub(T v);
117 
119  void isub(const Point& v);
120 
122  void imul(T v);
123 
125  void imul(const Point& v);
126 
128  void idiv(T v);
129 
131  void idiv(const Point& v);
132 
133  // MARK: Basic getters
134 
136  const T& at(size_t i) const;
137 
139  T& at(size_t i);
140 
142  T sum() const;
143 
145  T min() const;
146 
148  T max() const;
149 
151  T absmin() const;
152 
154  T absmax() const;
155 
157  size_t dominantAxis() const;
158 
160  size_t subminantAxis() const;
161 
163  template <typename U>
165 
167  bool isEqual(const Point& other) const;
168 
169  // MARK: Operators
170 
172  T& operator[](size_t i);
173 
175  const T& operator[](size_t i) const;
176 
178  Point& operator=(const std::initializer_list<T>& lst);
179 
181  Point& operator=(const Point& v);
182 
185 
187  Point& operator+=(const Point& v);
188 
191 
193  Point& operator-=(const Point& v);
194 
197 
199  Point& operator*=(const Point& v);
200 
203 
205  Point& operator/=(const Point& v);
206 
208  bool operator==(const Point& v) const;
209 
211  bool operator!=(const Point& v) const;
212 };
213 
215 template <typename T>
217 
219 template <typename T>
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>
272 Point2<T> min(const Point2<T>& a, const Point2<T>& b);
273 
275 template <typename T>
276 Point2<T> max(const Point2<T>& a, const Point2<T>& b);
277 
279 template <typename T>
280 Point2<T> clamp(const Point2<T>& v, const Point2<T>& low,
281  const Point2<T>& high);
282 
284 template <typename T>
286 
288 template <typename T>
290 
293 
296 
299 
302 
303 } // namespace jet
304 
305 #include "detail/point2-inl.h"
306 
307 #endif // INCLUDE_JET_POINT2_H_
jet::Point< T, 2 >
2-D point class.
Definition: point2.h:23
jet::Point< T, 2 >::x
T x
X (or the first) component of the point.
Definition: point2.h:26
jet::Point< T, 2 >::iadd
void iadd(const Point &v)
Computes this += (v.x, v.y).
jet::ceil
Point2< T > ceil(const Point2< T > &a)
Returns element-wise ceiled point.
jet::Point< T, 2 >::sub
Point sub(const Point &v) const
Computes this - (v.x, v.y).
jet::Point2I
Point2< ssize_t > Point2I
Integer-type 2D point.
Definition: point2.h:298
jet::Point< T, 2 >::set
void set(T s)
Set both x and y components to s.
jet::Point< T, 2 >::mul
Point mul(const Point &v) const
Computes this * (v.x, v.y).
jet::Point< T, 2 >::absmax
T absmax() const
Returns the absolute maximum value among x and y.
point.h
jet::Point< T, 2 >::operator=
Point & operator=(const std::initializer_list< T > &lst)
Set x and y components with given initializer list.
jet::Point< T, 2 >::operator*=
Point & operator*=(const Point &v)
Computes this *= (v.x, v.y)
jet::Point< T, 2 >::rsub
Point rsub(T v) const
Computes (v, v) - this.
jet::Point< T, 2 >::operator+=
Point & operator+=(T v)
Computes this += (v, v)
jet::Point< T, 2 >::absmin
T absmin() const
Returns the absolute minimum value among x and y.
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, 2 >::add
Point add(T v) const
Computes this + (v, v).
jet::Point< T, 2 >::set
void set(const Point &pt)
Set x and y with other point pt.
jet::Point< T, 2 >::iadd
void iadd(T v)
Computes this += (v, v).
jet::Point< T, 2 >::operator-=
Point & operator-=(T v)
Computes this -= (v, v)
jet::Point< T, 2 >::y
T y
Y (or the second) component of the point.
Definition: point2.h:32
jet::Point< T, 2 >::isEqual
bool isEqual(const Point &other) const
Returns true if other is the same as this point.
jet::Point< T, 2 >::div
Point div(T v) const
Computes this / (v, v).
jet::Point< T, 2 >::at
T & at(size_t i)
Returns reference to the i -th element of the point.
jet::Point< T, 2 >::set
void set(const std::initializer_list< U > &lst)
Set x and y components with given initializer list.
jet::Point< T, 2 >::add
Point add(const Point &v) const
Computes this + (v.x, v.y).
jet::Point< T, 2 >::operator+=
Point & operator+=(const Point &v)
Computes this += (v.x, v.y)
jet::Point< T, 2 >::operator[]
const T & operator[](size_t i) const
Returns const reference to the i -th element of the point.
jet::Point< T, 2 >::Point
constexpr Point()
Constructs default point (0, 0).
Definition: point2.h:37
jet::Point< T, 2 >::subminantAxis
size_t subminantAxis() const
Returns the index of the subminant axis.
jet::Point< T, 2 >::min
T min() const
Returns the minimum value among x and y.
jet
Definition: advection_solver2.h:18
jet::Point< T, 2 >::sum
T sum() const
Returns the sum of all the components (i.e. x + y).
jet::Point< T, 2 >::operator[]
T & operator[](size_t i)
Returns reference to the i -th element of the point.
jet::Point2D
Point2< double > Point2D
Double-type 2D point.
Definition: point2.h:295
jet::Point< T, 2 >::Point
constexpr Point(T x_, T y_)
Constructs point with given parameters x_ and y_.
Definition: point2.h:40
jet::clamp
T clamp(T val, T low, T high)
Returns the clamped value.
jet::Point< T, 2 >::idiv
void idiv(const Point &v)
Computes this /= (v.x, v.y).
jet::operator+
Matrix2x2< T > operator+(const Matrix2x2< T > &a, const Matrix2x2< T > &b)
Returns a + b (element-size).
jet::floor
Point2< T > floor(const Point2< T > &a)
Returns element-wise floored point.
jet::Point< T, 2 >::max
T max() const
Returns the maximum value among x and y.
jet::Point< T, 2 >::imul
void imul(T v)
Computes this *= (v, v).
jet::Point< T, 2 >::idiv
void idiv(T v)
Computes this /= (v, v).
jet::Point2F
Point2< float > Point2F
Float-type 2D point.
Definition: point2.h:292
jet::Point< T, 2 >::operator/=
Point & operator/=(T v)
Computes this /= (v, v)
jet::Point< T, 2 >::imul
void imul(const Point &v)
Computes this *= (v.x, v.y).
jet::Point< T, 2 >::Point
Point(const std::initializer_list< U > &lst)
Constructs point with initializer list.
jet::Point2UI
Point2< size_t > Point2UI
Unsigned integer-type 2D point.
Definition: point2.h:301
jet::Point< T, 2 >::dominantAxis
size_t dominantAxis() const
Returns the index of the dominant axis.
jet::Point< T, 2 >::operator!=
bool operator!=(const Point &v) const
Returns true if other is the not same as this point.
jet::Point< T, 2 >::Point
constexpr Point(const Point &v)
Copy constructor.
Definition: point2.h:47
jet::Point< T, 2 >::operator=
Point & operator=(const Point &v)
Set x and y with other point pt.
jet::Point
Generic N-D point class.
Definition: point.h:23
jet::operator/
Matrix2x2< T > operator/(const Matrix2x2< T > &a, T b)
Returns a' / b, where every element of matrix a' is a.
jet::Point< T, 2 >::operator-=
Point & operator-=(const Point &v)
Computes this -= (v.x, v.y)
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, 2 >::operator*=
Point & operator*=(T v)
Computes this *= (v, v)
jet::Point< T, 2 >::rdiv
Point rdiv(T v) const
Computes (v, v) / this.
jet::Point< T, 2 >::div
Point div(const Point &v) const
Computes this / (v.x, v.y).
jet::operator-
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
jet::Point< T, 2 >::set
void set(T x, T y)
Set x and y components with given parameters.
jet::Point< T, 2 >::rdiv
Point rdiv(const Point &v) const
Computes (v.x, v.y) / this.
jet::Point< T, 2 >::mul
Point mul(T v) const
Computes this * (v, v).
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, 2 >::rsub
Point rsub(const Point &v) const
Computes (v.x, v.y) - this.
jet::Point< T, 2 >::operator/=
Point & operator/=(const Point &v)
Computes this /= (v.x, v.y)
jet::Point< T, 2 >::operator==
bool operator==(const Point &v) const
Returns true if other is the same as this point.
jet::Point< T, 2 >::setZero
void setZero()
Set both x and y to zero.
jet::Point< T, 2 >::sub
Point sub(T v) const
Computes this - (v, v).
jet::Point< T, 2 >::isub
void isub(const Point &v)
Computes this -= (v.x, v.y).
jet::Point< T, 2 >::at
const T & at(size_t i) const
Returns const reference to the i -th element of the point.
jet::Point< T, 2 >::castTo
Point< U, 2 > castTo() const
Returns a point with different value type.
jet::Point< T, 2 >::isub
void isub(T v)
Computes this -= (v, v).