-
Notifications
You must be signed in to change notification settings - Fork 1
/
point.h
50 lines (40 loc) · 920 Bytes
/
point.h
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
#ifndef point_HEADER
#define point_HEADER
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <assert.h>
struct point {
point() { } // uninitialized constructor
point(unsigned x, unsigned y, unsigned z) {
x_[0] = x;
x_[1] = y;
x_[2] = z;
}
static const unsigned dim = 3;
unsigned operator[] (unsigned i) const {
assert(i < dim);
return x_[i];
}
void set (unsigned i, unsigned val) {
assert(i < dim);
x_[i] = val;
}
bool operator == (const point& other) const {
for (unsigned i = 0; i < dim; ++i) {
if (x_[i] != other[i]) { return false; }
}
return true;
}
/* Arbitrary total ordering. */
bool operator < (const point& other) const {
for (unsigned i = 0; i < dim; ++i) {
if (x_[i] < other[i]) { return true; }
if (x_[i] > other[i]) { return false; }
}
return false;
}
private:
unsigned x_[dim];
};
#endif