Functors-Impl.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_FUNCTORS_IMPL_HPP
12 #define CUBBYFLOW_FUNCTORS_IMPL_HPP
13 
14 #include <Core/Math/MathUtils.hpp>
15 
16 #include <cmath>
17 
18 namespace CubbyFlow
19 {
20 template <typename T>
21 constexpr T NoOp<T>::operator()(const T& a) const
22 {
23  return a;
24 }
25 
26 template <typename T, typename U>
27 constexpr U TypeCast<T, U>::operator()(const T& a) const
28 {
29  return static_cast<U>(a);
30 }
31 
32 template <typename T>
33 constexpr T DoCeil<T>::operator()(const T& a) const
34 {
35  return std::ceil(a);
36 }
37 
38 template <typename T>
39 constexpr T DoFloor<T>::operator()(const T& a) const
40 {
41  return std::floor(a);
42 }
43 
44 template <typename T>
45 constexpr T RMinus<T>::operator()(const T& a, const T& b) const
46 {
47  return b - a;
48 }
49 
50 template <typename T>
51 constexpr T RDivides<T>::operator()(const T& a, const T& b) const
52 {
53  return b / a;
54 }
55 
56 template <typename T>
57 constexpr T DoMin<T>::operator()(const T& a, const T& b) const
58 {
59  return std::min(a, b);
60 }
61 
62 template <typename T>
63 constexpr T DoMax<T>::operator()(const T& a, const T& b) const
64 {
65  return std::max(a, b);
66 }
67 
68 template <typename T>
69 constexpr T DoAbsMin<T>::operator()(const T& a, const T& b) const
70 {
71  return AbsMin(a, b);
72 }
73 
74 template <typename T>
75 constexpr T DoAbsMax<T>::operator()(const T& a, const T& b) const
76 {
77  return AbsMax(a, b);
78 }
79 
80 template <typename T>
81 constexpr bool SimilarTo<T>::operator()(const T& a, const T& b) const
82 {
83  return std::fabs(a - b) <= tolerance;
84 }
85 
86 template <typename T>
87 constexpr T DoClamp<T>::operator()(const T& a, const T& low,
88  const T& high) const
89 {
90  return Clamp(a, low, high);
91 }
92 } // namespace CubbyFlow
93 
94 #endif
constexpr bool operator()(const T &a, const T &b) const
Definition: Functors-Impl.hpp:81
std::enable_if_t< std::is_arithmetic< T >::value, T > Clamp(T val, T low, T high)
Returns the clamped value.
Definition: MathUtils-Impl.hpp:166
constexpr U operator()(const T &a) const
Definition: Functors-Impl.hpp:27
constexpr T operator()(const T &a) const
Definition: Functors-Impl.hpp:33
constexpr T operator()(const T &a) const
Definition: Functors-Impl.hpp:21
constexpr T operator()(const T &a, const T &b) const
Definition: Functors-Impl.hpp:75
Definition: pybind11Utils.hpp:20
constexpr T operator()(const T &a, const T &b) const
Definition: Functors-Impl.hpp:69
constexpr T operator()(const T &a) const
Definition: Functors-Impl.hpp:39
constexpr T operator()(const T &a, const T &b) const
Definition: Functors-Impl.hpp:57
constexpr T operator()(const T &a, const T &b) const
Definition: Functors-Impl.hpp:45
std::enable_if_t< std::is_arithmetic< T >::value, T > AbsMax(T x, T y)
Returns the absolute maximum value among the two inputs.
Definition: MathUtils-Impl.hpp:84
std::enable_if_t< std::is_arithmetic< T >::value, T > AbsMin(T x, T y)
Returns the absolute minimum value among the two inputs.
Definition: MathUtils-Impl.hpp:78
constexpr T operator()(const T &a, const T &b) const
Definition: Functors-Impl.hpp:63
constexpr T operator()(const T &a, const T &low, const T &high) const
Definition: Functors-Impl.hpp:87
constexpr T operator()(const T &a, const T &b) const
Definition: Functors-Impl.hpp:51