-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterval.h
More file actions
60 lines (44 loc) · 1.45 KB
/
interval.h
File metadata and controls
60 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef INTERVAL_H
#define INTERVAL_H
extern const float infinity;
/*
class representing a real-valued interval
*/
class interval {
public:
// min, max of the interval
float min, max;
// constructors
__host__ __device__ interval() : min(infinity), max(-infinity) {}
__host__ __device__ interval(float _min, float _max) : min(_min), max(_max) {}
/*
determine whether x is contained in the interval (inclusive)
@param x the value
@return true if min <= x <= max; false otherwise
*/
__host__ __device__ bool contains(float x) const {
return min <= x && x <= max;
}
/*
determine whether x is contained in the interval (exclusive)
@param x the value
@return true if min < x < max; false otherwise
*/
__host__ __device__ bool surrounds(float x) const {
return min < x && x < max;
}
/*
mathematical clamp function that clamps to min, max
@param x number to clamp
@return the clamped number
*/
__host__ __device__ float clamp(float x) const {
if (x < min) return min;
if (x > max) return max;
return x;
}
static const interval empty, universe;
};
const static interval empty(infinity, -infinity);
const static interval universe(-infinity, infinity);
#endif