Jet  v1.3.3
size2.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_SIZE2_H_
8 #define INCLUDE_JET_SIZE2_H_
9 
10 #include <jet/size.h>
11 
12 namespace jet {
13 
19 class Size2 {
20  public:
22  size_t x;
23 
25  size_t y;
26 
27  // MARK: Constructors
28 
30  constexpr Size2() : x(0), y(0) {}
31 
33  constexpr Size2(size_t x_, size_t y_) : x(x_), y(y_) {}
34 
36  template <typename U>
37  Size2(const std::initializer_list<U>& lst);
38 
40  constexpr Size2(const Size2& v) : x(v.x), y(v.y) {}
41 
42  // MARK: Basic setters
43 
45  void set(size_t s);
46 
48  void set(size_t x, size_t y);
49 
51  template <typename U>
52  void set(const std::initializer_list<U>& lst);
53 
55  void set(const Size2& pt);
56 
58  void setZero();
59 
60  // MARK: Binary operations: new instance = this (+) v
61 
63  Size2 add(size_t v) const;
64 
66  Size2 add(const Size2& v) const;
67 
69  Size2 sub(size_t v) const;
70 
72  Size2 sub(const Size2& v) const;
73 
75  Size2 mul(size_t v) const;
76 
78  Size2 mul(const Size2& v) const;
79 
81  Size2 div(size_t v) const;
82 
84  Size2 div(const Size2& v) const;
85 
86  // MARK: Binary operations: new instance = v (+) this
87 
89  Size2 rsub(size_t v) const;
90 
92  Size2 rsub(const Size2& v) const;
93 
95  Size2 rdiv(size_t v) const;
96 
98  Size2 rdiv(const Size2& v) const;
99 
100  // MARK: Augmented operations: this (+)= v
101 
103  void iadd(size_t v);
104 
106  void iadd(const Size2& v);
107 
109  void isub(size_t v);
110 
112  void isub(const Size2& v);
113 
115  void imul(size_t v);
116 
118  void imul(const Size2& v);
119 
121  void idiv(size_t v);
122 
124  void idiv(const Size2& v);
125 
126  // MARK: Basic getters
127 
129  const size_t& at(size_t i) const;
130 
132  size_t& at(size_t i);
133 
135  size_t sum() const;
136 
138  size_t min() const;
139 
141  size_t max() const;
142 
144  size_t absmin() const;
145 
147  size_t absmax() const;
148 
150  size_t dominantAxis() const;
151 
153  size_t subminantAxis() const;
154 
156  bool isEqual(const Size2& other) const;
157 
158  // MARK: Operators
159 
161  size_t& operator[](size_t i);
162 
164  const size_t& operator[](size_t i) const;
165 
167  template <typename U>
168  Size2& operator=(const std::initializer_list<U>& lst);
169 
171  Size2& operator=(const Size2& v);
172 
174  Size2& operator+=(size_t v);
175 
177  Size2& operator+=(const Size2& v);
178 
180  Size2& operator-=(size_t v);
181 
183  Size2& operator-=(const Size2& v);
184 
186  Size2& operator*=(size_t v);
187 
189  Size2& operator*=(const Size2& v);
190 
192  Size2& operator/=(size_t v);
193 
195  Size2& operator/=(const Size2& v);
196 
198  bool operator==(const Size2& v) const;
199 
201  bool operator!=(const Size2& v) const;
202 };
203 
206 
209 
211 Size2 operator+(size_t a, const Size2& b);
212 
214 Size2 operator+(const Size2& a, const Size2& b);
215 
217 Size2 operator-(const Size2& a, size_t b);
218 
220 Size2 operator-(size_t a, const Size2& b);
221 
223 Size2 operator-(const Size2& a, const Size2& b);
224 
226 Size2 operator*(const Size2& a, size_t b);
227 
229 Size2 operator*(size_t a, const Size2& b);
230 
232 Size2 operator*(const Size2& a, const Size2& b);
233 
235 Size2 operator/(const Size2& a, size_t b);
236 
238 Size2 operator/(size_t a, const Size2& b);
239 
241 Size2 operator/(const Size2& a, const Size2& b);
242 
244 Size2 min(const Size2& a, const Size2& b);
245 
247 Size2 max(const Size2& a, const Size2& b);
248 
250 Size2 clamp(const Size2& v, const Size2& low,
251  const Size2& high);
252 
254 Size2 ceil(const Size2& a);
255 
257 Size2 floor(const Size2& a);
258 
259 } // namespace jet
260 
261 #include "detail/size2-inl.h"
262 
263 #endif // INCLUDE_JET_SIZE2_H_
jet::Size2::sum
size_t sum() const
Returns the sum of all the components (i.e. x + y).
jet::Size2::idiv
void idiv(const Size2 &v)
Computes this /= (v.x, v.y).
jet::ceil
Point2< T > ceil(const Point2< T > &a)
Returns element-wise ceiled point.
jet::Size2::Size2
constexpr Size2(const Size2 &v)
Copy constructor.
Definition: size2.h:40
jet::Size2::set
void set(const std::initializer_list< U > &lst)
Set x and y components with given initializer list.
jet::Size2::iadd
void iadd(const Size2 &v)
Computes this += (v.x, v.y).
jet::Size2::rsub
Size2 rsub(size_t v) const
Computes (v, v) - this.
jet::Size2::isub
void isub(const Size2 &v)
Computes this -= (v.x, v.y).
jet::Size2::mul
Size2 mul(const Size2 &v) const
Computes this * (v.x, v.y).
jet::Size2::at
size_t & at(size_t i)
Returns reference to the i -th element of the size.
jet::Size2::operator[]
size_t & operator[](size_t i)
Returns reference to the i -th element of the size.
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::Size2::imul
void imul(const Size2 &v)
Computes this *= (v.x, v.y).
jet::Size2::operator/=
Size2 & operator/=(size_t v)
Computes this /= (v, v)
jet::Size2::imul
void imul(size_t v)
Computes this *= (v, v).
jet::Size2::div
Size2 div(const Size2 &v) const
Computes this / (v.x, v.y).
jet::Size2::sub
Size2 sub(size_t v) const
Computes this - (v, v).
jet::Size2::idiv
void idiv(size_t v)
Computes this /= (v, v).
jet::Size2::Size2
constexpr Size2()
Constructs default size (0, 0).
Definition: size2.h:30
jet::Size2::set
void set(size_t s)
Set both x and y components to s.
jet::Size2::rdiv
Size2 rdiv(size_t v) const
Computes (v, v) / this.
jet::Size2::absmax
size_t absmax() const
Returns the absolute maximum value among x and y.
jet::Size2::isEqual
bool isEqual(const Size2 &other) const
Returns true if other is the same as this size.
jet
Definition: advection_solver2.h:18
jet::Size2::operator+=
Size2 & operator+=(size_t v)
Computes this += (v, v)
jet::Size2::operator=
Size2 & operator=(const Size2 &v)
Set x and y with other size pt.
jet::Size2::x
size_t x
X (or the first) component of the size.
Definition: size2.h:22
jet::Size2::Size2
constexpr Size2(size_t x_, size_t y_)
Constructs size with given parameters x_ and y_.
Definition: size2.h:33
jet::Size2::y
size_t y
Y (or the second) component of the size.
Definition: size2.h:25
jet::Size2::subminantAxis
size_t subminantAxis() const
Returns the index of the subminant axis.
jet::Size2::rsub
Size2 rsub(const Size2 &v) const
Computes (v.x, v.y) - this.
jet::clamp
T clamp(T val, T low, T high)
Returns the clamped value.
jet::Size2::add
Size2 add(size_t v) const
Computes this + (v, v).
jet::Size2::isub
void isub(size_t v)
Computes this -= (v, v).
jet::Size2::add
Size2 add(const Size2 &v) const
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::Size2::iadd
void iadd(size_t v)
Computes this += (v, v).
jet::floor
Point2< T > floor(const Point2< T > &a)
Returns element-wise floored point.
jet::Size2::operator==
bool operator==(const Size2 &v) const
Returns true if other is the same as this size.
jet::Size2::operator+=
Size2 & operator+=(const Size2 &v)
Computes this += (v.x, v.y)
jet::Size2::operator-=
Size2 & operator-=(const Size2 &v)
Computes this -= (v.x, v.y)
jet::Size2::sub
Size2 sub(const Size2 &v) const
Computes this - (v.x, v.y).
jet::Size2::operator=
Size2 & operator=(const std::initializer_list< U > &lst)
Set x and y components with given initializer list.
jet::Size2::rdiv
Size2 rdiv(const Size2 &v) const
Computes (v.x, v.y) / this.
jet::Size2::operator-=
Size2 & operator-=(size_t v)
Computes this -= (v, v)
jet::Size2::dominantAxis
size_t dominantAxis() const
Returns the index of the dominant axis.
jet::Size2::operator!=
bool operator!=(const Size2 &v) const
Returns true if other is the not same as this size.
jet::Size2
2-D size class.
Definition: size2.h:19
jet::Size2::div
Size2 div(size_t v) const
Computes this / (v, v).
jet::Size2::max
size_t max() const
Returns the maximum value among x and y.
jet::Size2::mul
Size2 mul(size_t v) const
Computes this * (v, v).
jet::Size2::min
size_t min() const
Returns the minimum value among x and y.
jet::operator/
Matrix2x2< T > operator/(const Matrix2x2< T > &a, T b)
Returns a' / b, where every element of matrix a' is a.
jet::Size2::operator*=
Size2 & operator*=(const Size2 &v)
Computes this *= (v.x, v.y)
jet::Size2::Size2
Size2(const std::initializer_list< U > &lst)
Constructs size with initializer list.
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::Size2::set
void set(size_t x, size_t y)
Set x and y components with given parameters.
jet::Size2::at
const size_t & at(size_t i) const
Returns const reference to the i -th element of the size.
jet::operator-
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
jet::Size2::absmin
size_t absmin() const
Returns the absolute minimum value among x and y.
jet::Size2::operator*=
Size2 & operator*=(size_t v)
Computes this *= (v, v)
jet::Size2::operator[]
const size_t & operator[](size_t i) const
Returns const reference to the i -th element of the size.
jet::operator*
Matrix2x2< T > operator*(const Matrix2x2< T > &a, T b)
Returns a * b', where every element of matrix b' is b.
jet::Size2::setZero
void setZero()
Set both x and y to zero.
size.h
jet::Size2::set
void set(const Size2 &pt)
Set x and y with other size pt.
jet::Size2::operator/=
Size2 & operator/=(const Size2 &v)
Computes this /= (v.x, v.y)