-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.cpp
68 lines (55 loc) · 1 KB
/
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
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
#include "Point.h"
Point::Point()
{
this->x = 0;
this->y = 0;
this->cluster = -1;
}
Point::Point(double x, double y)
{
this->x = x;
this->y = y;
this->cluster = -1;
}
double Point::getX() const
{
return x;
}
double Point::getY() const
{
return y;
}
int Point::getCluster() const
{
return cluster;
}
int Point::setCluster(int c)
{
cluster = c;
}
void Point::setX(double x)
{
this->x = x;
}
void Point::setY(double y)
{
this->y = y;
}
bool Point::operator==(const Point &p) const
{
if (x != p.x || y != p.y) return false;
return true;
}
ostream &operator<<(ostream &output, const Point &p)
{
output << "(" << p.getX() << ", " << p.getY() << ")";
return output;
}
double Point::euclideanDistance(Point *pt)
{
double dist = 0.0;
double x_dist = pow((pt->getX() - x), 2);
double y_dist = pow((pt->getY() - y), 2);
dist = sqrt(x_dist + y_dist);
return dist;
}