Skip to content

ofConstants: Remove preprocessor constants and macros  #5163

@saki7

Description

@saki7

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
    • Trivial change.
  • M_TWO_PI
    • Trivial change.
  • FOUR_PI
    • Trivial change.
  • HALF_PI
    • Trivial change.
  • 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions