diff options
| author | Simon <simon@hardwired.org.uk> | 2010-08-26 11:20:16 (GMT) |
|---|---|---|
| committer | Simon <simon@hardwired.org.uk> | 2010-08-26 11:20:16 (GMT) |
| commit | 72a1d17fe42ccc74ac25328dcd272b7a2bf6856c (patch) | |
| tree | a064555f1694f7c763eb3f42c56fe92ea016713b /misc.c | |
| parent | 5751fea35f31640fddfaea1459503e366ae39729 (diff) | |
| download | powder-72a1d17fe42ccc74ac25328dcd272b7a2bf6856c.zip powder-72a1d17fe42ccc74ac25328dcd272b7a2bf6856c.tar.gz | |
This build works, but still a work in progress
Diffstat (limited to 'misc.c')
| -rw-r--r-- | misc.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +#include "misc.h" + +//Signum function +#ifdef WIN32 +_inline int sign(float i) +#else +inline int sign(float i) +#endif +{ + if (i<0) + return -1; + if (i>0) + return 1; + return 0; +} + +#ifdef WIN32 +_inline unsigned clamp_flt(float f, float min, float max) +#else +inline unsigned clamp_flt(float f, float min, float max) +#endif +{ + if(f<min) + return 0; + if(f>max) + return 255; + return (int)(255.0f*(f-min)/(max-min)); +} + +#ifdef WIN32 +_inline float restrict_flt(float f, float min, float max) +#else +inline float restrict_flt(float f, float min, float max) +#endif +{ + if(f<min) + return min; + if(f>max) + return max; + return f; +}
\ No newline at end of file |
