Jet  v1.3.3
size3.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_SIZE3_H_
8 #define INCLUDE_JET_SIZE3_H_
9 
10 #include <jet/size2.h>
11 
12 namespace jet {
13 
19 class Size3 {
20  public:
22  size_t x;
23 
25  size_t y;
26 
28  size_t z;
29 
30  // MARK: Constructors
31 
33  constexpr Size3() : x(0), y(0), z(0) {}
34 
36  constexpr Size3(size_t x_, size_t y_, size_t z_) : x(x_), y(y_), z(z_) {}
37 
39  constexpr Size3(const Size2& v, size_t z_) : x(v.x), y(v.y), z(z_) {}
40 
42  template <typename U>
43  Size3(const std::initializer_list<U>& lst);
44 
46  constexpr Size3(const Size3& v) : x(v.x), y(v.y), z(v.z) {}
47 
48  // MARK: Basic setters
49 
51  void set(size_t s);
52 
54  void set(size_t x, size_t y, size_t z);
55 
57  void set(const Size2& sz, size_t z);
58 
60  template <typename U>
61  void set(const std::initializer_list<U>& lst);
62 
64  void set(const Size3& v);
65 
67  void setZero();
68 
69  // MARK: Binary operations: new instance = this (+) v
70 
72  Size3 add(size_t v) const;
73 
75  Size3 add(const Size3& v) const;
76 
78  Size3 sub(size_t v) const;
79 
81  Size3 sub(const Size3& v) const;
82 
84  Size3 mul(size_t v) const;
85 
87  Size3 mul(const Size3& v) const;
89  Size3 div(size_t v) const;
90 
92  Size3 div(const Size3& v) const;
93 
94  // MARK: Binary operations: new instance = v (+) this
95 
97  Size3 rsub(size_t v) const;
98 
100  Size3 rsub(const Size3& v) const;
101 
103  Size3 rdiv(size_t v) const;
104 
106  Size3 rdiv(const Size3& v) const;
107 
108  // MARK: Augmented operations: this (+)= v
109 
111  void iadd(size_t v);
112 
114  void iadd(const Size3& v);
115 
117  void isub(size_t v);
118 
120  void isub(const Size3& v);
121 
123  void imul(size_t v);
124 
126  void imul(const Size3& v);
127 
129  void idiv(size_t v);
130 
132  void idiv(const Size3& v);
133 
134  // MARK: Basic getters
135 
137  const size_t& at(size_t i) const;
138 
140  size_t& at(size_t i);
141 
143  size_t sum() const;
144 
146  size_t min() const;
147 
149  size_t max() const;
150 
152  size_t absmin() const;
153 
155  size_t absmax() const;
156 
158  size_t dominantAxis() const;
159 
161  size_t subminantAxis() const;
162 
164  bool isEqual(const Size3& other) const;
165 
166  // MARK: Operators
167 
169  size_t& operator[](size_t i);
170 
172  const size_t& operator[](size_t i) const;
173 
175  template <typename U>
176  Size3& operator=(const std::initializer_list<U>& lst);
177 
179  Size3& operator=(const Size3& v);
180 
182  Size3& operator+=(size_t v);
183 
185  Size3& operator+=(const Size3& v);
186 
188  Size3& operator-=(size_t v);
189 
191  Size3& operator-=(const Size3& v);
192 
194  Size3& operator*=(size_t v);
195 
197  Size3& operator*=(const Size3& v);
198 
200  Size3& operator/=(size_t v);
201 
203  Size3& operator/=(const Size3& v);
204 
206  bool operator==(const Size3& v) const;
207 
209  bool operator!=(const Size3& v) const;
210 };
211 
214 
217 
219 Size3 operator+(size_t a, const Size3& b);
220 
222 Size3 operator+(const Size3& a, const Size3& b);
223 
225 Size3 operator-(const Size3& a, size_t b);
226 
228 Size3 operator-(size_t a, const Size3& b);
229 
231 Size3 operator-(const Size3& a, const Size3& b);
232 
234 Size3 operator*(const Size3& a, size_t b);
235 
237 Size3 operator*(size_t a, const Size3& b);
238 
240 Size3 operator*(const Size3& a, const Size3& b);
241 
243 Size3 operator/(const Size3& a, size_t b);
244 
246 Size3 operator/(size_t a, const Size3& b);
247 
249 Size3 operator/(const Size3& a, const Size3& b);
250 
252 Size3 min(const Size3& a, const Size3& b);
253 
255 Size3 max(const Size3& a, const Size3& b);
256 
258 Size3 clamp(const Size3& v, const Size3& low, const Size3& high);
259 
261 Size3 ceil(const Size3& a);
262 
264 Size3 floor(const Size3& a);
265 
266 } // namespace jet
267 
268 #include "detail/size3-inl.h"
269 
270 #endif // INCLUDE_JET_SIZE3_H_
jet::ceil
Point2< T > ceil(const Point2< T > &a)
Returns element-wise ceiled point.
jet::Size3::imul
void imul(size_t v)
Computes this *= (v, v, v).
jet::Size3::div
Size3 div(const Size3 &v) const
Computes this / (v.x, v.y, v.z).
jet::Size3::add
Size3 add(const Size3 &v) const
Computes this + (v.x, v.y, v.z).
jet::Size3::imul
void imul(const Size3 &v)
Computes this *= (v.x, v.y, v.z).
jet::Size3::operator!=
bool operator!=(const Size3 &v) const
Returns true if other is the not same as this size.
jet::Size3::rsub
Size3 rsub(const Size3 &v) const
Computes (v.x, v.y, v.z) - this.
jet::Size3::subminantAxis
size_t subminantAxis() const
Returns the index of the subminant axis.
jet::Size3::rsub
Size3 rsub(size_t v) const
Computes (v, v, v) - this.
jet::Size3::Size3
constexpr Size3(const Size3 &v)
Copy constructor.
Definition: size3.h:46
jet::Size3::sum
size_t sum() const
Returns the sum of all the components (i.e. x + y).
jet::Size3::operator-=
Size3 & operator-=(size_t v)
Computes this -= (v, v, v)
jet::Size3::dominantAxis
size_t dominantAxis() const
Returns the index of the dominant axis.
jet::Size3::operator-=
Size3 & operator-=(const Size3 &v)
Computes this -= (v.x, v.y, v.z)
jet::Size3::operator[]
const size_t & operator[](size_t i) const
Returns const 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::Size3::idiv
void idiv(const Size3 &v)
Computes this /= (v.x, v.y, v.z).
jet::Size3::iadd
void iadd(size_t v)
Computes this += (v, v, v).
size2.h
jet::Size3::iadd
void iadd(const Size3 &v)
Computes this += (v.x, v.y, v.z).
jet::Size3::rdiv
Size3 rdiv(const Size3 &v) const
Computes (v.x, v.y, v.z) / this.
jet::Size3::div
Size3 div(size_t v) const
Computes this / (v, v, v).
jet::Size3::operator/=
Size3 & operator/=(size_t v)
Computes this /= (v, v, v)
jet::Size3::set
void set(const Size3 &v)
Set x, y, and z with other size pt.
jet::Size3::sub
Size3 sub(size_t v) const
Computes this - (v, v, v).
jet::Size3::min
size_t min() const
Returns the minimum value among x, y, and z.
jet::Size3::set
void set(size_t s)
Set all x, y, and z components to s.
jet::Size3::z
size_t z
Z (or the third) component of the size.
Definition: size3.h:28
jet::Size3::set
void set(const std::initializer_list< U > &lst)
Set x, y, and z components with given initializer list.
jet
Definition: advection_solver2.h:18
jet::Size3::mul
Size3 mul(size_t v) const
Computes this * (v, v, v).
jet::Size3::Size3
Size3(const std::initializer_list< U > &lst)
Constructs size with initializer list.
jet::Size3::isub
void isub(const Size3 &v)
Computes this -= (v.x, v.y, v.z).
jet::Size3::max
size_t max() const
Returns the maximum value among x, y, and z.
jet::clamp
T clamp(T val, T low, T high)
Returns the clamped value.
jet::Size3::operator*=
Size3 & operator*=(size_t v)
Computes this *= (v, v, v)
jet::operator+
Matrix2x2< T > operator+(const Matrix2x2< T > &a, const Matrix2x2< T > &b)
Returns a + b (element-size).
jet::Size3::set
void set(size_t x, size_t y, size_t z)
Set x, y, and z components with given parameters.
jet::floor
Point2< T > floor(const Point2< T > &a)
Returns element-wise floored point.
jet::Size3::at
const size_t & at(size_t i) const
Returns const reference to the i -th element of the size.
jet::Size3::set
void set(const Size2 &sz, size_t z)
Set x, y, and z components with given sz.x, sz.y, and z.
jet::Size3
3-D size class.
Definition: size3.h:19
jet::Size3::isub
void isub(size_t v)
Computes this -= (v, v, v).
jet::Size3::absmax
size_t absmax() const
Returns the absolute maximum value among x, y, and z.
jet::Size3::Size3
constexpr Size3(size_t x_, size_t y_, size_t z_)
Constructs size with given parameters x_, y_, and z_.
Definition: size3.h:36
jet::Size3::setZero
void setZero()
Set both x, y, and z to zero.
jet::Size2
2-D size class.
Definition: size2.h:19
jet::Size3::rdiv
Size3 rdiv(size_t v) const
Computes (v, v, v) / this.
jet::Size3::mul
Size3 mul(const Size3 &v) const
Computes this * (v.x, v.y, v.z).
jet::Size3::operator[]
size_t & operator[](size_t i)
Returns reference to the i -th element of the size.
jet::Size3::operator/=
Size3 & operator/=(const Size3 &v)
Computes this /= (v.x, v.y, v.z)
jet::Size3::x
size_t x
X (or the first) component of the size.
Definition: size3.h:22
jet::Size3::sub
Size3 sub(const Size3 &v) const
Computes this - (v.x, v.y, v.z).
jet::Size3::operator=
Size3 & operator=(const std::initializer_list< U > &lst)
Set x, y, and z components with given initializer list.
jet::Size3::operator==
bool operator==(const Size3 &v) const
Returns true if other is the same as this size.
jet::operator/
Matrix2x2< T > operator/(const Matrix2x2< T > &a, T b)
Returns a' / b, where every element of matrix a' is a.
jet::Size3::operator=
Size3 & operator=(const Size3 &v)
Set x, y, and z with other size pt.
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::Size3::Size3
constexpr Size3(const Size2 &v, size_t z_)
Constructs size with a 2-D size and a scalar.
Definition: size3.h:39
jet::Size3::Size3
constexpr Size3()
Constructs default size (0, 0, 0).
Definition: size3.h:33
jet::Size3::operator*=
Size3 & operator*=(const Size3 &v)
Computes this *= (v.x, v.y, v.z)
jet::Size3::add
Size3 add(size_t v) const
Computes this + (v, v, v).
jet::operator-
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
jet::Size3::absmin
size_t absmin() const
Returns the absolute minimum value among x, y, and z.
jet::Size3::idiv
void idiv(size_t v)
Computes this /= (v, 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::Size3::operator+=
Size3 & operator+=(const Size3 &v)
Computes this += (v.x, v.y, v.z)
jet::Size3::isEqual
bool isEqual(const Size3 &other) const
Returns true if other is the same as this size.
jet::Size3::y
size_t y
Y (or the second) component of the size.
Definition: size3.h:25
jet::Size3::operator+=
Size3 & operator+=(size_t v)
Computes this += (v, v, v)
jet::Size3::at
size_t & at(size_t i)
Returns reference to the i -th element of the size.