diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-05-14 01:10:17 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-05-14 01:41:39 +0200 |
| commit | 2b271ed5348daec2bcf90b83da47781e2d8b964c (patch) | |
| tree | 1828f251cf4b7d4f6a66a6af67c2681998f2483e /src/common.h | |
| parent | f02210172efc6bfc05c4598c14e1268d2828097e (diff) | |
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.h | 16 |
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 @@ | |||
| 61 | #define SETBIT(m, x) (m |= BITMASK(x)) | 61 | #define SETBIT(m, x) (m |= BITMASK(x)) |
| 62 | #define CLEARBIT(m, x) (m &= ~BITMASK(x)) | 62 | #define CLEARBIT(m, x) (m &= ~BITMASK(x)) |
| 63 | 63 | ||
| 64 | static inline int maxval(int x, int y) { return x > y ? x : y; } | ||
| 65 | static inline int minval(int x, int y) { return x < y ? x : y; } | ||
| 66 | |||
| 67 | static inline int clamp15(int x) | ||
| 68 | { | ||
| 69 | return x < -32767 ? -32767 : x > 32767 ? 32767 : x; | ||
| 70 | } | ||
| 71 | |||
| 72 | /* absolute scale is assumed to fit in 15 bits */ | ||
| 73 | static inline int dist2(int dx, int dy) | ||
| 74 | { | ||
| 75 | dx = clamp15(dx); | ||
| 76 | dy = clamp15(dy); | ||
| 77 | return dx * dx + dy * dy; | ||
| 78 | } | ||
| 79 | |||
| 64 | /* Count number of bits (Sean Eron Andersson's Bit Hacks) */ | 80 | /* Count number of bits (Sean Eron Andersson's Bit Hacks) */ |
| 65 | static inline int bitcount(unsigned v) | 81 | static inline int bitcount(unsigned v) |
| 66 | { | 82 | { |
