-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPoint.cpp
42 lines (31 loc) · 875 Bytes
/
Point.cpp
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
#include "Point.h"
#include "Vector.h"
Point::Point() : x(0), y(0), z(0) {}
Point::Point(int x, int y, int z) : x(x), y(y), z(z) {}
Point Point::getMidpoint(Point p, Point q) {
return Point((p.x+q.x)/2, (p.y+q.y)/2, (p.z+q.z)/2);
}
bool operator==(const Point& lhs, const Point& rhs) {
return (lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.z == rhs.z);
}
bool operator!=(const Point& lhs, const Point& rhs) {
return !operator==(lhs,rhs);
}
Point& Point::operator+=(const Vector& vector) {
x += (int) vector.x;
y += (int) vector.y;
z += (int) vector.z;
return *this;
}
Point operator+(Point point, const Vector& vector) {
return point += vector;
}
Point& Point::operator-=(const Vector& vector) {
x -= (int) vector.x;
y -= (int) vector.y;
z -= (int) vector.z;
return *this;
}
Point operator-(Point point, const Vector& vector) {
return point -= vector;
}