-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.cpp
69 lines (56 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
69
#include "point.hpp"
#include <cmath>
#include <limits>
using Shape::Point;
Point::Point() : x(0.0), y(0.0)
{
}
Point::~Point()
{
}
void Point::set_x(double x)
{
this->x = x;
}
void Point::set_y(double y)
{
this->y = y;
}
double Point::get_x()
{
return x;
}
double Point::get_y()
{
return y;
}
Point::Point(double x, double y)
{
this->x = x;
this->y = y;
}
Point Point::operator=(const Point &other)
{
if (this != &other)
{
this->x = other.x;
this->y = other.y;
}
}
bool Point::isApproximatelyEqual(double x, double y) const
{
return fabs(x - y) <= numeric_limits<float>::epsilon();
}
bool Point::operator==(const Point &other) const
{
if (this->isApproximatelyEqual(this->x, other.x) && this->isApproximatelyEqual(this->y, other.y))
return true;
return false;
}
// comparison is done first on y coordinate and then on x coordinate
bool Point::operator<(const Point &b) const
{
if (y != b.y)
return y < b.y;
return x < b.x;
}