Browse Source

Add default arguments to math::clamp, clampSafe, and rescale.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
daad5bd355
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      include/math.hpp

+ 3
- 3
include/math.hpp View File

@@ -106,14 +106,14 @@ T sgn(T x) {
/** Limits `x` between `a` and `b`.
If `b < a`, returns a.
*/
inline float clamp(float x, float a, float b) {
inline float clamp(float x, float a = 0.f, float b = 1.f) {
return std::fmax(std::fmin(x, b), a);
}

/** Limits `x` between `a` and `b`.
If `b < a`, switches the two values.
*/
inline float clampSafe(float x, float a, float b) {
inline float clampSafe(float x, float a = 0.f, float b = 1.f) {
return (a <= b) ? clamp(x, a, b) : clamp(x, b, a);
}

@@ -145,7 +145,7 @@ inline float chop(float x, float epsilon = 1e-6f) {

/** Rescales `x` from the range `[xMin, xMax]` to `[yMin, yMax]`.
*/
inline float rescale(float x, float xMin, float xMax, float yMin, float yMax) {
inline float rescale(float x, float xMin, float xMax, float yMin = 0.f, float yMax = 1.f) {
return yMin + (x - xMin) / (xMax - xMin) * (yMax - yMin);
}



Loading…
Cancel
Save