-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint.cpp
More file actions
80 lines (61 loc) · 1.45 KB
/
point.cpp
File metadata and controls
80 lines (61 loc) · 1.45 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
#include "Point.h"
Point::Point(void)
:x(0.0),
y(0.0)
{
}
Point::Point(const float& new_x, const float& new_y)
:x(new_x),
y(new_y)
{
}
void Point::toStream(std::ostream & output_stream) const
{
output_stream << x << std::endl;
output_stream << y << std::endl;
}
void Point::fromStream(std::istream & input_stream)
{
input_stream >> x;
input_stream >> y;
}
std::ostream & operator<<(std::ostream & output_stream, const Point & point)
{
point.toStream(output_stream);
return output_stream;
}
std::istream & operator>>(std::istream & input_stream, Point & point)
{
point.fromStream(input_stream);
return input_stream;
}
bool PointSmallerXCompare::operator()(const Point & first, const Point & second) const
{
bool hasSmallerX = (first.x < second.x);
return hasSmallerX;
}
bool PointLargerXCompare::operator()(const Point & first, const Point & second) const
{
bool hasLargerX = (first.x > second.x);
return hasLargerX;
}
Point & operator+(const Point & first, const Point & second)
{
return Point(first.x + second.x, first.y + second.y);
}
Point & operator-(const Point & first, const Point & second)
{
return Point(first.x - second.x, first.y - second.y);
}
Point & operator*(const Point & point, const float& f)
{
return Point(point.x*f, point.y*f);
}
Point & operator*(const float& f, const Point & point)
{
return Point(point.x*f, point.y*f);
}
Point & operator/(const Point & point, const float& f)
{
return Point(point.x/f, point.y/f);
}