-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegion.h
134 lines (105 loc) · 4.44 KB
/
Region.h
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
█████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
/vvvvvvvvvvvvvvvvvvv \=========================================,
`^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
Katana Engine \/ © 2012 - Shuriken Studios LLC */
#pragma once
namespace KatanaEngine
{
/** @brief Defines a rectangular region defined by a point, height, width. */
class Region
{
public:
/** @brief Instantiates a new Region object. */
Region() { X = Y = Width = Height = 0; }
/** @brief Instantiates a new Region object.
@param position the upper left corner of the region.
@param size The dimensions of the region.
@overload */
Region(const Point position, const Point size)
: Region(position, size.X, size.Y) { }
/** @brief Instantiates a new Region object.
@param position the upper left corner of the region.
@param width The width of the region.
@param height The height of the region.
@overload */
Region(const Point position, const int width, const int height)
: Region(position.X, position.Y, width, height) { }
/** @brief Instantiates a new Region object.
@param x The left side of the region.
@param y The top side of the region.
@param width The width of the region.
@param height The height of the region.
@overload */
Region(const int x, const int y, const int width, const int height)
{
Set(x, y, width, height);
}
virtual ~Region() { }
/** @brief Sets the components of the region.
@param x The left side of the region.
@param y The top side of the region.
@param width The width of the region.
@param height The height of the region.
@overload */
void Set(const int x, const int y, const int width, const int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
/** @brief The top of the region.
@return Returns the top. */
int GetTop() { return Y; }
/** @brief The bottom of the region.
@return Returns the bottom. */
int GetBottom() { return Y + Height; }
/** @brief The left side of the region.
@return Returns the left side. */
int GetLeft() { return X; }
/** @brief The right side of the region.
@return Returns the right side. */
int GetRight() { return X + Width; }
/** @brief The top left corner of the region.
@return Returns the top left corner. */
Point GetTopLeft() { return Point(GetLeft(), GetTop()); }
/** @brief The top right corner of the region.
@return Returns the top right corner. */
Point GetTopRight() { return Point(GetRight(), GetTop()); }
/** @brief The bottom left corner of the region.
@return Returns the bottom left corner. */
Point GetBottomLeft() { return Point(GetLeft(), GetBottom()); }
/** @brief The bottom right corner of the region.
@return Returns the bottom right corner. */
Point GetBottomRight() { return Point(GetRight(), GetBottom()); }
/** @brief The center position of the region.
@return Returns the center position. */
Vector2 GetCenter() { return GetTopLeft().ToVector2() + (Vector2(Width, Height) / 2); }
/** @brief Moves the region by the specified amount.
@param x The amount to move the region on the x-axis.
@param y The amount to move the region on the y-axis. */
void Translate(const int x, const int y)
{
X += x;
Y += y;
}
/** @brief Moves the region by the specified amount.
@param point The amount to move the region.
@overload */
void Translate(const Point &point)
{
X += point.X;
Y += point.Y;
}
int X; /**< @brief The left side of the region. */
int Y; /**< @brief The top of the region. */
int Width; /**< @brief The width of the region. */
int Height; /**< @brief The height of the region. */
};
}