aboutsummaryrefslogtreecommitdiff
path: root/src/engine/data/vector2.cpp
blob: 80fc43c373d63c7f4fc25cb0a240e305396d6daa (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "vector2.hpp"

#include <compare>
#include <tuple>

#include "util/hash_impl.hpp"

auto Vector2::get_x() const noexcept -> Vector2::Value
{
	return _x;
}

void Vector2::set_x(Vector2::Value x) noexcept
{
	_x = x;
}

auto Vector2::get_y() const noexcept -> Vector2::Value
{
	return _y;
}

void Vector2::set_y(Vector2::Value y) noexcept
{
	_y = y;
}

auto Vector2::to_direction(const Vector2 &direction, Vector2::Value amount) const noexcept
	-> Vector2
{
	return *this + (direction * Vector2({.x = amount, .y = amount}));
}

auto Vector2::operator+=(const Vector2 &rhs) noexcept -> const Vector2 &
{
	_x += rhs._x;
	_y += rhs._y;

	return *this;
}

auto Vector2::operator-=(const Vector2 &rhs) noexcept -> const Vector2 &
{
	_x -= rhs._x;
	_y -= rhs._y;

	return *this;
}

auto Vector2::operator+(const Vector2 &rhs) const noexcept -> Vector2
{
	auto new_vector2 = Vector2(*this);

	new_vector2._x += rhs._x;
	new_vector2._y += rhs._y;

	return new_vector2;
}

auto Vector2::operator-(const Vector2 &rhs) const noexcept -> Vector2
{
	auto new_vector2 = Vector2(*this);

	new_vector2._x -= rhs._x;
	new_vector2._y -= rhs._y;

	return new_vector2;
}

auto Vector2::operator*(const Vector2 &rhs) const noexcept -> Vector2
{
	auto new_vector2 = *this;

	new_vector2._x *= rhs._x;
	new_vector2._y *= rhs._y;

	return new_vector2;
}

auto Vector2::operator==(const Vector2 &rhs) const noexcept -> bool
{
	return _x == rhs._x && _y == rhs._y;
}

auto Vector2::operator!=(const Vector2 &rhs) const noexcept -> bool
{
	return !(*this == rhs);
}

auto Vector2::operator<(const Vector2 &rhs) const noexcept -> bool
{
	return std::tie(_x, _y) < std::tie(rhs._x, rhs._y);
}

auto Vector2::operator>(const Vector2 &rhs) const noexcept -> bool
{
	return std::tie(_x, _y) > std::tie(rhs._x, rhs._y);
}

auto Vector2::operator<=(const Vector2 &rhs) const noexcept -> bool
{
	return *this < rhs || *this == rhs;
}

auto Vector2::operator>=(const Vector2 &rhs) const noexcept -> bool
{
	return *this > rhs || *this == rhs;
}

auto Vector2Hasher::operator()(const Vector2 &vector2) const noexcept -> std::size_t
{
	std::size_t result_hash = 0;

	hash_combine(result_hash, vector2.get_x());
	hash_combine(result_hash, vector2.get_y());

	return result_hash;
}