aboutsummaryrefslogtreecommitdiff
path: root/src/engine/data/vector2.cpp
blob: f91afa8ac700b9a4e2a205547a2774453a2dce26 (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
#include "vector2.hpp"

#include "util/hash.hpp"

Vector2::Vector2(const Vector2Options &options) : _x(options.x), _y(options.y) {}

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

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

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

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

const Vector2 &Vector2::operator+=(const Vector2 &vector2) noexcept
{
	_x += vector2._x;
	_y += vector2._y;

	return *this;
}

const Vector2 &Vector2::operator-=(const Vector2 &vector2) noexcept
{
	_x -= vector2._x;
	_y -= vector2._y;

	return *this;
}

bool Vector2::operator==(const Vector2 &vector2) const noexcept
{
	return _x == vector2._x && _y == vector2._y;
}

Vector2 Vector2::up() noexcept
{
	return Vector2({.x = 0, .y = 1});
}

Vector2 Vector2::down() noexcept
{
	return Vector2({.x = 0, .y = -1});
}

Vector2 Vector2::left() noexcept
{
	return Vector2({.x = -1, .y = 0});
}

Vector2 Vector2::right() noexcept
{
	return Vector2({.x = 1, .y = 0});
}

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

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

	return result_hash;
}