openframeworks / openframeworks/openFrameworks

ofConstants: Remove preprocessor constants and macros

Open
#5,163 17 comments 0 reactions 1 assignee View on GitHub

@ofTheo is already working on this.

Since Jul 15, 2016.

core feature
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.