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
|
#include <kurator/engine/Rect.h>
#include <algorithm>
#include <cmath>
#include <raylib.h>
#include <kurator/engine/Point.h>
using std::abs;
namespace kurator
{
namespace engine
{
Rect::Rect() :
position {0, 0},
size {0, 0}
{
}
Rect::Rect(const Point& first, const Point& second) :
position {std::min(first.x, second.x), std::min(first.y, second.y)},
size {abs(second - first)}
{
}
Point Rect::topleft() const
{
return position;
}
Point Rect::bottomright() const
{
return position + size;
}
Point Rect::center() const
{
return position + size.scale(0.5);
}
bool Rect::contains(const Point& point)
{
const auto br = bottomright();
return point.x >= position.x && point.x <= br.x && point.y >= position.y && point.y <= br.y;
}
bool Rect::contains(const Point& circle, double radius)
{
return CheckCollisionCircleRec(
{static_cast<float>(circle.x), static_cast<float>(circle.y)},
radius,
{
static_cast<float>(position.x),
static_cast<float>(position.y),
static_cast<float>(size.x),
static_cast<float>(size.y)
});
}
} // namespace engine
} // namespace kurator
|