openframeworks / openframeworks/openFrameworks
ofConstants: Remove preprocessor constants and macros
Open
@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
constexprvalue withM_PI.
- I suggest a
TWO_PI- Trivial change.
M_TWO_PI- Trivial change.
FOUR_PI- Trivial change.
HALF_PI- Trivial change.
DEG_TO_RAD- This should be a
constexprfunction.
- This should be a
RAD_TO_DEG- This should be a
constexprfunction.
- This should be a
MIN- This should use
std::min().
- This should use
MAX- This should use
std::max().
- This should use
CLAMP- This should be a
constexprfunction.
- This should be a
ABS- This should use
std::abs. - We need a float version which uses
std::fabstoo.
- This should use
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.