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
|
//
// Created by saintruler on 05.05.19.
//
#include "Point.h"
Point::Point(double x, double y)
{
this->x = x;
this->y = y;
}
Point operator+(const Point& left, const Point& right)
{
return Point(left.x + right.x, left.y + right.y);
}
Point operator+=(Point& left, const Point& right)
{
left.x += right.x;
left.y += right.y;
return left;
}
Point operator-(const Point& left, const Point& right)
{
return Point(left.x - right.x, left.y - right.y);
}
Point operator-=(Point& left, const double right)
{
left.x -= right;
left.y -= right;
return left;
}
Point operator/(const Point& left, const double right)
{
return Point(left.x / right, left.y / right);
}
Point operator/=(Point& left, const double right)
{
left.x /= right;
left.y /= right;
return left;
}
Point operator*(const Point& left, const double right)
{
return Point(left.x * right, left.y * right);
}
Point operator*=(Point& left, const double right)
{
left.x *= right;
left.y *= right;
return left;
}
double Point::length()
{
return sqrt(pow(x, 2) + pow(y, 2));
}
double Point::length_squared()
{
return pow(x, 2) + pow(y, 2);
}
void Point::normalize()
{
const double l = length();
this->x /= l;
this->y /= l;
}
|