From 2b271ed5348daec2bcf90b83da47781e2d8b964c Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Fri, 14 May 2010 01:10:17 +0200 Subject: janitor: Move min/max and dist functions up to common.h Signed-off-by: Henrik Rydberg --- src/common.h | 16 ++++++++++++++++ src/gestures.c | 2 -- src/hwdata.h | 7 +++++++ src/hwstate.c | 18 +----------------- 4 files changed, 24 insertions(+), 19 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) { diff --git a/src/gestures.c b/src/gestures.c index f44e6ab..a0ef5d4 100644 --- a/src/gestures.c +++ b/src/gestures.c @@ -31,8 +31,6 @@ static const int FINGER_ATTACK_MS = 70; static const int FINGER_DECAY_MS = 120; -static inline int maxval(int x, int y) { return x > y ? x : y; } - inline int dxval(const struct FingerState *a, const struct FingerState *b) { return a->hw.position_x - b->hw.position_x; diff --git a/src/hwdata.h b/src/hwdata.h index 15a9fcb..5dd99cf 100644 --- a/src/hwdata.h +++ b/src/hwdata.h @@ -81,4 +81,11 @@ void init_hwdata(struct HWData *hw); int read_hwdata(struct HWData *hw, const struct input_event* ev); void output_hwdata(const struct HWData *hw); +static inline int finger_dist2(const struct FingerData *a, + const struct FingerData *b) +{ + return dist2(a->position_x - b->position_x, + a->position_y - b->position_y); +} + #endif diff --git a/src/hwstate.c b/src/hwstate.c index 07bab31..a68b81a 100644 --- a/src/hwstate.c +++ b/src/hwstate.c @@ -25,27 +25,11 @@ #define NOTOUCH(hw, c) ((hw)->touch_major == 0 && (c)->has_touch_major) -const int XMAX = 32767; - void init_hwstate(struct HWState *s) { memset(s, 0, sizeof(struct HWState)); } -static inline int clamp15(int x) -{ - return x < -XMAX ? -XMAX : x > XMAX ? XMAX : x; -} - -/* abslute scale is assumed to fit in 15 bits */ -inline int dist2(const struct FingerData *a, const struct FingerData *b) -{ - int dx = clamp15(a->position_x - b->position_x); - int dy = clamp15(a->position_y - b->position_y); - - return dx * dx + dy * dy; -} - /* Dmitry Torokhov's code from kernel/driver/input/input.c */ static int defuzz(int value, int old_val, int fuzz) { @@ -104,7 +88,7 @@ void modify_hwstate(struct HWState *s, sid[j] = 0; row = A + hw->nfinger * j; for (i = 0; i < hw->nfinger; i++) - row[i] = dist2(&hw->finger[i], &s->finger[j].hw); + row[i] = finger_dist2(&hw->finger[i], &s->finger[j].hw); } match_fingers(hw2s, A, hw->nfinger, s->nfinger); -- cgit v1.2.3