MathUtils.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: MathUtils.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Mathematics util functions for CubbyFlow.
6 > Created Time: 2017/02/26
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_MATH_UTILS_H
10 #define CUBBYFLOW_MATH_UTILS_H
11 
12 #include <Core/Utils/Macros.h>
13 
14 #include <cstddef>
15 #include <limits>
16 
17 namespace CubbyFlow
18 {
30  template <typename T>
31  inline bool Similar(T x, T y, T eps = std::numeric_limits<T>::epsilon());
32 
42  template <typename T>
43  inline T Sign(T x);
44 
55  template <typename T>
56  inline T AbsMin(T x, T y);
57 
68  template <typename T>
69  inline T AbsMax(T x, T y);
70 
72  template <typename T>
73  inline T AbsMinN(const T* x, size_t n);
74 
76  template <typename T>
77  inline T AbsMaxN(const T* x, size_t n);
78 
79  template <typename T>
80  inline size_t ArgMin2(T x, T y);
81 
82  template <typename T>
83  inline size_t ArgMax2(T x, T y);
84 
85  template <typename T>
86  inline size_t ArgMin3(T x, T y, T z);
87 
88  template <typename T>
89  inline size_t ArgMax3(T x, T y, T z);
90 
100  template <typename T>
101  inline T Square(T x);
102 
112  template <typename T>
113  inline T Cubic(T x);
114 
126  template <typename T>
127  inline T Clamp(T val, T low, T high);
128 
138  template <typename T>
139  inline T DegreesToRadians(T angleInDegrees);
140 
150  template <typename T>
151  inline T RadiansToDegrees(T angleInRadians);
152 
164  template<class T>
165  inline void GetBarycentric(T x, ssize_t iLow, ssize_t iHigh, ssize_t* i, T* t);
166 
179  template<typename S, typename T>
180  inline S Lerp(const S& f0, const S& f1, T t);
181 
183  template<typename S, typename T>
184  inline S BiLerp(
185  const S& f00, const S& f10,
186  const S& f01, const S& f11,
187  T tx, T ty);
188 
190  template<typename S, typename T>
191  inline S TriLerp(
192  const S& f000, const S& f100,
193  const S& f010, const S& f110,
194  const S& f001, const S& f101,
195  const S& f011, const S& f111,
196  T tx, T ty, T tz);
197 
199  template <typename S, typename T>
200  inline S CatmullRom(const S& f0, const S& f1, const S& f2, const S& f3, T t);
201 
203  template <typename T>
204  inline T MonotonicCatmullRom(const T& f0, const T& f1, const T& f2, const T& f3, T t);
205 }
206 
208 
209 #endif
T AbsMin(T x, T y)
Returns the absolute minimum value among the two inputs.
Definition: MathUtils-Impl.h:39
S Lerp(const S &value0, const S &value1, T f)
Computes linear interpolation.
Definition: MathUtils-Impl.h:184
T AbsMaxN(const T *x, size_t n)
Returns absolute maximum among n-elements.
Definition: MathUtils-Impl.h:64
size_t ArgMin2(T x, T y)
Definition: MathUtils-Impl.h:77
T Square(T x)
Returns the square of x.
Definition: MathUtils-Impl.h:111
size_t ArgMax3(T x, T y, T z)
Definition: MathUtils-Impl.h:100
size_t ArgMax2(T x, T y)
Definition: MathUtils-Impl.h:83
S CatmullRom(const S &f0, const S &f1, const S &f2, const S &f3, T f)
Computes Catmull-Rom interpolation.
Definition: MathUtils-Impl.h:213
T AbsMinN(const T *x, size_t n)
Returns absolute minimum among n-elements.
Definition: MathUtils-Impl.h:51
Definition: pybind11Utils.h:24
T Clamp(T val, T low, T high)
Returns the clamped value.
Definition: MathUtils-Impl.h:123
S BiLerp(const S &f00, const S &f10, const S &f01, const S &f11, T tx, T ty)
Computes bilinear interpolation.
Definition: MathUtils-Impl.h:190
T Cubic(T x)
Returns the cubic of x.
Definition: MathUtils-Impl.h:117
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 fz)
Computes trilinear interpolation.
Definition: MathUtils-Impl.h:199
bool Similar(T x, T y, T eps)
Returns true if x and y are similar.
Definition: MathUtils-Impl.h:20
T MonotonicCatmullRom(const T &f0, const T &f1, const T &f2, const T &f3, T f)
Computes monotonic Catmull-Rom interpolation.
Definition: MathUtils-Impl.h:228
T AbsMax(T x, T y)
Returns the absolute maximum value among the two inputs.
Definition: MathUtils-Impl.h:45
T Sign(T x)
Returns the sign of the value.
Definition: MathUtils-Impl.h:26
size_t ArgMin3(T x, T y, T z)
Definition: MathUtils-Impl.h:89
T DegreesToRadians(T angleInDegrees)
Converts degrees to radians.
Definition: MathUtils-Impl.h:139
T RadiansToDegrees(T angleInRadians)
Converts radians to degrees.
Definition: MathUtils-Impl.h:145
void GetBarycentric(T x, ssize_t iLow, ssize_t iHigh, ssize_t *i, T *f)
Gets the barycentric coordinate.
Definition: MathUtils-Impl.h:151