MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_rectangle.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_RECTANGLE_H_1606631656
12#define INCGUARD_MGL_RECTANGLE_H_1606631656
13
15
16namespace MGL
17{
20{
21 float x;
22 float y;
23 float width;
24 float height;
25
26 /* ------------------------------------------------------------------------- */
30 /* ------------------------------------------------------------------------- */
31 constexpr Rectangle() noexcept
32 : x(0.0f)
33 , y(0.0f)
34 , width(0.0f)
35 , height(0.0f)
36 {}
37
38 /* ------------------------------------------------------------------------- */
46 /* ------------------------------------------------------------------------- */
47 constexpr Rectangle(float inX, float inY, float inWidth, float inHeight) noexcept
48 : x(inX)
49 , y(inY)
50 , width(inWidth)
51 , height(inHeight)
52 {}
53
54 /* ------------------------------------------------------------------------- */
60 /* ------------------------------------------------------------------------- */
61 constexpr Rectangle(const Vector2 &position, const Vector2 &size) noexcept
62 : x(position.x)
63 , y(position.y)
64 , width(size.x)
65 , height(size.y)
66 {}
67
68 /* ------------------------------------------------------------------------- */
73 /* ------------------------------------------------------------------------- */
74 constexpr void SetPosition(const Vector2 &position) noexcept
75 {
76 x = position.x;
77 y = position.y;
78 }
79
80 /* ------------------------------------------------------------------------- */
86 /* ------------------------------------------------------------------------- */
87 constexpr void SetPosition(float inX, float inY) noexcept
88 {
89 x = inX;
90 y = inY;
91 }
92
93 /* ------------------------------------------------------------------------- */
98 /* ------------------------------------------------------------------------- */
99 constexpr void SetSize(const Vector2 &size) noexcept
100 {
101 width = size.x;
102 height = size.y;
103 }
104
105 /* ------------------------------------------------------------------------- */
111 /* ------------------------------------------------------------------------- */
112 constexpr void SetSize(float inWidth, float inHeight) noexcept
113 {
114 width = inWidth;
115 height = inHeight;
116 }
117
118 /* ------------------------------------------------------------------------- */
123 /* ------------------------------------------------------------------------- */
124 [[nodiscard]] constexpr Vector2 GetPosition() const noexcept
125 {
126 return {x, y};
127 }
128
129 /* ------------------------------------------------------------------------- */
134 /* ------------------------------------------------------------------------- */
135 [[nodiscard]] constexpr Vector2 GetSize() const noexcept
136 {
137 return {width, height};
138 }
139
140 /* ------------------------------------------------------------------------- */
147 /* ------------------------------------------------------------------------- */
148 [[nodiscard]] constexpr bool IsEnclosed(const Vector2 &point) const noexcept
149 {
150 if ((x <= point.x) && (y <= point.y))
151 {
152 if (((x + width) >= point.x) && ((y + height) >= point.y))
153 {
154 return true;
155 }
156 }
157
158 return false;
159 }
160};
161} // namespace MGL
162
163#endif // INCGUARD_MGL_RECTANGLE_H_1606631656
164
165// vim: et ts=4 sw=4 sts=4
MGL 2Dベクトル
矩形
Definition mgl_rectangle.h:20
constexpr Rectangle(float inX, float inY, float inWidth, float inHeight) noexcept
指定したパラメータで初期化
Definition mgl_rectangle.h:47
constexpr void SetPosition(float inX, float inY) noexcept
位置を設定
Definition mgl_rectangle.h:87
constexpr void SetPosition(const Vector2 &position) noexcept
位置を設定
Definition mgl_rectangle.h:74
constexpr void SetSize(float inWidth, float inHeight) noexcept
サイズを設定
Definition mgl_rectangle.h:112
float y
Y座標
Definition mgl_rectangle.h:22
constexpr Vector2 GetPosition() const noexcept
位置を取得
Definition mgl_rectangle.h:124
float width
Definition mgl_rectangle.h:23
float height
高さ
Definition mgl_rectangle.h:24
constexpr void SetSize(const Vector2 &size) noexcept
サイズを設定
Definition mgl_rectangle.h:99
constexpr bool IsEnclosed(const Vector2 &point) const noexcept
指定した位置が矩形の内側にあるかを取得
Definition mgl_rectangle.h:148
float x
X座標
Definition mgl_rectangle.h:21
constexpr Vector2 GetSize() const noexcept
サイズを取得
Definition mgl_rectangle.h:135
constexpr Rectangle() noexcept
ゼロ初期化
Definition mgl_rectangle.h:31
constexpr Rectangle(const Vector2 &position, const Vector2 &size) noexcept
位置とサイズで初期化
Definition mgl_rectangle.h:61
2Dベクトル
Definition mgl_vector2.h:23