From 38f5de318160e0dd4250e943f6c3cbdfb51c1ef4 Mon Sep 17 00:00:00 2001 From: Kasugaccho <30593725+Kasugaccho@users.noreply.github.com> Date: Tue, 14 May 2019 01:13:13 +0900 Subject: [PATCH] v0.4.6.1 --- MSVC/DungeonTemplateLibrary/20190502.cpp | 9 +- README.md | 2 +- include/DTL.hpp | 2 +- include/Shape/Border.hpp | 492 ++++++++++++++++++++- include/Shape/BorderOdd.hpp | 521 ++++++++++++++++++++++- include/Shape/PointGrid.hpp | 443 ++++++++++++++++++- include/Shape/Rect.hpp | 443 ++++++++++++++++++- 7 files changed, 1819 insertions(+), 93 deletions(-) diff --git a/MSVC/DungeonTemplateLibrary/20190502.cpp b/MSVC/DungeonTemplateLibrary/20190502.cpp index 11f63f6..37a9615 100644 --- a/MSVC/DungeonTemplateLibrary/20190502.cpp +++ b/MSVC/DungeonTemplateLibrary/20190502.cpp @@ -1,16 +1,11 @@ #include #include -#include int main() { - std::array, 10> matrix{ {} }; + std::array, 10> matrix{ {} }; dtl::Border(1).draw(matrix); - - std::string str{}; - dtl::board::WriteNumber("\n", "(", "), ").draw(matrix, str); - - std::cout << str; + dtl::OutputNumber(",").draw(matrix); } \ No newline at end of file diff --git a/README.md b/README.md index 4405332..11b55c2 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ ## Overview -### [**Version 0.4.6**](https://github.com/Kasugaccho/DungeonTemplateLibrary/releases) [ C++11/14/17 ] +### [**Version 0.4.6.1**](https://github.com/Kasugaccho/DungeonTemplateLibrary/releases) [ C++11/14/17 ] |Compiler|C++17|C++14| |:---|:---|:---| diff --git a/include/DTL.hpp b/include/DTL.hpp index 877c0c8..3f4eff3 100644 --- a/include/DTL.hpp +++ b/include/DTL.hpp @@ -17,7 +17,7 @@ /* バージョン */ #ifndef DUNGEON_TEMPLATE_LIBRARY_VERSION -#define DUNGEON_TEMPLATE_LIBRARY_VERSION (20190513L) +#define DUNGEON_TEMPLATE_LIBRARY_VERSION (20190514L) #endif diff --git a/include/Shape/Border.hpp b/include/Shape/Border.hpp index b587e85..fbf0bc5 100644 --- a/include/Shape/Border.hpp +++ b/include/Shape/Border.hpp @@ -1,24 +1,4 @@ -/*####################################################################################### - 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_SHAPE_BORDER_HPP -#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_BORDER_HPP - -/*####################################################################################### - 日本語リファレンス (Reference-JP) - https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::Border-(形状クラス)/ -#######################################################################################*/ - -/* Character Code : UTF-8 (BOM) */ -/* Bug Check : already checked */ -/* Android NDK Compile (Clang 5.0) : already checked */ - +/* #include #include #include @@ -98,3 +78,473 @@ namespace dtl { } #endif //Included Dungeon Template Library +*/ + +/*####################################################################################### + 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_SHAPE_BORDER_HPP +#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_BORDER_HPP + +/*####################################################################################### + 日本語リファレンス (Reference-JP) + https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::Border-(%E5%BD%A2%E7%8A%B6%E3%82%AF%E3%83%A9%E3%82%B9)/ +#######################################################################################*/ + +/* Character Code : UTF-8 (BOM) */ +/* Bug Check : already checked */ +/* Android NDK Compile (Clang 5.0) : already checked */ + +#include +#include +#include +#include +#include +#include + +namespace dtl { + inline namespace shape { + + //マップの外枠を指定した数値で埋める + template + class Border { + private: + + + ///// エイリアス ///// + + using Index_Size = std::size_t; + + + + ///// メンバ変数 ///// + + Index_Size start_x{}; + Index_Size start_y{}; + Index_Size width{}; + Index_Size height{}; + Matrix_Int_ draw_value{}; + + + ///// 代入処理 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_) const noexcept { + matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_&& matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_][end_x_])) matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_ * max_x_ + end_x_])) matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Function_ && function_) const noexcept { + if (function_(matrix_[end_y_][end_x_][layer_])) matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + + ///// 基本処理 ///// + + //STL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawSTL(Matrix_ && matrix_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < matrix_[this->start_y].size(); ++col) + this->substitutionSTL(matrix_, col, this->start_y, args_...); + for (Index_Size col{ this->start_x }; col < matrix_[end_y_ - 1].size(); ++col) + this->substitutionSTL(matrix_, col, end_y_ - 1, args_...); + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() == 0) continue; + this->substitutionSTL(matrix_, this->start_x, row, args_...); + this->substitutionSTL(matrix_, matrix_[row].size() - 1, row, std::forward(args_)...); + } + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawWidthSTL(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[this->start_y].size(); ++col) + this->substitutionSTL(matrix_, col, this->start_y, args_...); + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[end_y_ - 1].size(); ++col) + this->substitutionSTL(matrix_, col, end_y_ - 1, args_...); + if (end_x_ == 0) return true; + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() == 0) continue; + this->substitutionSTL(matrix_, this->start_x, row, args_...); + if (matrix_[row].size() <= end_x_) this->substitutionSTL(matrix_, matrix_[row].size() - 1, row, args_...); + else this->substitutionSTL(matrix_, end_x_ - 1, row, std::forward(args_)...); + } + return true; + } + + //LayerSTL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < matrix_[this->start_y].size(); ++col) + this->substitutionLayer(matrix_, layer_, col, this->start_y, args_...); + for (Index_Size col{ this->start_x }; col < matrix_[end_y_ - 1].size(); ++col) + this->substitutionLayer(matrix_, layer_, col, end_y_ - 1, args_...); + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() == 0) continue; + this->substitutionLayer(matrix_, layer_, this->start_x, row, args_...); + this->substitutionLayer(matrix_, layer_, matrix_[row].size() - 1, row, std::forward(args_)...); + } + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerWidthSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[this->start_y].size(); ++col) + this->substitutionLayer(matrix_, layer_, col, this->start_y, args_...); + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[end_y_ - 1].size(); ++col) + this->substitutionLayer(matrix_, layer_, col, end_y_ - 1, args_...); + if (end_x_ == 0) return true; + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() == 0) continue; + this->substitutionLayer(matrix_, layer_, this->start_x, row, args_...); + if (matrix_[row].size() <= end_x_) this->substitutionLayer(matrix_, layer_, matrix_[row].size() - 1, row, args_...); + else this->substitutionLayer(matrix_, layer_, end_x_ - 1, row, std::forward(args_)...); + } + return true; + } + + //Normal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawNormal(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_x_ == 0 || end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < end_x_; ++col) { + this->substitutionSTL(matrix_, col, this->start_y, args_...); + this->substitutionSTL(matrix_, col, end_y_ - 1, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + this->substitutionSTL(matrix_, this->start_x, row, args_...); + this->substitutionSTL(matrix_, end_x_ - 1, row, std::forward(args_)...); + } + return true; + } + + //LayerNormal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerNormal(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_x_ == 0 || end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < end_x_; ++col) { + this->substitutionLayer(matrix_, layer_, col, this->start_y, args_...); + this->substitutionLayer(matrix_, layer_, col, end_y_ - 1, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + this->substitutionLayer(matrix_, layer_, this->start_x, row, args_...); + this->substitutionLayer(matrix_, layer_, end_x_ - 1, row, std::forward(args_)...); + } + return true; + } + + //Array + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawArray(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Args_ && ... args_) const noexcept { + if (end_x_ == 0 || end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < end_x_; ++col) { + this->substitutionArray(matrix_, col, this->start_y, max_x_, args_...); + this->substitutionArray(matrix_, col, end_y_ - 1, max_x_, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + this->substitutionArray(matrix_, this->start_x, row, max_x_, args_...); + this->substitutionArray(matrix_, end_x_ - 1, row, max_x_, std::forward(args_)...); + } + return true; + } + + public: + + + ///// 情報取得 ///// + + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointX() const noexcept { + return this->start_x; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointY() const noexcept { + return this->start_y; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getWidth() const noexcept { + return this->width; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getHeight() const noexcept { + return this->height; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Matrix_Int_ getValue() const noexcept { + return this->draw_value; + } + + + ///// 生成呼び出し ///// + + //STL + template + constexpr bool draw(Matrix_ && matrix_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //LayerSTL + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //Normal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //LayerNormal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //Array + template + constexpr bool drawArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_); + } + template + constexpr bool drawOperatorArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_, function_); + } + + + ///// 生成呼び出しファンクタ ///// + + template + constexpr bool operator()(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + return this->draw(std::forward(matrix_), std::forward(args_)...); + } + + + ///// ダンジョン行列生成 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& create(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->draw(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperator(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperator(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperatorArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperatorArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + + + ///// 消去 ///// + + //始点座標Xを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clearPointX() noexcept { + this->start_x = 0; + return *this; + } + //始点座標Yを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clearPointY() noexcept { + this->start_y = 0; + return *this; + } + //範囲の大きさ(X軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clearWidth() noexcept { + this->width = 0; + return *this; + } + //範囲の大きさ(Y軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clearHeight() noexcept { + this->height = 0; + return *this; + } + //塗り値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clearValue() noexcept { + const Matrix_Int_ new_draw_value{}; + this->draw_value = new_draw_value; + return *this; + } + //始点座標(X,Y)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clearPoint() noexcept { + this->clearPointX(); + this->clearPointY(); + return *this; + } + //描画範囲を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clearRange() noexcept { + this->clearPointX(); + this->clearPointY(); + this->clearWidth(); + this->clearHeight(); + return *this; + } + //全ての値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Border& clear() noexcept { + this->clearRange(); + this->clearValue(); + return *this; + } + + + ///// 代入 ///// + + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setPointX(const Index_Size end_x_) noexcept { + this->start_x = end_x_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setPointY(const Index_Size end_y_) noexcept { + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setWidth(const Index_Size width_) noexcept { + this->width = width_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setHeight(const Index_Size height_) noexcept { + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setValue(const Matrix_Int_ & draw_value_) noexcept { + this->draw_value = draw_value_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setPoint(const Index_Size point_) noexcept { + this->start_x = point_; + this->start_y = point_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setPoint(const Index_Size end_x_, const Index_Size end_y_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size length_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = length_; + this->height = length_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = width_; + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Border& 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 *this; + } + + + ///// コンストラクタ ///// + + constexpr Border() noexcept = default; + constexpr explicit Border(const Matrix_Int_ & draw_value_) noexcept + :draw_value(draw_value_) {} + constexpr explicit Border(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 Border(const dtl::base::MatrixRange & matrix_range_, const Matrix_Int_ & draw_value_) noexcept + :start_x(matrix_range_.x), start_y(matrix_range_.y), + width(matrix_range_.w), height(matrix_range_.h), + draw_value(draw_value_) {} + constexpr explicit Border(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_) {} + constexpr explicit Border(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_, const Matrix_Int_ & draw_value_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_), + draw_value(draw_value_) {} + }; + } +} + +#endif //Included Dungeon Template Library \ No newline at end of file diff --git a/include/Shape/BorderOdd.hpp b/include/Shape/BorderOdd.hpp index cddf008..869f9e1 100644 --- a/include/Shape/BorderOdd.hpp +++ b/include/Shape/BorderOdd.hpp @@ -1,24 +1,4 @@ -/*####################################################################################### - 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_SHAPE_BORDER_ODD_HPP -#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_BORDER_ODD_HPP - -/*####################################################################################### - 日本語リファレンス (Reference-JP) - https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::BorderOdd-(形状クラス)/ -#######################################################################################*/ - -/* Character Code : UTF-8 (BOM) */ -/* Bug Check : already checked */ -/* Android NDK Compile (Clang 5.0) : already checked */ - +/* #include #include #include @@ -103,3 +83,502 @@ namespace dtl { } #endif //Included Dungeon Template Library + +*/ + +/*####################################################################################### + 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_SHAPE_BORDER_ODD_HPP +#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_BORDER_ODD_HPP + +/*####################################################################################### + 日本語リファレンス (Reference-JP) + https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::BorderOdd-(%E5%BD%A2%E7%8A%B6%E3%82%AF%E3%83%A9%E3%82%B9)/ +#######################################################################################*/ + +/* Character Code : UTF-8 (BOM) */ +/* Bug Check : already checked */ +/* Android NDK Compile (Clang 5.0) : already checked */ + +#include +#include +#include +#include +#include +#include + +namespace dtl { + inline namespace shape { + + //四角形の生成 + template + class BorderOdd { + private: + + + ///// エイリアス ///// + + using Index_Size = std::size_t; + + + + ///// メンバ変数 ///// + + Index_Size start_x{}; + Index_Size start_y{}; + Index_Size width{}; + Index_Size height{}; + Matrix_Int_ draw_value{}; + + + ///// 代入処理 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_) const noexcept { + matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_&& matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_][end_x_])) matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_ * max_x_ + end_x_])) matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Function_ && function_) const noexcept { + if (function_(matrix_[end_y_][end_x_][layer_])) matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + + ///// 基本処理 ///// + + //STL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawSTL(Matrix_ && matrix_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ == 0) return true; + for (Index_Size col{ this->start_x }; col < matrix_[this->start_y].size(); ++col) + this->substitutionSTL(matrix_, col, start_y, args_...); + for (Index_Size col{ this->start_x }; col < matrix_[end_y_ - 1].size(); ++col) { + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionSTL(matrix_, col, end_y_ - 2, args_...); + this->substitutionSTL(matrix_, col, end_y_ - 1, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() == 0) continue; + this->substitutionSTL(matrix_, start_x, row, args_...); + if ((matrix_[row].size() - this->start_x) % 2 == 0) this->substitutionSTL(matrix_, matrix_[row].size() - 2, row, args_...); + this->substitutionSTL(matrix_, matrix_[row].size() - 1, row, std::forward(args_)...); + } + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawWidthSTL(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ < 2) return true; + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[this->start_y].size(); ++col) + this->substitutionSTL(matrix_, col, start_y, args_...); + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[end_y_ - 1].size(); ++col) { + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionSTL(matrix_, col, end_y_ - 2, args_...); + this->substitutionSTL(matrix_, col, end_y_ - 1, args_...); + } + if (end_x_ < 2) return true; + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() == 0) continue; + this->substitutionSTL(matrix_, start_x, row, args_...); + if (matrix_[row].size() <= end_x_) { + if ((matrix_[row].size() - this->start_x) % 2 == 0) this->substitutionSTL(matrix_, matrix_[row].size() - 2, row, args_...); + this->substitutionSTL(matrix_, matrix_[row].size() - 1, row, args_...); + } + else { + if ((end_x_ - this->start_x) % 2 == 0) this->substitutionSTL(matrix_, end_x_ - 2, row, args_...); + this->substitutionSTL(matrix_, end_x_ - 1, row, std::forward(args_)...); + } + } + return true; + } + + //LayerSTL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ < 2) return true; + for (Index_Size col{ this->start_x }; col < matrix_[this->start_y].size(); ++col) + this->substitutionLayer(matrix_, layer_, col, start_y, args_...); + for (Index_Size col{ this->start_x }; col < matrix_[end_y_ - 1].size(); ++col) { + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionLayer(matrix_, layer_, col, end_y_ - 2, args_...); + this->substitutionLayer(matrix_, layer_, col, end_y_ - 1, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() < 2) continue; + this->substitutionLayer(matrix_, layer_, start_x, row, args_...); + if ((matrix_[row].size() - this->start_x) % 2 == 0) this->substitutionLayer(matrix_, layer_, matrix_[row].size() - 2, row, args_...); + this->substitutionLayer(matrix_, layer_, matrix_[row].size() - 1, row, std::forward(args_)...); + } + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerWidthSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_y_ < 2) return true; + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[this->start_y].size(); ++col) + this->substitutionLayer(matrix_, layer_, col, start_y, args_...); + for (Index_Size col{ this->start_x }; col < end_x_ && col < matrix_[end_y_ - 1].size(); ++col) { + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionLayer(matrix_, layer_, col, end_y_ - 2, args_...); + this->substitutionLayer(matrix_, layer_, col, end_y_ - 1, args_...); + } + if (end_x_ < 2) return true; + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + if (matrix_[row].size() == 0) continue; + this->substitutionLayer(matrix_, layer_, start_x, row, args_...); + if (matrix_[row].size() <= end_x_) { + if ((matrix_[row].size() - this->start_x) % 2 == 0) this->substitutionLayer(matrix_, layer_, matrix_[row].size() - 2, row, args_...); + this->substitutionLayer(matrix_, layer_, matrix_[row].size() - 1, row, args_...); + } + else { + if ((end_x_ - this->start_x) % 2 == 0) this->substitutionLayer(matrix_, layer_, end_x_ - 2, row, args_...); + this->substitutionLayer(matrix_, layer_, end_x_ - 1, row, std::forward(args_)...); + } + } + return true; + } + + //Normal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawNormal(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_x_ < 2 || end_y_ < 2) return true; + for (Index_Size col{ this->start_x }; col < end_x_; ++col) { + this->substitutionSTL(matrix_, col, start_y, args_...); + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionSTL(matrix_, col, end_y_ - 2, args_...); + this->substitutionSTL(matrix_, col, end_y_ - 1, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + this->substitutionSTL(matrix_, start_x, row, args_...); + if ((end_x_ - this->start_x) % 2 == 0) this->substitutionSTL(matrix_, end_x_ - 2, row, args_...); + this->substitutionSTL(matrix_, end_x_ - 1, row, std::forward(args_)...); + } + return true; + } + + //LayerNormal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerNormal(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + if (end_x_ < 2 || end_y_ < 2) return true; + for (Index_Size col{ this->start_x }; col < end_x_; ++col) { + this->substitutionLayer(matrix_, layer_, col, start_y, args_...); + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionLayer(matrix_, layer_, col, end_y_ - 2, args_...); + this->substitutionLayer(matrix_, layer_, col, end_y_ - 1, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + this->substitutionLayer(matrix_, layer_, start_x, row, args_...); + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionLayer(matrix_, layer_, end_x_ - 2, row, args_...); + this->substitutionLayer(matrix_, layer_, end_x_ - 1, row, std::forward(args_)...); + } + return true; + } + + //Array + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawArray(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Args_ && ... args_) const noexcept { + if (end_x_ < 2 || end_y_ < 2) return true; + for (Index_Size col{ this->start_x }; col < end_x_; ++col) { + this->substitutionArray(matrix_, col, start_y, max_x_, args_...); + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionArray(matrix_, col, end_y_ - 2, max_x_, args_...); + this->substitutionArray(matrix_, col, end_y_ - 1, max_x_, args_...); + } + for (Index_Size row{ this->start_y }; row < end_y_; ++row) { + this->substitutionArray(matrix_, start_x, row, max_x_, args_...); + if ((end_y_ - this->start_y) % 2 == 0) this->substitutionArray(matrix_, end_x_ - 2, row, max_x_, args_...); + this->substitutionArray(matrix_, end_x_ - 1, row, max_x_, std::forward(args_)...); + } + return true; + } + + public: + + + ///// 情報取得 ///// + + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointX() const noexcept { + return this->start_x; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointY() const noexcept { + return this->start_y; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getWidth() const noexcept { + return this->width; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getHeight() const noexcept { + return this->height; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Matrix_Int_ getValue() const noexcept { + return this->draw_value; + } + + + ///// 生成呼び出し ///// + + //STL + template + constexpr bool draw(Matrix_ && matrix_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //LayerSTL + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //Normal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //LayerNormal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //Array + template + constexpr bool drawArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_); + } + template + constexpr bool drawOperatorArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_, function_); + } + + + ///// 生成呼び出しファンクタ ///// + + template + constexpr bool operator()(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + return this->draw(std::forward(matrix_), std::forward(args_)...); + } + + + ///// ダンジョン行列生成 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& create(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->draw(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperator(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperator(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperatorArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperatorArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + + + ///// 消去 ///// + + //始点座標Xを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clearPointX() noexcept { + this->start_x = 0; + return *this; + } + //始点座標Yを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clearPointY() noexcept { + this->start_y = 0; + return *this; + } + //範囲の大きさ(X軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clearWidth() noexcept { + this->width = 0; + return *this; + } + //範囲の大きさ(Y軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clearHeight() noexcept { + this->height = 0; + return *this; + } + //塗り値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clearValue() noexcept { + const Matrix_Int_ new_draw_value{}; + this->draw_value = new_draw_value; + return *this; + } + //始点座標(X,Y)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clearPoint() noexcept { + this->clearPointX(); + this->clearPointY(); + return *this; + } + //描画範囲を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clearRange() noexcept { + this->clearPointX(); + this->clearPointY(); + this->clearWidth(); + this->clearHeight(); + return *this; + } + //全ての値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& clear() noexcept { + this->clearRange(); + this->clearValue(); + return *this; + } + + + ///// 代入 ///// + + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setPointX(const Index_Size end_x_) noexcept { + this->start_x = end_x_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setPointY(const Index_Size end_y_) noexcept { + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setWidth(const Index_Size width_) noexcept { + this->width = width_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setHeight(const Index_Size height_) noexcept { + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setValue(const Matrix_Int_ & draw_value_) noexcept { + this->draw_value = draw_value_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setPoint(const Index_Size point_) noexcept { + this->start_x = point_; + this->start_y = point_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setPoint(const Index_Size end_x_, const Index_Size end_y_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size length_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = length_; + this->height = length_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = width_; + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + BorderOdd& 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 *this; + } + + + ///// コンストラクタ ///// + + constexpr BorderOdd() noexcept = default; + constexpr explicit BorderOdd(const Matrix_Int_ & draw_value_) noexcept + :draw_value(draw_value_) {} + constexpr explicit BorderOdd(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 BorderOdd(const dtl::base::MatrixRange & matrix_range_, const Matrix_Int_ & draw_value_) noexcept + :start_x(matrix_range_.x), start_y(matrix_range_.y), + width(matrix_range_.w), height(matrix_range_.h), + draw_value(draw_value_) {} + constexpr explicit BorderOdd(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_) {} + constexpr explicit BorderOdd(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_, const Matrix_Int_ & draw_value_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_), + draw_value(draw_value_) {} + }; + } +} + +#endif //Included Dungeon Template Library \ No newline at end of file diff --git a/include/Shape/PointGrid.hpp b/include/Shape/PointGrid.hpp index 9ba62b9..c1d57fa 100644 --- a/include/Shape/PointGrid.hpp +++ b/include/Shape/PointGrid.hpp @@ -1,24 +1,4 @@ -/*####################################################################################### - 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_SHAPE_POINT_GRID_HPP -#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_POINT_GRID_HPP - -/*####################################################################################### - 日本語リファレンス (Reference-JP) - https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::PointGrid-(形状クラス)/ -#######################################################################################*/ - -/* Character Code : UTF-8 (BOM) */ -/* Bug Check : already checked */ -/* Android NDK Compile (Clang 5.0) : already checked */ - +/* #include #include #include @@ -84,3 +64,424 @@ namespace dtl { } #endif //Included Dungeon Template Library + +*/ + +/*####################################################################################### + 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_SHAPE_POINT_GRID_HPP +#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_POINT_GRID_HPP + +/*####################################################################################### + 日本語リファレンス (Reference-JP) + https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::PointGrid-(%E5%BD%A2%E7%8A%B6%E3%82%AF%E3%83%A9%E3%82%B9)/ +#######################################################################################*/ + +/* Character Code : UTF-8 (BOM) */ +/* Bug Check : already checked */ +/* Android NDK Compile (Clang 5.0) : already checked */ + +#include +#include +#include +#include +#include +#include + +namespace dtl { + inline namespace shape { + + //偶数マスを指定した数値で埋める + template + class PointGrid { + private: + + + ///// エイリアス ///// + + using Index_Size = std::size_t; + + + + ///// メンバ変数 ///// + + Index_Size start_x{}; + Index_Size start_y{}; + Index_Size width{}; + Index_Size height{}; + Matrix_Int_ draw_value{}; + + + ///// 代入処理 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_) const noexcept { + matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_&& matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_][end_x_])) matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_ * max_x_ + end_x_])) matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Function_ && function_) const noexcept { + if (function_(matrix_[end_y_][end_x_][layer_])) matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + + ///// 基本処理 ///// + + //STL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawSTL(Matrix_ && matrix_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; row += 2) + for (Index_Size col{ this->start_x }; col < matrix_[row].size(); col += 2) + this->substitutionSTL(matrix_, col, row, args_...); + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawWidthSTL(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; row += 2) + for (Index_Size col{ this->start_x }; col < matrix_[row].size() && col < end_x_; col += 2) + this->substitutionSTL(matrix_, col, row, args_...); + return true; + } + + //LayerSTL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; row += 2) + for (Index_Size col{ this->start_x }; col < matrix_[row].size(); col += 2) + this->substitutionLayer(matrix_, layer_, col, row, args_...); + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerWidthSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; row += 2) + for (Index_Size col{ this->start_x }; col < matrix_[row].size() && col < end_x_; col += 2) + this->substitutionLayer(matrix_, layer_, col, row, args_...); + return true; + } + + //Normal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawNormal(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; row += 2) + for (Index_Size col{ this->start_x }; col < end_x_; col += 2) + this->substitutionSTL(matrix_, col, row, args_...); + return true; + } + + //LayerNormal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerNormal(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; row += 2) + for (Index_Size col{ this->start_x }; col < end_x_; col += 2) + this->substitutionLayer(matrix_, layer_, col, row, args_...); + return true; + } + + //Array + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawArray(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; row += 2) + for (Index_Size col{ this->start_x }; col < end_x_; col += 2) + this->substitutionArray(matrix_, col, row, max_x_, args_...); + return true; + } + + public: + + + ///// 情報取得 ///// + + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointX() const noexcept { + return this->start_x; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointY() const noexcept { + return this->start_y; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getWidth() const noexcept { + return this->width; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getHeight() const noexcept { + return this->height; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Matrix_Int_ getValue() const noexcept { + return this->draw_value; + } + + + ///// 生成呼び出し ///// + + //STL + template + constexpr bool draw(Matrix_ && matrix_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //LayerSTL + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //Normal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //LayerNormal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //Array + template + constexpr bool drawArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_); + } + template + constexpr bool drawOperatorArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_, function_); + } + + + ///// 生成呼び出しファンクタ ///// + + template + constexpr bool operator()(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + return this->draw(std::forward(matrix_), std::forward(args_)...); + } + + + ///// ダンジョン行列生成 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& create(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->draw(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperator(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperator(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperatorArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperatorArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + + + ///// 消去 ///// + + //始点座標Xを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clearPointX() noexcept { + this->start_x = 0; + return *this; + } + //始点座標Yを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clearPointY() noexcept { + this->start_y = 0; + return *this; + } + //範囲の大きさ(X軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clearWidth() noexcept { + this->width = 0; + return *this; + } + //範囲の大きさ(Y軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clearHeight() noexcept { + this->height = 0; + return *this; + } + //塗り値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clearValue() noexcept { + const Matrix_Int_ new_draw_value{}; + this->draw_value = new_draw_value; + return *this; + } + //始点座標(X,Y)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clearPoint() noexcept { + this->clearPointX(); + this->clearPointY(); + return *this; + } + //描画範囲を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clearRange() noexcept { + this->clearPointX(); + this->clearPointY(); + this->clearWidth(); + this->clearHeight(); + return *this; + } + //全ての値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& clear() noexcept { + this->clearRange(); + this->clearValue(); + return *this; + } + + + ///// 代入 ///// + + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setPointX(const Index_Size end_x_) noexcept { + this->start_x = end_x_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setPointY(const Index_Size end_y_) noexcept { + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setWidth(const Index_Size width_) noexcept { + this->width = width_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setHeight(const Index_Size height_) noexcept { + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setValue(const Matrix_Int_ & draw_value_) noexcept { + this->draw_value = draw_value_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setPoint(const Index_Size point_) noexcept { + this->start_x = point_; + this->start_y = point_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setPoint(const Index_Size end_x_, const Index_Size end_y_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size length_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = length_; + this->height = length_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = width_; + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + PointGrid& 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 *this; + } + + + ///// コンストラクタ ///// + + constexpr PointGrid() noexcept = default; + constexpr explicit PointGrid(const Matrix_Int_ & draw_value_) noexcept + :draw_value(draw_value_) {} + constexpr explicit PointGrid(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 PointGrid(const dtl::base::MatrixRange & matrix_range_, const Matrix_Int_ & draw_value_) noexcept + :start_x(matrix_range_.x), start_y(matrix_range_.y), + width(matrix_range_.w), height(matrix_range_.h), + draw_value(draw_value_) {} + constexpr explicit PointGrid(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_) {} + constexpr explicit PointGrid(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_, const Matrix_Int_ & draw_value_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_), + draw_value(draw_value_) {} + }; + } +} + +#endif //Included Dungeon Template Library \ No newline at end of file diff --git a/include/Shape/Rect.hpp b/include/Shape/Rect.hpp index 8f1cd5f..5c384ec 100644 --- a/include/Shape/Rect.hpp +++ b/include/Shape/Rect.hpp @@ -1,24 +1,4 @@ -/*####################################################################################### - 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_SHAPE_RECT_HPP -#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_RECT_HPP - -/*####################################################################################### - 日本語リファレンス (Reference-JP) - https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::Rect-(形状クラス)/ -#######################################################################################*/ - -/* Character Code : UTF-8 (BOM) */ -/* Bug Check : already checked */ -/* Android NDK Compile (Clang 5.0) : already checked */ - +/* #include #include #include @@ -134,3 +114,424 @@ namespace dtl { } #endif //Included Dungeon Template Library + +*/ + +/*####################################################################################### + 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_SHAPE_RECT_HPP +#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_SHAPE_RECT_HPP + +/*####################################################################################### + 日本語リファレンス (Reference-JP) + https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::Rect-(%E5%BD%A2%E7%8A%B6%E3%82%AF%E3%83%A9%E3%82%B9)/ +#######################################################################################*/ + +/* Character Code : UTF-8 (BOM) */ +/* Bug Check : already checked */ +/* Android NDK Compile (Clang 5.0) : already checked */ + +#include +#include +#include +#include +#include +#include + +namespace dtl { + inline namespace shape { + + //マスを指定した数値で埋める + template + class Rect { + private: + + + ///// エイリアス ///// + + using Index_Size = std::size_t; + + + + ///// メンバ変数 ///// + + Index_Size start_x{}; + Index_Size start_y{}; + Index_Size width{}; + Index_Size height{}; + Matrix_Int_ draw_value{}; + + + ///// 代入処理 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_) const noexcept { + matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_&& matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_) const noexcept { + matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionSTL(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_][end_x_])) matrix_[end_y_][end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionArray(Matrix_&& matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Function_&& function_) const noexcept { + if (function_(matrix_[end_y_ * max_x_ + end_x_])) matrix_[end_y_ * max_x_ + end_x_] = this->draw_value; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + inline void substitutionLayer(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Function_ && function_) const noexcept { + if (function_(matrix_[end_y_][end_x_][layer_])) matrix_[end_y_][end_x_][layer_] = this->draw_value; + } + + + ///// 基本処理 ///// + + //STL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawSTL(Matrix_ && matrix_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; ++row) + for (Index_Size col{ this->start_x }; col < matrix_[row].size(); ++col) + this->substitutionSTL(matrix_, col, row, args_...); + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawWidthSTL(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; ++row) + for (Index_Size col{ this->start_x }; col < matrix_[row].size() && col < end_x_; ++col) + this->substitutionSTL(matrix_, col, row, args_...); + return true; + } + + //LayerSTL + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; ++row) + for (Index_Size col{ this->start_x }; col < matrix_[row].size(); ++col) + this->substitutionLayer(matrix_, layer_, col, row, args_...); + return true; + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerWidthSTL(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; ++row) + for (Index_Size col{ this->start_x }; col < matrix_[row].size() && col < end_x_; ++col) + this->substitutionLayer(matrix_, layer_, col, row, args_...); + return true; + } + + //Normal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawNormal(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; ++row) + for (Index_Size col{ this->start_x }; col < end_x_; ++col) + this->substitutionSTL(matrix_, col, row, args_...); + return true; + } + + //LayerNormal + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawLayerNormal(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; ++row) + for (Index_Size col{ this->start_x }; col < end_x_; ++col) + this->substitutionLayer(matrix_, layer_, col, row, args_...); + return true; + } + + //Array + template + DTL_VERSIONING_CPP14_CONSTEXPR + bool drawArray(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Args_ && ... args_) const noexcept { + for (Index_Size row{ this->start_y }; row < end_y_; ++row) + for (Index_Size col{ this->start_x }; col < end_x_; ++col) + this->substitutionArray(matrix_, col, row, max_x_, args_...); + return true; + } + + public: + + + ///// 情報取得 ///// + + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointX() const noexcept { + return this->start_x; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getPointY() const noexcept { + return this->start_y; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getWidth() const noexcept { + return this->width; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Index_Size getHeight() const noexcept { + return this->height; + } + DTL_VERSIONING_CPP17_NODISCARD + constexpr Matrix_Int_ getValue() const noexcept { + return this->draw_value; + } + + + ///// 生成呼び出し ///// + + //STL + template + constexpr bool draw(Matrix_ && matrix_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawSTL(std::forward(matrix_), (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawWidthSTL(matrix_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //LayerSTL + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, Function_ && function_) const noexcept { + return (this->width == 0) ? this->drawLayerSTL(std::forward(matrix_), layer_, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_) : this->drawLayerWidthSTL(matrix_, layer_, this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_); + } + + //Normal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawNormal(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //LayerNormal + template + constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height); + } + template + constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawLayerNormal(std::forward(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_); + } + + //Array + template + constexpr bool drawArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_); + } + template + constexpr bool drawOperatorArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept { + return this->drawArray(std::forward(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_, function_); + } + + + ///// 生成呼び出しファンクタ ///// + + template + constexpr bool operator()(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + return this->draw(std::forward(matrix_), std::forward(args_)...); + } + + + ///// ダンジョン行列生成 ///// + + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& create(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->draw(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperator(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperator(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + template + DTL_VERSIONING_CPP14_CONSTEXPR + Matrix_&& createOperatorArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept { + this->drawOperatorArray(matrix_, std::forward(args_)...); + return std::forward(matrix_); + } + + + ///// 消去 ///// + + //始点座標Xを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clearPointX() noexcept { + this->start_x = 0; + return *this; + } + //始点座標Yを初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clearPointY() noexcept { + this->start_y = 0; + return *this; + } + //範囲の大きさ(X軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clearWidth() noexcept { + this->width = 0; + return *this; + } + //範囲の大きさ(Y軸方向)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clearHeight() noexcept { + this->height = 0; + return *this; + } + //塗り値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clearValue() noexcept { + const Matrix_Int_ new_draw_value{}; + this->draw_value = new_draw_value; + return *this; + } + //始点座標(X,Y)を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clearPoint() noexcept { + this->clearPointX(); + this->clearPointY(); + return *this; + } + //描画範囲を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clearRange() noexcept { + this->clearPointX(); + this->clearPointY(); + this->clearWidth(); + this->clearHeight(); + return *this; + } + //全ての値を初期値に戻す + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& clear() noexcept { + this->clearRange(); + this->clearValue(); + return *this; + } + + + ///// 代入 ///// + + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setPointX(const Index_Size end_x_) noexcept { + this->start_x = end_x_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setPointY(const Index_Size end_y_) noexcept { + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setWidth(const Index_Size width_) noexcept { + this->width = width_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setHeight(const Index_Size height_) noexcept { + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setValue(const Matrix_Int_ & draw_value_) noexcept { + this->draw_value = draw_value_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setPoint(const Index_Size point_) noexcept { + this->start_x = point_; + this->start_y = point_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setPoint(const Index_Size end_x_, const Index_Size end_y_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size length_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = length_; + this->height = length_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& setRange(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept { + this->start_x = end_x_; + this->start_y = end_y_; + this->width = width_; + this->height = height_; + return *this; + } + DTL_VERSIONING_CPP14_CONSTEXPR + Rect& 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 *this; + } + + + ///// コンストラクタ ///// + + constexpr Rect() noexcept = default; + constexpr explicit Rect(const Matrix_Int_ & draw_value_) noexcept + :draw_value(draw_value_) {} + constexpr explicit Rect(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 Rect(const dtl::base::MatrixRange & matrix_range_, const Matrix_Int_ & draw_value_) noexcept + :start_x(matrix_range_.x), start_y(matrix_range_.y), + width(matrix_range_.w), height(matrix_range_.h), + draw_value(draw_value_) {} + constexpr explicit Rect(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_) {} + constexpr explicit Rect(const Index_Size end_x_, const Index_Size end_y_, const Index_Size width_, const Index_Size height_, const Matrix_Int_ & draw_value_) noexcept + :start_x(end_x_), start_y(end_y_), + width(width_), height(height_), + draw_value(draw_value_) {} + }; + } +} + +#endif //Included Dungeon Template Library \ No newline at end of file