-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.h
58 lines (45 loc) · 1.48 KB
/
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
51
52
53
54
55
56
57
58
#ifndef INF_H
#define INF_H
const double INF = std::numeric_limits<float>::infinity();
#endif
#ifndef POINT_H
#define POINT_H
template<class T>
T pow2(const T &val) {
return val * val;
}
class Point {
public:
int dimension;
double x, y, z;
double zeroDistance;
Point(double x1 = 0):
dimension(1), x(x1), y(0), z(0),
zeroDistance(sqrt(x1 * x1)) {}
Point(double x1, double y1):
dimension(2), x(x1), y(y1), z(0),
zeroDistance(sqrt(x1 * x1 + y1 * y1)) {}
Point(double x1, double y1, double z1):
dimension(3), x(x1), y(y1), z(z1),
zeroDistance(sqrt(x1 * x1 + y1 * y1 + z1 * z1)) {}
void setPoint(double x1 = 0, double y1 = 0, double z1 = 0) {
x = x1, y = y1, z = z1;
if (x1 > 0) dimension = 1;
if (y1 > 0) dimension = 2;
if (z1 > 0) dimension = 3;
}
double distance(const Point &pb) {
return sqrt(pow2(x - pb.x) + pow2(y - pb.y) + pow2(z - pb.z));
}
inline bool operator<(const Point &pb) const {
return this->zeroDistance < pb.zeroDistance;
}
inline bool operator>(const Point &pb) const { return pb < *this; }
inline bool operator>=(const Point &pb) const { return !(*this < pb); }
inline bool operator<=(const Point &pb) const { return !(*this > pb); }
inline bool operator==(const Point &pb) const {
return (this->x == pb.x && this->y == pb.y && this->z == pb.z);
}
inline bool operator!=(const Point &pb) const { return !(*this == pb); }
};
#endif