summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2010-08-26 11:20:16 (GMT)
committer Simon <simon@hardwired.org.uk>2010-08-26 11:20:16 (GMT)
commit72a1d17fe42ccc74ac25328dcd272b7a2bf6856c (patch)
treea064555f1694f7c763eb3f42c56fe92ea016713b /misc.c
parent5751fea35f31640fddfaea1459503e366ae39729 (diff)
downloadpowder-72a1d17fe42ccc74ac25328dcd272b7a2bf6856c.zip
powder-72a1d17fe42ccc74ac25328dcd272b7a2bf6856c.tar.gz
This build works, but still a work in progress
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/misc.c b/misc.c
new file mode 100644
index 0000000..fe50b32
--- /dev/null
+++ b/misc.c
@@ -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