3#include <Core/RaCore.hpp>
13constexpr Scalar
Sqrt2 = Scalar( 1.41421356237309504880 );
14constexpr Scalar e = Scalar( 2.7182818284590452354 );
15constexpr Scalar Pi = Scalar( 3.14159265358979323846 );
16constexpr Scalar InvPi = Scalar( 0.31830988618379067154 );
17constexpr Scalar PiDiv2 = Scalar( 1.57079632679489661923 );
18constexpr Scalar PiDiv3 = Scalar( 1.04719755119659774615 );
19constexpr Scalar PiDiv4 = Scalar( 0.78539816339744830962 );
20constexpr Scalar PiDiv6 = Scalar( 0.52359877559829887307 );
21constexpr Scalar PiMul2 = Scalar( 2 * Pi );
22constexpr Scalar toRad = Scalar( Pi / Scalar( 180.0 ) );
23constexpr Scalar toDeg = Scalar( Scalar( 180.0 ) * InvPi );
52template <
typename Vector_Or_Scalar>
53inline bool checkRange(
const Vector_Or_Scalar& v,
const Scalar& min,
const Scalar& max ) {
55 return clamp( v, min, max ) == v;
64inline T
ipow(
const T& x, uint exp ) {
65 if ( exp == 0 ) {
return T( 1 ); }
66 if ( exp == 1 ) {
return x; }
67 T p =
ipow( x, exp / 2 );
68 if ( ( exp % 2 ) == 0 ) {
return p * p; }
69 else {
return p * p * x; }
75template <
typename T, u
int N>
77 static inline constexpr T pow(
const T& x ) {
78 return ( N % 2 == 0 ) ? IpowHelper<T, N / 2>::pow( x ) * IpowHelper<T, N / 2>::pow( x )
79 : IpowHelper<T, N / 2>::pow( x ) * IpowHelper<T, N / 2>::pow( x ) * x;
84struct IpowHelper<T, 1> {
85 static inline constexpr T pow(
const T& x ) {
return x; }
89struct IpowHelper<T, 0> {
90 static inline constexpr T
pow(
const T& ) {
return T( 1 ); }
94template <u
int N,
typename T>
95inline constexpr T
ipow(
const T& x ) {
96 return IpowHelper<T, N>::pow( x );
101 return ( T( 0 ) < x ) - ( x < T( 0 ) );
106inline constexpr int sign(
const T& val ) {
114inline constexpr T
signNZ(
const T& val ) {
121 return std::clamp( v,
static_cast<T
>( 0 ),
static_cast<T
>( 1 ) );
126inline constexpr T
lerp(
const T& a,
const T& b, Scalar t ) {
127 return ( 1 - t ) * a + t * b;
134 T t =
clamp( ( x - edge0 ) / ( edge1 - edge0 ),
static_cast<T
>( 0 ),
static_cast<T
>( 1 ) );
135 return t * t * ( 3.0 - 2.0 * t );
138template <
typename T,
template <
typename,
int...>
typename M,
int... p>
139M<T, p...>
smoothstep( T edge0, T edge1, M<T, p...> v ) {
constexpr Scalar toRadians(Scalar a)
Useful functions.
bool checkRange(const Vector_Or_Scalar &v, const Scalar &min, const Scalar &max)
T smoothstep(T edge0, T edge1, T x)
As define by https://registry.khronos.org/OpenGL-Refpages/gl4/html/smoothstep.xhtml.
constexpr Scalar toDegrees(Scalar a)
Converts an angle from radians to degrees.
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type areApproxEqual(T x, T y, T espilonBoostFactor=T(10))
Compare two numbers such that |x-y| < espilon*epsilonBoostFactor.
constexpr Scalar Sqrt2
Mathematical constants casted to Scalar. Values taken from math.h.
constexpr T lerp(const T &a, const T &b, Scalar t)
Returns the linear interpolation between a and b.
constexpr T signNZ(const T &val)
constexpr int sign(const T &val)
Returns the sign of any numeric type as { -1, 0, 1}.
T ipow(const T &x, uint exp)
Run-time exponent version.
constexpr T saturate(T v)
Clamps the value between 0 and 1.
Derived::PlainMatrix clamp(const Eigen::MatrixBase< Derived > &v, const Eigen::MatrixBase< DerivedA > &min, const Eigen::MatrixBase< DerivedB > &max)
Component-wise clamp() function on a floating-point vector.
hepler function to manage enum as underlying types in VariableSet