aabb2.h
1.02 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
#ifndef STIM_AABB2_H
#define STIM_AABB2_H
#include <stim/cuda/cudatools/callable.h>
namespace stim{
/// Structure for a 2D axis aligned bounding box
template<typename T>
struct aabb2{
//protected:
T low[2]; //top left corner position
T high[2]; //dimensions along x and y
//public:
CUDA_CALLABLE aabb2(T x, T y){ //initialize an axis aligned bounding box of size 0 at the given position
low[0] = high[0] = x; //set the position to the user specified coordinates
low[1] = high[1] = y;
}
//insert a point into the bounding box, growing the box appropriately
CUDA_CALLABLE void insert(T x, T y){
if(x < low[0]) low[0] = x;
if(y < low[1]) low[1] = y;
if(x > high[0]) high[0] = x;
if(y > high[1]) high[1] = y;
}
//trim the bounding box so that the lower bounds are (x, y)
CUDA_CALLABLE void trim_low(T x, T y){
if(low[0] < x) low[0] = x;
if(low[1] < y) low[1] = y;
}
CUDA_CALLABLE void trim_high(T x, T y){
if(high[0] > x) high[0] = x;
if(high[1] > y) high[1] = y;
}
};
}
#endif