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

Bounds::Bounds(const BoundsOptions &options) noexcept
	: _width(options.width), _height(options.height)
{
}

auto Bounds::get_width() const noexcept -> Bounds::Value
{
	return _width;
}

void Bounds::set_width(Bounds::Value width) noexcept
{
	_width = width;
}

auto Bounds::get_height() const noexcept -> Bounds::Value
{
	return _height;
}

void Bounds::set_height(Bounds::Value height) noexcept
{
	_height = height;
}

auto Bounds::validate_coords(const Vector2 &coords) const noexcept -> CoordsValidation
{
	if (static_cast<Bounds::Value>(coords.get_x()) >= _width)
	{
		return CoordsValidation::X_HIGH;
	}

	if (coords.get_x() < 0)
	{
		return CoordsValidation::X_LOW;
	}

	if (static_cast<Bounds::Value>(coords.get_y()) >= _height)
	{
		return CoordsValidation::Y_HIGH;
	}

	if (coords.get_y() < 0)
	{
		return CoordsValidation::Y_LOW;
	}

	return CoordsValidation::VALID;
}

auto Bounds::operator*=(const Bounds &rhs) noexcept -> const Bounds &
{
	_width *= rhs._width;
	_height *= rhs._height;

	return *this;
}

auto Bounds::operator+=(const Bounds &rhs) noexcept -> const Bounds &
{
	_width += rhs._width;
	_height += rhs._height;

	return *this;
}

auto Bounds::operator-=(const Bounds &rhs) noexcept -> const Bounds &
{
	_width -= rhs._width;
	_height -= rhs._height;

	return *this;
}

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

	new_bounds._width -= rhs._width;
	new_bounds._height -= rhs._height;

	return new_bounds;
}