Constants.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Constants.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Constant lists for CubbyFlow.
6 > Created Time: 2017/01/31
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_CONSTANTS_H
10 #define CUBBYFLOW_CONSTANTS_H
11 
12 #include <Core/Utils/Macros.h>
13 
14 namespace CubbyFlow
15 {
16  // MARK: Zero
18  constexpr size_t ZERO_SIZE = 0;
20  constexpr ssize_t ZERO_SSIZE = 0;
21 
23  template <typename T>
24  constexpr T Zero()
25  {
26  return 0;
27  }
28 
30  template <>
31  constexpr float Zero<float>()
32  {
33  return 0.f;
34  }
35 
37  template <>
38  constexpr double Zero<double>()
39  {
40  return 0.0;
41  }
42 
43  // MARK: One
45  constexpr size_t ONE_SIZE = 1;
46 
48  constexpr ssize_t ONE_SSIZE = 1;
49 
51  template <typename T>
52  constexpr T One()
53  {
54  return 1;
55  }
56 
58  template <>
59  constexpr float One<float>()
60  {
61  return 1.f;
62  }
63 
65  template <>
66  constexpr double One<double>()
67  {
68  return 1.0;
69  }
70 
71  // MARK: PI
73  constexpr float PI_FLOAT = 3.14159265358979323846264338327950288f;
75  constexpr double PI_DOUBLE = 3.14159265358979323846264338327950288;
76 
78  template <typename T>
79  constexpr T PI()
80  {
81  return static_cast<T>(PI_DOUBLE);
82  }
83 
85  template <>
86  constexpr float PI<float>()
87  {
88  return PI_FLOAT;
89  }
90 
92  template <>
93  constexpr double PI<double>()
94  {
95  return PI_DOUBLE;
96  }
97 
98  // MARK: PI/2
100  constexpr float HALF_PI_FLOAT = 1.57079632679489661923132169163975144f;
101 
103  constexpr double HALF_PI_DOUBLE = 1.57079632679489661923132169163975144;
104 
106  template <typename T>
107  constexpr T HalfPI()
108  {
109  return static_cast<T>(HALF_PI_DOUBLE);
110  }
111 
113  template <>
114  constexpr float HalfPI<float>()
115  {
116  return HALF_PI_FLOAT;
117  }
118 
120  template <>
121  constexpr double HalfPI<double>()
122  {
123  return HALF_PI_DOUBLE;
124  }
125 
126  // MARK: PI/4
128  constexpr float QUARTER_PI_FLOAT = 0.785398163397448309615660845819875721f;
129 
131  constexpr double QUARTER_PI_DOUBLE = 0.785398163397448309615660845819875721;
132 
134  template <typename T>
135  constexpr T QuarterPI()
136  {
137  return static_cast<T>(QUARTER_PI_DOUBLE);
138  }
139 
141  template <>
142  constexpr float QuarterPI<float>()
143  {
144  return QUARTER_PI_FLOAT;
145  }
146 
148  template <>
149  constexpr double QuarterPI<double>()
150  {
151  return QUARTER_PI_DOUBLE;
152  }
153 
154  // MARK: Physics
156  constexpr double GRAVITY = -9.8;
157 
159  constexpr double WATER_DENSITY = 1000.0;
160 
162  constexpr double SPEED_OF_SOUND_IN_WATER = 1482.0;
163 
164  // MARK: Common enums
166  constexpr int DIRECTION_NONE = 0;
167 
169  constexpr int DIRECTION_LEFT = 1 << 0;
170 
172  constexpr int DIRECTION_RIGHT = 1 << 1;
173 
175  constexpr int DIRECTION_DOWN = 1 << 2;
176 
178  constexpr int DIRECTION_UP = 1 << 3;
179 
181  constexpr int DIRECTION_BACK = 1 << 4;
182 
184  constexpr int DIRECTION_FRONT = 1 << 5;
185 
187  constexpr int DIRECTION_ALL =
191 }
192 
193 #endif
constexpr int DIRECTION_DOWN
Down direction.
Definition: Constants.h:175
constexpr double WATER_DENSITY
Water density.
Definition: Constants.h:159
constexpr int DIRECTION_BACK
Back direction.
Definition: Constants.h:181
constexpr T QuarterPI()
PI/4 for type T.
Definition: Constants.h:135
constexpr float HalfPI< float >()
PI/2 for float.
Definition: Constants.h:114
constexpr T HalfPI()
PI/2 for type T.
Definition: Constants.h:107
constexpr float One< float >()
One for float.
Definition: Constants.h:59
constexpr int DIRECTION_ALL
All direction.
Definition: Constants.h:187
constexpr T One()
One for type T.
Definition: Constants.h:52
constexpr double PI_DOUBLE
Double-type PI.
Definition: Constants.h:75
constexpr int DIRECTION_FRONT
Front direction.
Definition: Constants.h:184
constexpr int DIRECTION_UP
Up direction.
Definition: Constants.h:178
constexpr float PI< float >()
Pi for float.
Definition: Constants.h:86
constexpr float HALF_PI_FLOAT
Float-type PI/2.
Definition: Constants.h:100
constexpr int DIRECTION_RIGHT
RIght direction.
Definition: Constants.h:172
constexpr float QUARTER_PI_FLOAT
Float-type PI/4.
Definition: Constants.h:128
constexpr double HalfPI< double >()
PI/2 for double.
Definition: Constants.h:121
constexpr float Zero< float >()
Zero for float.
Definition: Constants.h:31
constexpr double GRAVITY
Gravity.
Definition: Constants.h:156
constexpr size_t ONE_SIZE
One size_t.
Definition: Constants.h:45
constexpr double PI< double >()
Pi for double.
Definition: Constants.h:93
Definition: pybind11Utils.h:24
constexpr float PI_FLOAT
Float-type PI.
Definition: Constants.h:73
constexpr ssize_t ONE_SSIZE
One ssize_t.
Definition: Constants.h:48
constexpr int DIRECTION_NONE
No direction.
Definition: Constants.h:166
constexpr float QuarterPI< float >()
PI/4 for float.
Definition: Constants.h:142
constexpr double QuarterPI< double >()
PI/4 for double.
Definition: Constants.h:149
constexpr size_t ZERO_SIZE
Zero size_t.
Definition: Constants.h:18
constexpr int DIRECTION_LEFT
Left direction.
Definition: Constants.h:169
constexpr double Zero< double >()
Zero for double.
Definition: Constants.h:38
constexpr double SPEED_OF_SOUND_IN_WATER
Speed of sound in water at 20 degrees Celsius.
Definition: Constants.h:162
constexpr ssize_t ZERO_SSIZE
Zero ssize_t.
Definition: Constants.h:20
constexpr double QUARTER_PI_DOUBLE
Double-type PI/4.
Definition: Constants.h:131
constexpr T Zero()
Zero for type T.
Definition: Constants.h:24
constexpr double One< double >()
One for double.
Definition: Constants.h:66
constexpr T PI()
PI for type T.
Definition: Constants.h:79
constexpr double HALF_PI_DOUBLE
Double-type PI/2.
Definition: Constants.h:103