aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.h
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-05-14 01:10:17 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-05-14 01:41:39 +0200
commit2b271ed5348daec2bcf90b83da47781e2d8b964c (patch)
tree1828f251cf4b7d4f6a66a6af67c2681998f2483e /src/common.h
parentf02210172efc6bfc05c4598c14e1268d2828097e (diff)
downloadxorg-input-kobomultitouch-2b271ed5348daec2bcf90b83da47781e2d8b964c.tar.gz
xorg-input-kobomultitouch-2b271ed5348daec2bcf90b83da47781e2d8b964c.tar.bz2
xorg-input-kobomultitouch-2b271ed5348daec2bcf90b83da47781e2d8b964c.zip
janitor: Move min/max and dist functions up to common.h
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/common.h')
-rw-r--r--src/common.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common.h b/src/common.h
index 1b4d007..32be48d 100644
--- a/src/common.h
+++ b/src/common.h
@@ -61,6 +61,22 @@
#define SETBIT(m, x) (m |= BITMASK(x))
#define CLEARBIT(m, x) (m &= ~BITMASK(x))
+static inline int maxval(int x, int y) { return x > y ? x : y; }
+static inline int minval(int x, int y) { return x < y ? x : y; }
+
+static inline int clamp15(int x)
+{
+ return x < -32767 ? -32767 : x > 32767 ? 32767 : x;
+}
+
+/* absolute scale is assumed to fit in 15 bits */
+static inline int dist2(int dx, int dy)
+{
+ dx = clamp15(dx);
+ dy = clamp15(dy);
+ return dx * dx + dy * dy;
+}
+
/* Count number of bits (Sean Eron Andersson's Bit Hacks) */
static inline int bitcount(unsigned v)
{