Skip to content

dtl::XX::YY::draw

Kasugaccho edited this page Aug 10, 2019 · 4 revisions

Select Language ๐ŸŒ

English ๐Ÿ‡ฌ๐Ÿ‡ง / ๆ—ฅๆœฌ่ชž ๐Ÿ‡ฏ๐Ÿ‡ต


// (1) STL
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_) const noexcept;

// (2) LayerSTL
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_, const std::size_t layer_) const noexcept;

// (3) Normal
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_, const std::size_t max_x_, const std::size_t max_y_) const noexcept;

// (4) LayerNormal
template<typename Matrix_>
constexpr bool draw(Matrix_&& matrix_, const std::size_t layer_, const std::size_t max_x_, const std::size_t max_y_) const noexcept;

Overview

Draw on Matrix.

Return Value

The return type is bool.

Return Value Description
false Drawing failed.
true Drawing was successful.

Exception

Don't throw exception.

Computational Complexity

O(n^2).

  • Some are O(n).

Example

(1) STL

#include <DTL.hpp>
#include <cstddef>
#include <cstdint>
#include <array>

int main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 16 };
	constexpr std::size_t height{ 8 };

	std::array<std::array<shape_t, width>, height> matrix{ {} };

	dtl::shape::Border<shape_t>(1).draw(matrix);

	dtl::console::OutputNumber<shape_t>(",").draw(matrix);
	dtl::console::OutputString<shape_t>("//", "##").draw(matrix);

	return 0;
}

Output

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
################################
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
################################

(2) LayerSTL

#include <DTL.hpp>
#include <cstddef>
#include <cstdint>
#include <array>

int main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 16 };
	constexpr std::size_t height{ 8 };
	constexpr std::size_t layer_max{ 2 };
	constexpr std::size_t draw_layer{ 1 };

	std::array<std::array<std::array<shape_t, layer_max>, width>, height> matrix{ {} };

	dtl::shape::Border<shape_t>(1).draw(matrix, draw_layer);

	dtl::console::OutputNumber<shape_t>(",").draw(matrix, draw_layer);
	dtl::console::OutputString<shape_t>("//", "##").draw(matrix, draw_layer);

	return 0;
}

Output

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
################################
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
################################

(3) Normal

#include <DTL.hpp>
#include <cstddef>
#include <cstdint>

int main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 16 };
	constexpr std::size_t height{ 8 };

	shape_t matrix[height][width]{};

	dtl::shape::Border<shape_t>(1).draw(matrix, width, height);

	dtl::console::OutputNumber<shape_t>(",").draw(matrix, width, height);
	dtl::console::OutputString<shape_t>("//", "##").draw(matrix, width, height);

	return 0;
}

Output

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
################################
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
################################

(4) LayerNormal

#include <DTL.hpp>
#include <cstddef>
#include <cstdint>

int main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 16 };
	constexpr std::size_t height{ 8 };
	constexpr std::size_t layer_max{ 2 };
	constexpr std::size_t draw_layer{ 1 };

	shape_t matrix[height][width][layer_max]{};

	dtl::shape::Border<shape_t>(1).draw(matrix, draw_layer, width, height);

	dtl::console::OutputNumber<shape_t>(",").draw(matrix, draw_layer, width, height);
	dtl::console::OutputString<shape_t>("//", "##").draw(matrix, draw_layer, width, height);

	return 0;
}

Output

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
################################
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
##////////////////////////////##
################################
Clone this wiki locally