Constants.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_CONSTANTS_HPP
12 #define CUBBYFLOW_CONSTANTS_HPP
13 
14 #include <Core/Utils/Macros.hpp>
15 
16 namespace CubbyFlow
17 {
18 // MARK: Zero
20 constexpr size_t ZERO_SIZE = 0;
22 constexpr ssize_t ZERO_SSIZE = 0;
23 
25 template <typename T>
26 constexpr T Zero()
27 {
28  return 0;
29 }
30 
32 template <>
33 constexpr float Zero<float>()
34 {
35  return 0.f;
36 }
37 
39 template <>
40 constexpr double Zero<double>()
41 {
42  return 0.0;
43 }
44 
45 // MARK: One
47 constexpr size_t ONE_SIZE = 1;
48 
50 constexpr ssize_t ONE_SSIZE = 1;
51 
53 template <typename T>
54 constexpr T One()
55 {
56  return 1;
57 }
58 
60 template <>
61 constexpr float One<float>()
62 {
63  return 1.f;
64 }
65 
67 template <>
68 constexpr double One<double>()
69 {
70  return 1.0;
71 }
72 
73 // MARK: PI
75 constexpr float PI_FLOAT = 3.14159265358979323846264338327950288f;
77 constexpr double PI_DOUBLE = 3.14159265358979323846264338327950288;
78 
80 template <typename T>
81 constexpr T PI()
82 {
83  return static_cast<T>(PI_DOUBLE);
84 }
85 
87 template <>
88 constexpr float PI<float>()
89 {
90  return PI_FLOAT;
91 }
92 
94 template <>
95 constexpr double PI<double>()
96 {
97  return PI_DOUBLE;
98 }
99 
100 // MARK: PI/2
102 constexpr float HALF_PI_FLOAT = 1.57079632679489661923132169163975144f;
103 
105 constexpr double HALF_PI_DOUBLE = 1.57079632679489661923132169163975144;
106 
108 template <typename T>
109 constexpr T HalfPI()
110 {
111  return static_cast<T>(HALF_PI_DOUBLE);
112 }
113 
115 template <>
116 constexpr float HalfPI<float>()
117 {
118  return HALF_PI_FLOAT;
119 }
120 
122 template <>
123 constexpr double HalfPI<double>()
124 {
125  return HALF_PI_DOUBLE;
126 }
127 
128 // MARK: PI/4
130 constexpr float QUARTER_PI_FLOAT = 0.785398163397448309615660845819875721f;
131 
133 constexpr double QUARTER_PI_DOUBLE = 0.785398163397448309615660845819875721;
134 
136 template <typename T>
137 constexpr T QuarterPI()
138 {
139  return static_cast<T>(QUARTER_PI_DOUBLE);
140 }
141 
143 template <>
144 constexpr float QuarterPI<float>()
145 {
146  return QUARTER_PI_FLOAT;
147 }
148 
150 template <>
151 constexpr double QuarterPI<double>()
152 {
153  return QUARTER_PI_DOUBLE;
154 }
155 
156 // MARK: 2*PI
158 constexpr float TWO_PI_FLOAT = static_cast<float>(2.0 * PI_DOUBLE);
159 
161 constexpr double TWO_PI_DOUBLE = 2.0 * PI_DOUBLE;
162 
164 template <typename T>
165 constexpr T TwoPI()
166 {
167  return static_cast<T>(TWO_PI_DOUBLE);
168 }
169 
171 template <>
172 constexpr float TwoPI<float>()
173 {
174  return TWO_PI_FLOAT;
175 }
176 
178 template <>
179 constexpr double TwoPI<double>()
180 {
181  return TWO_PI_DOUBLE;
182 }
183 
184 // MARK: 4*PI
186 constexpr float FOUR_PI_FLOAT = static_cast<float>(4.0 * PI_DOUBLE);
187 
189 constexpr double FOUR_PI_DOUBLE = 4.0 * PI_DOUBLE;
190 
192 template <typename T>
193 constexpr T FourPI()
194 {
195  return static_cast<T>(FOUR_PI_DOUBLE);
196 }
197 
199 template <>
200 constexpr float FourPI<float>()
201 {
202  return FOUR_PI_FLOAT;
203 }
204 
206 template <>
207 constexpr double FourPI<double>()
208 {
209  return FOUR_PI_DOUBLE;
210 }
211 
212 // MARK: 1/PI
214 constexpr float INV_PI_FLOAT = static_cast<float>(1.0 / PI_DOUBLE);
215 
217 constexpr double INV_PI_DOUBLE = 1.0 / PI_DOUBLE;
218 
220 template <typename T>
221 constexpr T InvPI()
222 {
223  return static_cast<T>(INV_PI_DOUBLE);
224 }
225 
227 template <>
228 constexpr float InvPI<float>()
229 {
230  return INV_PI_FLOAT;
231 }
232 
234 template <>
235 constexpr double InvPI<double>()
236 {
237  return INV_PI_DOUBLE;
238 }
239 
240 // MARK: 1/2*PI
242 constexpr float INV_TWO_PI_FLOAT = static_cast<float>(0.5 / PI_DOUBLE);
243 
245 constexpr double INV_TWO_PI_DOUBLE = 0.5 / PI_DOUBLE;
246 
248 template <typename T>
249 constexpr T InvTwoPI()
250 {
251  return static_cast<T>(INV_TWO_PI_DOUBLE);
252 }
253 
255 template <>
256 constexpr float InvTwoPI<float>()
257 {
258  return INV_TWO_PI_FLOAT;
259 }
260 
262 template <>
263 constexpr double InvTwoPI<double>()
264 {
265  return INV_TWO_PI_DOUBLE;
266 }
267 
268 // MARK: 1/4*PI
270 constexpr float INV_FOUR_PI_FLOAT = static_cast<float>(0.25 / PI_DOUBLE);
271 
273 constexpr double INV_FOUR_PI_DOUBLE = 0.25 / PI_DOUBLE;
274 
276 template <typename T>
277 constexpr T InvFourPI()
278 {
279  return static_cast<T>(INV_FOUR_PI_DOUBLE);
280 }
281 
283 template <>
284 constexpr float InvFourPI<float>()
285 {
286  return INV_FOUR_PI_FLOAT;
287 }
288 
290 template <>
291 constexpr double InvFourPI<double>()
292 {
293  return INV_FOUR_PI_DOUBLE;
294 }
295 
296 // MARK: Physics
298 constexpr float GRAVITY_FLOAT = -9.8f;
299 constexpr double GRAVITY = -9.8;
300 
302 constexpr float WATER_DENSITY_FLOAT = 1000.0f;
303 constexpr double WATER_DENSITY = 1000.0;
304 
306 constexpr float SPEED_OF_SOUND_IN_WATER_FLOAT = 1482.0f;
307 constexpr double SPEED_OF_SOUND_IN_WATER = 1482.0;
308 
309 // MARK: Common enums
311 constexpr int DIRECTION_NONE = 0;
312 
314 constexpr int DIRECTION_LEFT = 1 << 0;
315 
317 constexpr int DIRECTION_RIGHT = 1 << 1;
318 
320 constexpr int DIRECTION_DOWN = 1 << 2;
321 
323 constexpr int DIRECTION_UP = 1 << 3;
324 
326 constexpr int DIRECTION_BACK = 1 << 4;
327 
329 constexpr int DIRECTION_FRONT = 1 << 5;
330 
332 constexpr int DIRECTION_ALL = DIRECTION_LEFT | DIRECTION_RIGHT |
333  DIRECTION_DOWN | DIRECTION_UP | DIRECTION_BACK |
335 } // namespace CubbyFlow
336 
337 #endif
constexpr int DIRECTION_DOWN
Down direction.
Definition: Constants.hpp:320
constexpr float TwoPI< float >()
2*PI for float.
Definition: Constants.hpp:172
constexpr double INV_PI_DOUBLE
Double-type 1/PI.
Definition: Constants.hpp:217
constexpr double WATER_DENSITY
Definition: Constants.hpp:303
constexpr float SPEED_OF_SOUND_IN_WATER_FLOAT
Speed of sound in water at 20 degrees Celsius.
Definition: Constants.hpp:306
constexpr int DIRECTION_BACK
Back direction.
Definition: Constants.hpp:326
constexpr T QuarterPI()
PI/4 for type T.
Definition: Constants.hpp:137
constexpr float INV_TWO_PI_FLOAT
Float-type 1/2*PI.
Definition: Constants.hpp:242
constexpr float HalfPI< float >()
PI/2 for float.
Definition: Constants.hpp:116
constexpr T HalfPI()
PI/2 for type T.
Definition: Constants.hpp:109
constexpr float One< float >()
One for float.
Definition: Constants.hpp:61
constexpr int DIRECTION_ALL
All direction.
Definition: Constants.hpp:332
constexpr float FOUR_PI_FLOAT
Float-type 4*PI.
Definition: Constants.hpp:186
constexpr T One()
One for type T.
Definition: Constants.hpp:54
constexpr double PI_DOUBLE
Double-type PI.
Definition: Constants.hpp:77
constexpr int DIRECTION_FRONT
Front direction.
Definition: Constants.hpp:329
constexpr float WATER_DENSITY_FLOAT
Water density.
Definition: Constants.hpp:302
constexpr int DIRECTION_UP
Up direction.
Definition: Constants.hpp:323
constexpr double InvFourPI< double >()
1/4*PI for double.
Definition: Constants.hpp:291
constexpr float PI< float >()
Pi for float.
Definition: Constants.hpp:88
constexpr float HALF_PI_FLOAT
Float-type PI/2.
Definition: Constants.hpp:102
constexpr int DIRECTION_RIGHT
Right direction.
Definition: Constants.hpp:317
constexpr float QUARTER_PI_FLOAT
Float-type PI/4.
Definition: Constants.hpp:130
constexpr double HalfPI< double >()
PI/2 for double.
Definition: Constants.hpp:123
constexpr float Zero< float >()
Zero for float.
Definition: Constants.hpp:33
constexpr double GRAVITY
Definition: Constants.hpp:299
constexpr size_t ONE_SIZE
One size_t.
Definition: Constants.hpp:47
constexpr T InvFourPI()
1/4*PI for type T.
Definition: Constants.hpp:277
constexpr float FourPI< float >()
4*PI for float.
Definition: Constants.hpp:200
constexpr float InvPI< float >()
1/PI for float.
Definition: Constants.hpp:228
constexpr T TwoPI()
2*PI for type T.
Definition: Constants.hpp:165
constexpr T FourPI()
4*PI for type T.
Definition: Constants.hpp:193
constexpr double InvPI< double >()
1/PI for double.
Definition: Constants.hpp:235
constexpr double PI< double >()
Pi for double.
Definition: Constants.hpp:95
Definition: pybind11Utils.hpp:20
constexpr double TwoPI< double >()
2*PI for double.
Definition: Constants.hpp:179
constexpr float PI_FLOAT
Float-type PI.
Definition: Constants.hpp:75
constexpr ssize_t ONE_SSIZE
One ssize_t.
Definition: Constants.hpp:50
constexpr double INV_TWO_PI_DOUBLE
Double-type 1/2*PI.
Definition: Constants.hpp:245
constexpr int DIRECTION_NONE
No direction.
Definition: Constants.hpp:311
constexpr float QuarterPI< float >()
PI/4 for float.
Definition: Constants.hpp:144
constexpr float TWO_PI_FLOAT
Float-type 2*PI.
Definition: Constants.hpp:158
constexpr T InvTwoPI()
1/2*PI for type T.
Definition: Constants.hpp:249
constexpr double QuarterPI< double >()
PI/4 for double.
Definition: Constants.hpp:151
constexpr float INV_FOUR_PI_FLOAT
Float-type 1/4*PI.
Definition: Constants.hpp:270
constexpr float InvTwoPI< float >()
1/2*PI for float.
Definition: Constants.hpp:256
constexpr size_t ZERO_SIZE
Zero size_t.
Definition: Constants.hpp:20
constexpr int DIRECTION_LEFT
Left direction.
Definition: Constants.hpp:314
constexpr double Zero< double >()
Zero for double.
Definition: Constants.hpp:40
constexpr double SPEED_OF_SOUND_IN_WATER
Definition: Constants.hpp:307
constexpr ssize_t ZERO_SSIZE
Zero ssize_t.
Definition: Constants.hpp:22
constexpr double INV_FOUR_PI_DOUBLE
Double-type 1/4*PI.
Definition: Constants.hpp:273
constexpr float INV_PI_FLOAT
Float-type 1/PI.
Definition: Constants.hpp:214
constexpr double FourPI< double >()
4*PI for double.
Definition: Constants.hpp:207
constexpr double InvTwoPI< double >()
1/2*PI for double.
Definition: Constants.hpp:263
constexpr double QUARTER_PI_DOUBLE
Double-type PI/4.
Definition: Constants.hpp:133
constexpr float InvFourPI< float >()
1/4*PI for float.
Definition: Constants.hpp:284
constexpr double TWO_PI_DOUBLE
Double-type 2*PI.
Definition: Constants.hpp:161
constexpr double FOUR_PI_DOUBLE
Double-type 4*pi.
Definition: Constants.hpp:189
constexpr T Zero()
Zero for type T.
Definition: Constants.hpp:26
constexpr T InvPI()
1/PI for type T.
Definition: Constants.hpp:221
constexpr double One< double >()
One for double.
Definition: Constants.hpp:68
constexpr float GRAVITY_FLOAT
Gravity.
Definition: Constants.hpp:298
constexpr T PI()
PI for type T.
Definition: Constants.hpp:81
constexpr double HALF_PI_DOUBLE
Double-type PI/2.
Definition: Constants.hpp:105