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
81
82
83
84
85
86
|
#include <kurator/engine/Point.h>
#include <cmath>
namespace kurator
{
namespace engine
{
double
Point::magnitude() const
{
return std::sqrt(std::pow(x, 2) + std::pow(y, 2));
}
double
Point::distance(const Point& other) const
{
return std::sqrt(std::pow(other.x - x, 2) + std::pow(other.y - y, 2));
}
double
Point::angle() const
{
return std::atan2(y, x); // (+x, _) is 0
}
Point
Point::rotate(const double angle) const
{
return {
x * std::cos(angle) - y * std::sin(angle),
x * std::sin(angle) + y * std::cos(angle),
};
}
Point
Point::scale(const double _scale) const
{
return {x * _scale, y * _scale};
}
Point
Point::normalized() const
{
return scale(1.0 / magnitude());
}
Point
Point::operator-(const Point& other) const
{
return subtract(other);
}
Point
Point::operator+(const Point& other) const
{
return {x + other.x, y + other.y};
}
Point
Point::subtract(const Point& other) const
{
return {x - other.x, y - other.y};
}
Point
Point::subtract(const double _x, const double _y) const
{
return {x - _x, y - _y};
}
} // namespace engine
} // namespace kurator
|