29 return std::sqrt(
x *
x +
y *
y);
32 #ifdef DEG2RAD // functions are preferred over macros 39 #define M_PI 3.14159265358979323846 45 inline float DEG2RAD(
const float x) {
return x * float(
M_PI) / 180.0f; }
51 inline float RAD2DEG(
const float x) {
return x * 180.0f / float(
M_PI); }
53 #define M_PIl 3.14159265358979323846264338327950288L 54 #define M_2PIl (2.0L * 3.14159265358979323846264338327950288L) 57 inline long double DEG2RAD(
const long double x) {
return x *
M_PIl / 180.0; }
59 inline long double RAD2DEG(
const long double x) {
return x * 180.0 /
M_PIl; }
63 #define DEG2RAD DEG2RAD 64 #define RAD2DEG RAD2DEG 70 return x < 0 ? -1 : 1;
77 return (
x == 0 ||
x == -0) ? 0 :
sign(
x);
102 template <
typename T>
103 inline const T
min3(
const T&
A,
const T& B,
const T& C)
105 return std::min<T>(
A, std::min<T>(B, C));
107 template <
typename T>
108 inline const T
max3(
const T&
A,
const T& B,
const T& C)
110 return std::max<T>(
A, std::max<T>(B, C));
114 template <
typename T>
117 return x > 0 ?
static_cast<int>(floor(static_cast<double>(
x)))
118 : static_cast<int>(ceil(static_cast<double>(
x)));
123 template <
typename T,
typename K>
126 if (test_val < var) var = test_val;
130 template <
typename T,
typename K>
133 if (test_val > var) var = test_val;
137 template <
typename T>
138 inline void saturate(T& var,
const T sat_min,
const T sat_max)
140 if (var > sat_max) var = sat_max;
141 if (var < sat_min) var = sat_min;
145 template <
typename T>
149 if (var > sat_max) var = sat_max;
150 if (var < sat_min) var = sat_min;
162 if (
n <= 1)
throw std::invalid_argument(
"round2up: Overflow!");
void saturate(T &var, const T sat_min, const T sat_max)
Saturate the value of var (the variable gets modified) so it does not get out of [min,max].
double RAD2DEG(const double x)
Radians to degrees.
T hypot_fast(const T x, const T y)
Faster version of std::hypot(), to use when overflow is not an issue and we prefer fast code...
T lowestPositive(const T a, const T b)
Returns the lowest, possitive among two numbers.
int fix(T x)
Rounds toward zero.
double DEG2RAD(const double x)
Degrees to radians.
const T max3(const T &A, const T &B, const T &C)
int signWithZero(T x)
Returns the sign of X as "0", "1" or "-1".
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
T square(const T x)
Inline function for the square of a number.
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
T abs_diff(const T a, const T b)
Efficient and portable evaluation of the absolute difference of two unsigned integer values (but will...
T round2up(T val)
Round up to the nearest power of two of a given number.
const T min3(const T &A, const T &B, const T &C)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
int sign(T x)
Returns the sign of X as "1" or "-1".
GLsizei const GLfloat * value
T saturate_val(const T &value, const T sat_min, const T sat_max)
Like saturate() but it returns the value instead of modifying the variable.
GLubyte GLubyte GLubyte a