-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoord3.cu
159 lines (134 loc) · 3.31 KB
/
coord3.cu
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef COORD3_H
#define COORD3_H
/** Signed three dimensional coordinates.
*
* If the constructor is supplied with only X and Y coordinates, Z is set to
* 0.
*/
template<typename T=int64_t>
struct _coord3 {
T x;
T y;
T z;
_coord3();
_coord3(T x, T y);
__host__ __device__
_coord3(T x, T y, T z);
template<class Archive>
void serialize(Archive &ar, unsigned int version);
void operator=(const _coord3<T> other);
bool operator==(const _coord3<T> other) const;
bool operator!=(const _coord3<T> other) const;
};
// IMPLEMENTATIONS
/**
* Constructors
*/
template<typename T>
_coord3<T>::_coord3(T _x, T _y, T _z) :
x(_x), y(_y), z(_z) {}
template<typename T>
_coord3<T>::_coord3(T _x, T _y) :
x(_x), y(_y), z(0) {}
template<typename T>
_coord3<T>::_coord3() :
x(0), y(0), z(0) {}
/**
* Serialization
*/
template<typename T>
template<class Archive>
void _coord3<T>::serialize(Archive &ar, unsigned int version) {
ar & this->x;
ar & this->y;
ar & this->z;
}
/**
* Operators
*/
template<typename T>
void _coord3<T>::operator=(const _coord3 other) {
this->x = other.x;
this->y = other.y;
this->z = other.z;
}
template<typename T>
bool _coord3<T>::operator==(const _coord3<T> other) const {
return this->x == other.x && this->y == other.y && this->z == other.z;
}
template<typename T>
bool _coord3<T>::operator!=(const _coord3<T> other) const {
return !this->operator==(other);
}
template<typename T>
bool operator==(const dim3 A, const _coord3<T> B) {
return A.x == B.x && A.y == B.y && A.z == B.z;
}
template<typename T>
bool operator!=(const dim3 A, const _coord3<T> B) {
return !operator==(A, B);
}
template<typename T>
bool operator==(const _coord3<T> A, const dim3 B) {
return operator==(B, A);
}
template<typename T>
bool operator !=(const _coord3<T> A, const dim3 B) {
return operator!=(B, A);
}
template<typename T>
bool operator<(const _coord3<T> A, const _coord3<T> B) {
// This gives the default ordering as if ordered by indices of a row-major
// layout: x changing fastest, z slowest
return A.z < B.z ||
(A.z == B.z && A.y < B.y) ||
(A.z == B.z && A.y == B.y && A.x < B.x);
}
template<typename T>
__device__ __host__
_coord3<T> operator+(_coord3<T> A, _coord3<T> B) {
return _coord3<T>(A.x + B.x,
A.y + B.y,
A.z + B.z);
}
template<typename T>
__device__ __host__
_coord3<T> operator-(_coord3<T> A, _coord3<T> B) {
return _coord3<T>(A.x - B.x,
A.y - B.y,
A.z - B.z);
}
template<typename T>
__device__ __host__
_coord3<T> operator-(_coord3<T> A) {
return _coord3<T>(-A.x,
-A.y,
-A.z);
}
template<typename T>
__device__ __host__
_coord3<T> operator*(_coord3<T> A, int b) {
return _coord3<T>(A.x * b,
A.y * b,
A.z * b);
}
template<typename T>
_coord3<T> operator*(int b, _coord3<T> A) {
return operator*(A, b);
}
/** Make coord3 available as shorthand for one templated version of the
* coordinate type. */
#ifdef COORD3_64
typedef _coord3<int64_t> coord3;
#else
#ifdef COORD3_32
typedef _coord3<int32_t> coord3;
#else
#ifdef COORD3_16
typedef _coord3<int16_t> coord3;
#else
typedef _coord3<int> coord3;
#endif
#endif
#endif
#endif