-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatastruct_utils.hpp
78 lines (55 loc) · 1.27 KB
/
datastruct_utils.hpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#ifdef __CUDACC__
#define DECL __host__ __device__
#else
#define DECL
#endif
struct Point {
int u;
int v;
DECL Point(int u, int v) : u(u), v(v) {}
DECL Point(const Point& copy) : u(copy.u), v(copy.v) { }
friend Point operator+(Point lhs, const Point &rhs) {
lhs.u += rhs.u;
lhs.v += rhs.v;
return lhs;
}
friend Point operator-(Point lhs, const Point &rhs) {
lhs.u -= rhs.u;
lhs.v -= rhs.v;
return lhs;
}
Point & operator+=(const Point &rhs) {
u += rhs.u;
v += rhs.v;
return *this;
}
Point & operator-=(const Point &rhs) {
u -= rhs.u;
v -= rhs.v;
return *this;
}
Point & operator*=(float x) {
u = int( x * u );
v = int( x * v );
return *this;
}
friend Point operator*(Point lhs, float x) {
lhs *= x;
return lhs;
}
friend Point operator*(float x, Point rhs) {
rhs *= x;
return rhs;
}
};
struct Box {
Point topLeft;
Point botRight;
// Creates an empty region
DECL Box() : topLeft(0,0), botRight(-1, -1) { }
DECL Box(const Point &tl, const Point &br) : topLeft(tl), botRight(br) { }
DECL bool isEmpty() {
return (topLeft.u > botRight.u) || (topLeft.v > botRight.v);
}
};