1 #pragma once
2 
3 /// \file MathBasic.h
4 /// \brief Basic math routines
5 /// \author Pavel Sevecek (sevecek at sirrah.troja.mff.cuni.cz)
6 /// \date 2016-2021
7 
8 #include "objects/Object.h"
9 
10 NAMESPACE_SPH_BEGIN
11 
12 /// Minimum & Maximum value
13 
14 template <typename T>
min(const T & f1,const T & f2)15 INLINE constexpr T min(const T& f1, const T& f2) {
16     return (f1 < f2) ? f1 : f2;
17 }
18 
19 template <typename T>
max(const T & f1,const T & f2)20 INLINE constexpr T max(const T& f1, const T& f2) {
21     return (f1 > f2) ? f1 : f2;
22 }
23 
24 template <typename T, typename... TArgs>
min(const T & f1,const T & f2,const TArgs &...rest)25 INLINE constexpr T min(const T& f1, const T& f2, const TArgs&... rest) {
26     return min(min(f1, f2), rest...);
27 }
28 
29 template <typename T, typename... TArgs>
max(const T & f1,const T & f2,const TArgs &...rest)30 INLINE constexpr T max(const T& f1, const T& f2, const TArgs&... rest) {
31     return max(max(f1, f2), rest...);
32 }
33 
34 template <typename T>
clamp(const T & f,const T & f1,const T & f2)35 INLINE constexpr T clamp(const T& f, const T& f1, const T& f2) {
36     return max(f1, min(f, f2));
37 }
38 
39 template <typename T>
isOdd(const T & f)40 INLINE constexpr bool isOdd(const T& f) {
41     return f & 1;
42 }
43 
44 NAMESPACE_SPH_END
45