blob: 78eba110532f6aecd93857f92457454d958749d5 (
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
|
#pragma once
#include <cstdint>
#include <functional>
struct Vector2Options
{
int32_t x;
int32_t y;
};
/**
* A 2D Vector.
*/
class Vector2
{
public:
using Value = int32_t;
constexpr explicit Vector2(const Vector2Options &options) noexcept
: _x(options.x), _y(options.y)
{
}
[[nodiscard]] Value get_x() const noexcept;
void set_x(Value x) noexcept;
[[nodiscard]] Value get_y() const noexcept;
void set_y(Value y) noexcept;
[[nodiscard]] Vector2 to_direction(const Vector2 &direction,
Vector2::Value amount) const noexcept;
const Vector2 &operator+=(const Vector2 &rhs) noexcept;
const Vector2 &operator-=(const Vector2 &rhs) noexcept;
Vector2 operator+(const Vector2 &rhs) const noexcept;
Vector2 operator-(const Vector2 &rhs) const noexcept;
Vector2 operator*(const Vector2 &rhs) const noexcept;
bool operator==(const Vector2 &rhs) const noexcept;
/**
* Returns Vector2({.x = 0, .y = -1})
*/
static constexpr Vector2 up() noexcept
{
return Vector2({.x = 0, .y = -1});
}
/**
* Returns Vector2({.x = 0, .y = 1})
*/
static constexpr Vector2 down() noexcept
{
return Vector2({.x = 0, .y = 1});
}
/**
* Returns Vector2({.x = -1, .y = 0})
*/
static constexpr Vector2 left() noexcept
{
return Vector2({.x = -1, .y = 0});
}
/**
* Returns Vector2({.x = 1, .y = 0})
*/
static constexpr Vector2 right() noexcept
{
return Vector2({.x = 1, .y = 0});
}
private:
Value _x;
Value _y;
};
class Vector2Hasher
{
public:
std::size_t operator()(const Vector2 &vector2) const noexcept;
};
|