Jet  v1.3.3
math_utils.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_MATH_UTILS_H_
8 #define INCLUDE_JET_MATH_UTILS_H_
9 
10 #include <jet/macros.h>
11 #include <cstddef>
12 #include <limits>
13 
14 namespace jet {
15 
27 template <typename T>
28 inline bool similar(T x, T y, T eps = std::numeric_limits<T>::epsilon());
29 
39 template <typename T>
40 inline T sign(T x);
41 
53 template <typename T>
54 inline T min3(T x, T y, T z);
55 
67 template <typename T>
68 inline T max3(T x, T y, T z);
69 
71 template <typename T>
72 inline T minn(const T* x, size_t n);
73 
75 template <typename T>
76 inline T maxn(const T* x, size_t n);
77 
88 template <typename T>
89 inline T absmin(T x, T y);
90 
101 template <typename T>
102 inline T absmax(T x, T y);
103 
105 template <typename T>
106 inline T absminn(const T* x, size_t n);
107 
109 template <typename T>
110 inline T absmaxn(const T* x, size_t n);
111 
112 template <typename T>
113 inline size_t argmin2(T x, T y);
114 
115 template <typename T>
116 inline size_t argmax2(T x, T y);
117 
118 template <typename T>
119 inline size_t argmin3(T x, T y, T z);
120 
121 template <typename T>
122 inline size_t argmax3(T x, T y, T z);
123 
133 template <typename T>
134 inline T square(T x);
135 
145 template <typename T>
146 inline T cubic(T x);
147 
159 template <typename T>
160 inline T clamp(T val, T low, T high);
161 
171 template <typename T>
172 inline T degreesToRadians(T angleInDegrees);
173 
183 template <typename T>
184 inline T radiansToDegrees(T angleInRadians);
185 
197 template <class T>
198 inline void getBarycentric(T x, ssize_t iLow, ssize_t iHigh, ssize_t* i, T* t);
199 
212 template <typename S, typename T>
213 inline S lerp(const S& f0, const S& f1, T t);
214 
216 template <typename S, typename T>
217 inline S bilerp(const S& f00, const S& f10, const S& f01, const S& f11, T tx,
218  T ty);
219 
221 template <typename S, typename T>
222 inline S trilerp(const S& f000, const S& f100, const S& f010, const S& f110,
223  const S& f001, const S& f101, const S& f011, const S& f111,
224  T tx, T ty, T tz);
225 
227 template <typename S, typename T>
228 inline S catmullRom(const S& f0, const S& f1, const S& f2, const S& f3, T t);
229 
231 template <typename T>
232 inline T monotonicCatmullRom(const T& f0, const T& f1, const T& f2, const T& f3,
233  T t);
234 
235 } // namespace jet
236 
237 #include "detail/math_utils-inl.h"
238 
239 #endif // INCLUDE_JET_MATH_UTILS_H_
jet::absminn
T absminn(const T *x, size_t n)
Returns absolute minimum among n-elements.
jet::argmax2
size_t argmax2(T x, T y)
jet::argmax3
size_t argmax3(T x, T y, T z)
jet::radiansToDegrees
T radiansToDegrees(T angleInRadians)
Converts radians to degrees.
macros.h
jet::trilerp
S trilerp(const S &f000, const S &f100, const S &f010, const S &f110, const S &f001, const S &f101, const S &f011, const S &f111, T tx, T ty, T tz)
Computes trilinear interpolation.
jet::min3
T min3(T x, T y, T z)
Returns the minimum value among three inputs.
jet::sign
T sign(T x)
Returns the sign of the value.
jet::square
T square(T x)
Returns the square of x.
jet::argmin3
size_t argmin3(T x, T y, T z)
jet
Definition: advection_solver2.h:18
jet::minn
T minn(const T *x, size_t n)
Returns minimum among n-elements.
jet::getBarycentric
void getBarycentric(T x, ssize_t iLow, ssize_t iHigh, ssize_t *i, T *t)
Gets the barycentric coordinate.
jet::absmaxn
T absmaxn(const T *x, size_t n)
Returns absolute maximum among n-elements.
jet::cubic
T cubic(T x)
Returns the cubic of x.
jet::clamp
T clamp(T val, T low, T high)
Returns the clamped value.
jet::absmax
T absmax(T x, T y)
Returns the absolute maximum value among the two inputs.
jet::monotonicCatmullRom
T monotonicCatmullRom(const T &f0, const T &f1, const T &f2, const T &f3, T t)
Computes monotonic Catmull-Rom interpolation.
jet::max3
T max3(T x, T y, T z)
Returns the maximum value among three inputs.
jet::lerp
S lerp(const S &f0, const S &f1, T t)
Computes linear interpolation.
jet::argmin2
size_t argmin2(T x, T y)
jet::catmullRom
S catmullRom(const S &f0, const S &f1, const S &f2, const S &f3, T t)
Computes Catmull-Rom interpolation.
jet::maxn
T maxn(const T *x, size_t n)
Returns maximum among n-elements.
jet::absmin
T absmin(T x, T y)
Returns the absolute minimum value among the two inputs.
jet::degreesToRadians
T degreesToRadians(T angleInDegrees)
Converts degrees to radians.
jet::bilerp
S bilerp(const S &f00, const S &f10, const S &f01, const S &f11, T tx, T ty)
Computes bilinear interpolation.
jet::similar
bool similar(T x, T y, T eps=std::numeric_limits< T >::epsilon())
Returns true if x and y are similar.