-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathSimpleVoronoiIsland.hpp
396 lines (344 loc) · 19.4 KB
/
SimpleVoronoiIsland.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
/*#######################################################################################
Copyright (c) 2017-2019 Kasugaccho
Copyright (c) 2018-2019 As Project
https://github.com/Kasugaccho/DungeonTemplateLibrary
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_SHAPE_SIMPLE_VORONOI_ISLAND_HPP
#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DTL_SHAPE_SIMPLE_VORONOI_ISLAND_HPP
/*#######################################################################################
日本語リファレンス (Reference-JP)
https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::SimpleVoronoiIsland-(形状クラス)/
#######################################################################################*/
#include <utility>
#include <DTL/Base/Struct.hpp>
#include <DTL/Macros/constexpr.hpp>
#include <DTL/Macros/nodiscard.hpp>
#include <DTL/Random/RandomEngine.hpp>
#include <DTL/Type/Forward.hpp>
#include <DTL/Type/SizeT.hpp>
#include <DTL/Type/SSizeT.hpp>
#include <DTL/Type/UniquePtr.hpp>
#include <DTL/Utility/VoronoiDiagram.hpp>
/*#######################################################################################
[概要] "dtl名前空間"とは"DungeonTemplateLibrary"の全ての機能が含まれる名前空間である。
[Summary] The "dtl" is a namespace that contains all the functions of "DungeonTemplateLibrary".
#######################################################################################*/
namespace dtl {
inline namespace shape { //"dtl::shape"名前空間に属する
//マップの外枠を指定した数値で埋め、偶数マスを指定した数値で埋める
template<typename Matrix_Var_, typename UniquePair_ = DTL_TYPE_UNIQUE_PTR< ::std::pair<::dtl::type::ssize, ::dtl::type::ssize>[]>, typename UniqueInt_ = DTL_TYPE_UNIQUE_PTR<Matrix_Var_[]>>
class SimpleVoronoiIsland {
private:
///// エイリアス (Alias) /////
using Index_Size = ::dtl::type::size;
///// メンバ変数 (Member Variable) /////
::dtl::utility::VoronoiDiagram<Matrix_Var_, UniquePair_, UniqueInt_> voronoiDiagram{};
double probability_value{ 0.5 };
Matrix_Var_ land_value{};
Matrix_Var_ sea_value{};
public:
///// メンバ変数の値を取得 (Get Value) /////
/*#######################################################################################
[概要] 描画始点座標Xを取得する。
[戻り値] 戻り値の型は std::size_t である。
[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->voronoiDiagram.getPointX();
}
/*#######################################################################################
[概要] 描画始点座標Yを取得する。
[戻り値] 戻り値の型は std::size_t である。
[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->voronoiDiagram.getPointY();
}
/*#######################################################################################
[概要] 描画横幅Wを取得する。
[戻り値] 戻り値の型は std::size_t である。
[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->voronoiDiagram.getWidth();
}
/*#######################################################################################
[概要] 描画縦幅Hを取得する。
[戻り値] 戻り値の型は std::size_t である。
[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->voronoiDiagram.getHeight();
}
DTL_VERSIONING_CPP17_NODISCARD
constexpr ::dtl::type::size getValue() const noexcept {
return this->voronoiDiagram.getValue();
}
constexpr bool isIsland(const ::std::pair<::dtl::type::ssize, ::dtl::type::ssize>& point_, const ::dtl::type::ssize sx_, const ::dtl::type::ssize sy_, const ::dtl::type::ssize w_, const ::dtl::type::ssize h_, const ::dtl::type::ssize numerator_, const ::dtl::type::ssize denominator_) const noexcept {
//return true;
return (point_.first > ((w_ - sx_) * numerator_ / denominator_ + sx_) && point_.first < ((w_ - sx_) * (denominator_ - numerator_) / denominator_ + sx_)) && (point_.second > ((h_ - sy_) * numerator_ / denominator_ + sy_) && point_.second < ((h_ - sy_) * (denominator_ - numerator_) / denominator_ + sy_));
}
///// 生成呼び出し (Drawing Function Call) /////
//STL
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_) const noexcept {
return this->voronoiDiagram.draw(matrix_,
[this](const ::std::pair<::dtl::type::ssize, ::dtl::type::ssize> & point_, Matrix_Var_ & color_, const ::dtl::type::ssize sx_, const ::dtl::type::ssize sy_, const ::dtl::type::ssize w_, const ::dtl::type::ssize h_) {
if ((this->isIsland(point_, sx_, sy_, w_, h_, 2, 5) || this->isIsland(point_, sx_, sy_, w_, h_, 1, 5)) && DTL_RANDOM_ENGINE.probability(this->probability_value)) color_ = this->land_value;
else color_ = this->sea_value;
});
}
//LayerSTL
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_, const Index_Size layer_) const noexcept {
return this->voronoiDiagram.draw(matrix_, layer_,
[this](const ::std::pair<::dtl::type::ssize, ::dtl::type::ssize>& point_, Matrix_Var_ & color_, const ::dtl::type::ssize sx_, const ::dtl::type::ssize sy_, const ::dtl::type::ssize w_, const ::dtl::type::ssize h_) {
if ((this->isIsland(point_, sx_, sy_, w_, h_, 2, 5) || this->isIsland(point_, sx_, sy_, w_, h_, 1, 5)) && DTL_RANDOM_ENGINE.probability(this->probability_value)) color_ = this->land_value;
else color_ = this->sea_value;
});
}
//Normal
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept {
return this->voronoiDiagram.draw(matrix_, max_x_, max_y_,
[this](const ::std::pair<::dtl::type::ssize, ::dtl::type::ssize>& point_, Matrix_Var_ & color_, const ::dtl::type::ssize sx_, const ::dtl::type::ssize sy_, const ::dtl::type::ssize w_, const ::dtl::type::ssize h_) {
if ((this->isIsland(point_, sx_, sy_, w_, h_, 2, 5) || this->isIsland(point_, sx_, sy_, w_, h_, 1, 5)) && DTL_RANDOM_ENGINE.probability(this->probability_value)) color_ = this->land_value;
else color_ = this->sea_value;
});
}
//LayerNormal
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_) const noexcept {
return this->voronoiDiagram.draw(matrix_, layer_, max_x_, max_y_,
[this](const ::std::pair<::dtl::type::ssize, ::dtl::type::ssize>& point_, Matrix_Var_ & color_, const ::dtl::type::ssize sx_, const ::dtl::type::ssize sy_, const ::dtl::type::ssize w_, const ::dtl::type::ssize h_) {
if ((this->isIsland(point_, sx_, sy_, w_, h_, 2, 5) || this->isIsland(point_, sx_, sy_, w_, h_, 1, 5)) && DTL_RANDOM_ENGINE.probability(this->probability_value)) color_ = this->land_value;
else color_ = this->sea_value;
});
}
//Array
template<typename Matrix_>
constexpr bool drawArray(Matrix_&& matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept {
return this->voronoiDiagram.drawArray(matrix_, max_x_, max_y_,
[this](const ::std::pair<::dtl::type::ssize, ::dtl::type::ssize>& point_, Matrix_Var_ & color_, const ::dtl::type::ssize sx_, const ::dtl::type::ssize sy_, const ::dtl::type::ssize w_, const ::dtl::type::ssize h_) {
if ((this->isIsland(point_, sx_, sy_, w_, h_, 2, 5) || this->isIsland(point_, sx_, sy_, w_, h_, 1, 5)) && DTL_RANDOM_ENGINE.probability(this->probability_value)) color_ = this->land_value;
else color_ = this->sea_value;
});
}
///// 生成呼び出しファンクタ (Drawing Functor) /////
template<typename Matrix_, typename ...Args_>
constexpr bool operator()(Matrix_&& matrix_, Args_&& ... args_) const noexcept {
return this->draw(DTL_TYPE_FORWARD<Matrix_>(matrix_), DTL_TYPE_FORWARD<Args_>(args_)...);
}
///// ダンジョン行列生成 (Create Dungeon Matrix) /////
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& create(Matrix_&& matrix_, Args_&& ... args_) const noexcept {
this->draw(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& createArray(Matrix_&& matrix_, Args_&& ... args_) const noexcept {
this->drawArray(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& createOperator(Matrix_&& matrix_, Args_&& ... args_) const noexcept {
this->drawOperator(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& createOperatorArray(Matrix_&& matrix_, Args_&& ... args_) const noexcept {
this->drawOperatorArray(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
///// 消去 (Clear) /////
/*#######################################################################################
[概要] 描画始点座標Xを初期値に戻す(描画始点座標Xを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[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
SimpleVoronoiIsland& clearPointX() noexcept {
this->voronoiDiagram.clearPointX();
return *this;
}
/*#######################################################################################
[概要] 描画始点座標Yを初期値に戻す(描画始点座標Yを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[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
SimpleVoronoiIsland& clearPointY() noexcept {
this->voronoiDiagram.clearPointY();
return *this;
}
/*#######################################################################################
[概要] 範囲の大きさ(X軸方向)を初期値に戻す(描画横幅Wを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[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
SimpleVoronoiIsland& clearWidth() noexcept {
this->voronoiDiagram.clearWidth();
return *this;
}
/*#######################################################################################
[概要] 範囲の大きさ(Y軸方向)を初期値に戻す(描画縦幅Hを消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[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
SimpleVoronoiIsland& clearHeight() noexcept {
this->voronoiDiagram.clearHeight();
return *this;
}
/*#######################################################################################
[概要] 塗り値を初期値に戻す(描画値を消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Resets the drawing value to the initial value (deletes the drawing value).
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& clearValue() noexcept {
this->voronoiDiagram.clearValue();
return *this;
}
/*#######################################################################################
[概要] 描画始点座標(X,Y)を初期値に戻す(描画始点座標(X,Y)を消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[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
SimpleVoronoiIsland& clearPoint() noexcept {
this->clearPointX();
this->clearPointY();
return *this;
}
/*#######################################################################################
[概要] 描画範囲を初期値に戻す(描画範囲(X,Y,W,H)を消去する)。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[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
SimpleVoronoiIsland& clearRange() noexcept {
this->clearPointX();
this->clearPointY();
this->clearWidth();
this->clearHeight();
return *this;
}
/*#######################################################################################
[概要] 全ての値を初期値に戻す。
[戻り値] 戻り値の型は 当クラスの参照値 である。
[Summary] Reset all values to their initial values.
[Return value] The return type is a reference value of this class.
#######################################################################################*/
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& clear() noexcept {
this->clearRange();
this->clearValue();
return *this;
}
///// 代入 /////
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setPointX(const Index_Size end_x_) noexcept {
this->voronoiDiagram.setPointX(end_x_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setPointY(const Index_Size end_y_) noexcept {
this->voronoiDiagram.setPointY(end_y_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setWidth(const Index_Size width_) noexcept {
this->voronoiDiagram.setWidth(width_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setHeight(const Index_Size height_) noexcept {
this->voronoiDiagram.setHeight(height_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setValue(const ::dtl::type::size voronoi_num_) noexcept {
this->voronoiDiagram.setValue(voronoi_num_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setRange(const ::dtl::base::MatrixRange& matrix_range_) noexcept {
this->voronoiDiagram.setRange(matrix_range_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setPoint(const Index_Size point_) noexcept {
this->setPointX(point_);
this->setPointY(point_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setPoint(const Index_Size end_x_, const Index_Size end_y_) noexcept {
this->setPointX(end_x_);
this->setPointY(end_y_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size length_) noexcept {
this->setPointX(end_x_);
this->setPointY(end_y_);
this->setWidth(length_);
this->setHeight(length_);
return *this;
}
DTL_VERSIONING_CPP14_CONSTEXPR
SimpleVoronoiIsland& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept {
this->setPointX(end_x_);
this->setPointY(end_y_);
this->setWidth(width_);
this->setHeight(height_);
return *this;
}
///// コンストラクタ (Constructor) /////
SimpleVoronoiIsland() = default;
constexpr explicit SimpleVoronoiIsland(const ::dtl::type::size voronoi_num_) noexcept
:voronoiDiagram(voronoi_num_) {}
constexpr SimpleVoronoiIsland(const ::dtl::type::size voronoi_num_, const double probability_value_) noexcept
:voronoiDiagram(voronoi_num_), probability_value(probability_value_) {}
constexpr SimpleVoronoiIsland(const ::dtl::type::size voronoi_num_, const double probability_value_, const Matrix_Var_& land_value_) noexcept
:voronoiDiagram(voronoi_num_), probability_value(probability_value_), land_value(land_value_) {}
constexpr SimpleVoronoiIsland(const ::dtl::type::size voronoi_num_, const double probability_value_, const Matrix_Var_& land_value_, const Matrix_Var_& sea_value_) noexcept
:voronoiDiagram(voronoi_num_), probability_value(probability_value_), land_value(land_value_), sea_value(sea_value_) {}
constexpr explicit SimpleVoronoiIsland(const ::dtl::base::MatrixRange& matrix_range_) noexcept
:voronoiDiagram(matrix_range_) {}
constexpr SimpleVoronoiIsland(const ::dtl::base::MatrixRange& matrix_range_, const ::dtl::type::size voronoi_num_) noexcept
:voronoiDiagram(matrix_range_, voronoi_num_) {}
constexpr SimpleVoronoiIsland(const ::dtl::base::MatrixRange& matrix_range_, const ::dtl::type::size voronoi_num_, const double probability_value_) noexcept
:voronoiDiagram(matrix_range_, voronoi_num_), probability_value(probability_value_) {}
constexpr SimpleVoronoiIsland(const ::dtl::base::MatrixRange& matrix_range_, const ::dtl::type::size voronoi_num_, const double probability_value_, const Matrix_Var_& land_value_) noexcept
:voronoiDiagram(matrix_range_, voronoi_num_), probability_value(probability_value_), land_value(land_value_) {}
constexpr SimpleVoronoiIsland(const ::dtl::base::MatrixRange& matrix_range_, const ::dtl::type::size voronoi_num_, const double probability_value_, const Matrix_Var_& land_value_, const Matrix_Var_& sea_value_) noexcept
:voronoiDiagram(matrix_range_, voronoi_num_), probability_value(probability_value_), land_value(land_value_), sea_value(sea_value_) {}
};
}
}
#endif //Included Dungeon Template Library