summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2010-08-26 09:53:15 (GMT)
committer Simon <simon@hardwired.org.uk>2010-08-26 09:53:15 (GMT)
commit5751fea35f31640fddfaea1459503e366ae39729 (patch)
treead4180fdfba2b0600ac61b919f3ed3f5486dab8e /utils.c
parent470519c92ed917b41c6ccae2e193eb59bdfe2ece (diff)
downloadpowder-5751fea35f31640fddfaea1459503e366ae39729.zip
powder-5751fea35f31640fddfaea1459503e366ae39729.tar.gz
More work
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/utils.c b/utils.c
new file mode 100644
index 0000000..dfa9a3b
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,41 @@
+#include "utils.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