-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.cpp
68 lines (52 loc) · 1.13 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"
#include <math.h>
// using namespace std;
point::point(double initx, double inity) {
x = initx; y = inity;
}
point::point(const point& p) {
x = p.x; y = p.y;
}
double point::get_x() const {
return x;
}
double point::get_y() const {
return y;
}
void point::set_x(double newx) {
x = newx;
}
void point::set_y(double newy) {
y = newy;
}
void point::translate(double dx, double dy) {
x += dx; y += dy;
}
void point::scale(double factor) {
x *= factor; y *= factor;
}
void point::reflect_x() {
y *= -1;
}
void point::reflect_y() {
x *= -1;
}
void point::rotate(double radians) {
x = x * cos(radians) - y * sin(radians);
y = x * sin(radians) + y * cos(radians);
}
void point::operator = (const point& p2) {
x = p2.x; y = p2.y;
}
bool point::operator == (const point& p2) {
return x == p2.x && y == p2.y;
}
std::istream& operator >> (std::istream& ins, point& target) {
ins >> target.x;
ins >> target.y;
return ins;
}
std::ostream& operator << (std::ostream& outs, const point& source) {
outs << "(" << source.x << ", " << source.y << ")";
return outs;
}