interval.h 1.39 KB
Newer Older
1
2
3
4
5
6
7
#ifndef _CCS_INTERVAL_H
#define _CCS_INTERVAL_H

#ifdef __cplusplus
extern "C" {
#endif

Brice Videau's avatar
Brice Videau committed
8
9
10
11
12
13
14
15
16
17
struct ccs_interval_s {
	ccs_numeric_type_t type;
	ccs_numeric_t   lower;
	ccs_numeric_t   upper;
	ccs_bool_t      lower_included;
	ccs_bool_t      upper_included;
};

typedef struct ccs_interval_s ccs_interval_t;

18
extern ccs_result_t
19
20
ccs_interval_empty(ccs_interval_t *interval, ccs_bool_t *empty_ret);

21
extern ccs_result_t
22
23
24
25
ccs_interval_intersect(ccs_interval_t *interval1,
		       ccs_interval_t *interval2,
                       ccs_interval_t *interval_res);

26
extern ccs_result_t
27
28
29
30
ccs_interval_equal(ccs_interval_t *interval1,
                   ccs_interval_t *interval2,
                   ccs_bool_t     *equal_res);

31
inline ccs_bool_t
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value) {
	if (interval->type == CCS_NUM_FLOAT) {
		return ( interval->lower_included ?
		           interval->lower.f <= value.f :
		           interval->lower.f < value.f ) &&
		       ( interval->upper_included ?
		           interval->upper.f >= value.f :
		           interval->upper.f > value.f );
	} else {
		return ( interval->lower_included ?
		           interval->lower.i <= value.i :
		           interval->lower.i < value.i ) &&
		       ( interval->upper_included ?
		           interval->upper.i >= value.i :
		           interval->upper.i > value.i );
	}
}

#ifdef __cplusplus
}
#endif

#endif //_CCS_INTERVAL_H