summaryrefslogtreecommitdiff
path: root/battles/src/Point.cpp
blob: 31aecae4c93a7e24f5f75f4b9c4396769c0970c1 (plain)
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
#include <kurator/battles/Point.h>

#include <cmath>


namespace kurator
{
namespace battles
{


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 {x - other.x, y - other.y};
}


Point
Point::operator+(const Point& other) const
{
	return {x + other.x, y + other.y};
}


}  // namespace battles
}  // namespace kurator