X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=float.h;h=1f07d6c2b8b2df541ee2f26727d76f4d53fecf5f;hp=83e0a90d23f32c6b81e1cad2f5f7199bf9e897d7;hb=HEAD;hpb=9d4e50d23aec22dc580fd53c81ef23ab369e7eca diff --git a/float.h b/float.h index 83e0a90..1f07d6c 100644 --- a/float.h +++ b/float.h @@ -12,6 +12,37 @@ fclip(float f, float max) return f < SMIDGE || f >= (max - SMIDGE); } +static inline float +fconstrain(float f, float max) +{ + max -= SMIDGE; + + if(f > max) { + return max; + } + if(f < SMIDGE) { + return SMIDGE; + } + + return f; +} + +static inline float +fconstrain2(float f, float min, float max) +{ + min += SMIDGE; + max -= SMIDGE; + + if(f > max) { + return max; + } + if(f < min) { + return min; + } + + return f; +} + // wrap f so it's within the range [SMIDGE..(max-SMIDGE)] // assumes f is not outside this range by more than (max - (2 * SMIDGE)) static inline float