plastimatch
Loading...
Searching...
No Matches
clamp.h
Go to the documentation of this file.
1/* -----------------------------------------------------------------------
2 See COPYRIGHT.TXT and LICENSE.TXT for copyright and license information
3 ----------------------------------------------------------------------- */
4#ifndef _clamp_h_
5#define _clamp_h_
6
7#define CLAMP(value, min_value, max_value) \
8 do { \
9 if (value < min_value) { \
10 value = min_value; \
11 } else if (value > max_value) { \
12 value = max_value; \
13 } \
14 } while (0)
15
16#define CLAMP2(v1, v2, min_value, max_value) \
17 do { \
18 if (v1 < min_value) { \
19 v1 = min_value; \
20 } \
21 if (v2 > max_value) { \
22 v2 = max_value; \
23 } \
24 if (v2 < v1) { \
25 v2 = v1; \
26 } \
27 } while (0)
28
29#endif