/
BasicRect.hpp
477 lines (421 loc) · 23.2 KB
/
BasicRect.hpp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/*#######################################################################################
Copyright (c) 2017-2019 Kasugaccho
Copyright (c) 2018-2019 As Project
https://github.com/Kasugaccho/DungeonTemplateLibrary
wanotaitei@gmail.com
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#######################################################################################*/
#ifndef INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DTL_RANGE_BASIC_RECT_HPP
#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DTL_RANGE_BASIC_RECT_HPP
#include <DTL/Base/Struct.hpp>
#include <DTL/Macros/constexpr.hpp>
#include <DTL/Macros/nodiscard.hpp>
#include <DTL/Type/SizeT.hpp>
/*#######################################################################################
[概要] "dtl名前空間"とは"DungeonTemplateLibrary"の全ての機能が含まれる名前空間である。
[Summary] The "dtl" is a namespace that contains all the functions of "DungeonTemplateLibrary".
#######################################################################################*/
namespace dtl {
inline namespace range { //"dtl::range"名前空間に属する
//四角形クラス
template<typename Derived_>
class BasicRect {
private:
///// エイリアス (Alias) /////
using Index_Size = ::dtl::type::size;
protected:
///// メンバ変数 (Member Variable) /////
Index_Size start_x{};
Index_Size start_y{};
Index_Size width{};
Index_Size height{};
///// 計算補助 /////
constexpr Index_Size calcEndX(const Index_Size max_x_) const noexcept {
return (this->width == 0 || this->start_x + this->width >= max_x_)
? max_x_
: this->start_x + this->width;
}
constexpr Index_Size calcEndY(const Index_Size max_y_) const noexcept {
return (this->height == 0 || this->start_y + this->height >= max_y_)
? max_y_
: this->start_y + this->height;
}
public:
///// コンストラクタ (Constructor) /////
/*#######################################################################################
[概要] デフォルトのコンストラクタ
#######################################################################################*/
constexpr BasicRect() = default;
/*#######################################################################################
[概要] 描画範囲指定のコンストラクタ
#######################################################################################*/
constexpr explicit BasicRect(const ::dtl::base::MatrixRange& matrix_range_) noexcept
:start_x(matrix_range_.x), start_y(matrix_range_.y),
width(matrix_range_.w), height(matrix_range_.h) {}
/*#######################################################################################
[概要] 描画範囲指定のコンストラクタ
#######################################################################################*/
constexpr explicit BasicRect(const Index_Size start_x_, const Index_Size start_y_, const Index_Size width_, const Index_Size height_) noexcept
:start_x(start_x_), start_y(start_y_),
width(width_), height(height_) {}
///// メンバ変数の値を取得 (Get Value) /////
/*#######################################################################################
[概要] 描画始点座標Xを取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getPointX-(形状描画)/
[Summary] Gets the drawing start point coordinate X.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getPointX(Matrix_Int_& value_) noexcept {
value_ = static_cast<Matrix_Int_>(this->start_x);
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標Yを取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getPointY-(形状描画)/
[Summary] Gets the drawing start point coordinate Y.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getPointY(Matrix_Int_& value_) noexcept {
value_ = static_cast<Matrix_Int_>(this->start_y);
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画横幅Wを取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getWidth-(形状描画)/
[Summary] Gets the drawing width.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getWidth(Matrix_Int_& value_) noexcept {
value_ = static_cast<Matrix_Int_>(this->width);
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画縦幅Hを取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getHeight-(形状描画)/
[Summary] Gets the drawing height.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getHeight(Matrix_Int_& value_) noexcept {
value_ = static_cast<Matrix_Int_>(this->height);
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標(X,Y)を取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getPoint-(形状描画)/
[Summary] Gets the drawing start coordinate (X, Y).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getPoint(Matrix_Int_& value_) noexcept {
const Matrix_Int_ value{ this->start_x ,this->start_y };
value_ = value;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標(X,Y)を取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getPoint-(形状描画)/
[Summary] Gets the drawing start coordinate (X, Y).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_, typename Matrix_Int2_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getPoint(Matrix_Int_& value_, Matrix_Int2_& value2_) noexcept {
value_ = static_cast<Matrix_Int_>(this->start_x);
value2_ = static_cast<Matrix_Int2_>(this->start_y);
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画範囲(X,Y,W,H)を取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getRange-(形状描画)/
[Summary] Gets the drawing range.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_, typename Matrix_Int2_, typename Matrix_Int3_, typename Matrix_Int4_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getRange(Matrix_Int_& value_, Matrix_Int2_& value2_, Matrix_Int3_& value3_, Matrix_Int4_& value4_) noexcept {
value_ = static_cast<Matrix_Int_>(this->start_x);
value2_ = static_cast<Matrix_Int2_>(this->start_y);
value3_ = static_cast<Matrix_Int3_>(this->width);
value4_ = static_cast<Matrix_Int4_>(this->height);
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画範囲(X,Y,W)を取得する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getRange-(形状描画)/
[Summary] Gets the drawing range.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
template<typename Matrix_Int_, typename Matrix_Int2_, typename Matrix_Int3_, typename Matrix_Int4_>
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& getRange(Matrix_Int_& value_, Matrix_Int2_& value2_, Matrix_Int3_& value3_) noexcept {
value_ = static_cast<Matrix_Int_>(this->start_x);
value2_ = static_cast<Matrix_Int2_>(this->start_y);
value3_ = static_cast<Matrix_Int3_>(this->width);
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標Xを取得する。
[戻り値] 戻り値の型は std::size_t である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getPointX-(形状描画)/
[Summary] Gets the drawing start point coordinate X.
[Return value] The return type is std::size_t.
#######################################################################################*/
DTL_VERSIONING_CPP17_NODISCARD
constexpr Index_Size getPointX() const noexcept {
return this->start_x;
}
/*#######################################################################################
[概要] 描画始点座標Yを取得する。
[戻り値] 戻り値の型は std::size_t である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getPointY-(形状描画)/
[Summary] Gets the drawing start point coordinate Y.
[Return value] The return type is std::size_t.
#######################################################################################*/
DTL_VERSIONING_CPP17_NODISCARD
constexpr Index_Size getPointY() const noexcept {
return this->start_y;
}
/*#######################################################################################
[概要] 描画横幅Wを取得する。
[戻り値] 戻り値の型は std::size_t である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getWidth-(形状描画)/
[Summary] Gets the drawing width.
[Return value] The return type is std::size_t.
#######################################################################################*/
DTL_VERSIONING_CPP17_NODISCARD
constexpr Index_Size getWidth() const noexcept {
return this->width;
}
/*#######################################################################################
[概要] 描画縦幅Hを取得する。
[戻り値] 戻り値の型は std::size_t である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::getHeight-(形状描画)/
[Summary] Gets the drawing height.
[Return value] The return type is std::size_t.
#######################################################################################*/
DTL_VERSIONING_CPP17_NODISCARD
constexpr Index_Size getHeight() const noexcept {
return this->height;
}
///// 消去 (Clear) /////
/*#######################################################################################
[概要] 描画始点座標Xを初期値に戻す(描画始点座標Xを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::clearPointX-(形状描画)/
[Summary] Resets the drawing start coordinate X to the initial value (deletes the drawing start coordinate X).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& clearPointX() noexcept {
this->start_x = 0;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標Yを初期値に戻す(描画始点座標Yを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::clearPointY-(形状描画)/
[Summary] Resets the drawing start coordinate Y to the initial value (deletes the drawing start coordinate Y).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& clearPointY() noexcept {
this->start_y = 0;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 範囲の大きさ(X軸方向)を初期値に戻す(描画横幅Wを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::clearWidth-(形状描画)/
[Summary] Resets the width of the range (X axis direction) to the initial value (deletes the drawing width).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& clearWidth() noexcept {
this->width = 0;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 範囲の大きさ(Y軸方向)を初期値に戻す(描画縦幅Hを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::clearHeight-(形状描画)/
[Summary] Resets the height of the range (Y axis direction) to the initial value (deletes the drawing height).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& clearHeight() noexcept {
this->height = 0;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 範囲の大きさ(Width, Height)を初期値に戻す(描画幅(W,H)を消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Reset the drawing range length (Width, Height) to the initial value (delete the drawing length (W, H)).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& clearLength() noexcept {
this->clearWidth();
this->clearHeight();
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標(X,Y)を初期値に戻す(描画始点座標(X,Y)を消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::clearPoint-(形状描画)/
[Summary] Resets the drawing start coordinate (X, Y) to the initial value (deletes the drawing start coordinate (X, Y)).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& clearPoint() noexcept {
this->clearPointX();
this->clearPointY();
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画範囲を初期値に戻す(描画範囲(X,Y,W,H)を消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[参考ページ] https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::XX::YY::clearRange-(形状描画)/
[Summary] Resets the drawing range to the initial value (deletes the drawing range (X, Y, W, H)).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& clearRange() noexcept {
this->clearPointX();
this->clearPointY();
this->clearWidth();
this->clearHeight();
return static_cast<Derived_&>(*this);
}
///// 代入 /////
/*#######################################################################################
[概要] 描画始点座標Xを設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing start point coordinate X.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setPointX(const Index_Size start_x_) noexcept {
this->start_x = start_x_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標Yを設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing start point coordinate Y.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setPointY(const Index_Size start_y_) noexcept {
this->start_y = start_y_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画横幅Wを設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing width.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setWidth(const Index_Size width_) noexcept {
this->width = width_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画縦幅Hを設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing height.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setHeight(const Index_Size height_) noexcept {
this->height = height_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標(X,Y)を設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing start point coordinates (X, Y).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setPoint(const Index_Size point_) noexcept {
this->start_x = point_;
this->start_y = point_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画始点座標(X,Y)を設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing start point coordinates (X, Y).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setPoint(const Index_Size start_x_, const Index_Size start_y_) noexcept {
this->start_x = start_x_;
this->start_y = start_y_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画範囲(X,Y,W,H)を設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing range (X, Y, W, H).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setRange(const Index_Size start_x_, const Index_Size start_y_, const Index_Size length_) noexcept {
this->start_x = start_x_;
this->start_y = start_y_;
this->width = length_;
this->height = length_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画範囲(X,Y,W,H)を設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing range (X, Y, W, H).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setRange(const Index_Size start_x_, const Index_Size start_y_, const Index_Size width_, const Index_Size height_) noexcept {
this->start_x = start_x_;
this->start_y = start_y_;
this->width = width_;
this->height = height_;
return static_cast<Derived_&>(*this);
}
/*#######################################################################################
[概要] 描画範囲(X,Y,W,H)を設定する。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Set the drawing range (X, Y, W, H).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
Derived_& setRange(const ::dtl::base::MatrixRange & matrix_range_) noexcept {
this->start_x = matrix_range_.x;
this->start_y = matrix_range_.y;
this->width = matrix_range_.w;
this->height = matrix_range_.h;
return static_cast<Derived_&>(*this);
}
};
}
}
#endif //Included Dungeon Template Library