-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.cpp
More file actions
89 lines (72 loc) · 1.54 KB
/
Point.cpp
File metadata and controls
89 lines (72 loc) · 1.54 KB
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
#include "Point.h"
Point::Point(double x, double y, double z)
: p_{x,y,z}
{
}
Point::Point()
: p_{0, 0 ,0}
{
}
void Point::setCoord(double x, double y, double z)
{
p_[0] = x;
p_[1] = y;
p_[2] = z;
}
// Setter
double& Point::operator[](int entry)
{
if (entry==0)
return p_[0];
else if(entry==1)
return p_[1];
else if(entry==2)
return p_[2];
else
throw std::out_of_range("Point does not have index " + std::to_string(entry));
}
// Getter
double Point::operator[](int entry) const
{
if (entry==0)
return p_[0];
else if(entry==1)
return p_[1];
else if(entry==2)
return p_[2];
else
throw std::out_of_range("Point does not have index " + std::to_string(entry));
}
Point Point::operator+(Point const &obj)
{
Point result;
result.p_[0] = p_[0] + obj.p_[0];
result.p_[1] = p_[1] + obj.p_[1];
result.p_[2] = p_[2] + obj.p_[2];
return result;
}
Point Point::operator+(Point const &obj) const
{
Point result;
result.p_[0] = p_[0] + obj.p_[0];
result.p_[1] = p_[1] + obj.p_[1];
result.p_[2] = p_[2] + obj.p_[2];
return result;
}
Point Point::operator-(Point const &obj)
{
Point result;
result.p_[0] = p_[0] - obj.p_[0];
result.p_[1] = p_[1] - obj.p_[1];
result.p_[2] = p_[2] - obj.p_[2];
return result;
}
vector3 Point::getPoint() const
{
return p_;
}
std::ostream& operator<<(std::ostream& os, const Point& p)
{
os << "[ " << p[0] << ", " << p[1] << ", " << p[2] << " ]" << std::endl;
return os;
}