These are definetely evil:
#ifndef PI
#define PI 3.14159265358979323846
#endif
#ifndef TWO_PI
#define TWO_PI 6.28318530717958647693
#endif
#ifndef M_TWO_PI
#define M_TWO_PI 6.28318530717958647693
#endif
#ifndef FOUR_PI
#define FOUR_PI 12.56637061435917295385
#endif
#ifndef HALF_PI
#define HALF_PI 1.57079632679489661923
#endif
#ifndef DEG_TO_RAD
#define DEG_TO_RAD (PI/180.0)
#endif
#ifndef RAD_TO_DEG
#define RAD_TO_DEG (180.0/PI)
#endif
#ifndef MIN
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#endif
#ifndef CLAMP
#define CLAMP(val,min,max) ((val) < (min) ? (min) : ((val > max) ? (max) : (val)))
#endif
#ifndef ABS
#define ABS(x) (((x) < 0) ? -(x) : (x))
#endif
Suggestions
PI
- I suggest a
constexpr value with M_PI.
TWO_PI
M_TWO_PI
FOUR_PI
HALF_PI
DEG_TO_RAD
- This should be a
constexpr function.
RAD_TO_DEG
- This should be a
constexpr function.
MIN
- This should use
std::min().
MAX
- This should use
std::max().
CLAMP
- This should be a
constexpr function.
ABS
- This should use
std::abs.
- We need a float version which uses
std::fabs too.
These are definetely evil:
Suggestions
PIconstexprvalue withM_PI.TWO_PIM_TWO_PIFOUR_PIHALF_PIDEG_TO_RADconstexprfunction.RAD_TO_DEGconstexprfunction.MINstd::min().MAXstd::max().CLAMPconstexprfunction.ABSstd::abs.std::fabstoo.