Euphoria
table_bool.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "core/table.h"
4 
5 #include "base/rgb.h"
6 #include "core/image.h"
7 #include "base/lrud.h"
8 #include "base/enumtostring.h"
9 
10 #include <functional>
11 #include <optional>
12 
13 namespace eu::core
14 {
16 
18  // Setup
19 
20  enum class BorderSetupRule
21  {
24  random,
25  };
26 
27  void
29  (
30  BoolTable* world,
31  Lrud<BorderSetupRule> border_control,
32  std::function<bool()> rng
33  );
34 
36  // Smooth step
37 
38  enum class OutsideRule
39  {
41  };
42 
43  /* Count walls according to von Neumann neighborhood 'manhattan distance' rule.
44  */
45  int
47  (
48  const BoolTable& world,
49  Lrud<OutsideRule> outside_rule,
50  int cx,
51  int cy,
52  int step,
53  bool include_self
54  );
55 
56 
57  /* Count walls according to extended von Neumann neighborhood 'plus' rule.
58  */
59  int
61  (
62  const BoolTable& world,
63  Lrud<OutsideRule> outside_rule,
64  int cx,
65  int cy,
66  int step,
67  bool include_self
68  );
69 
70 
71  /* Count walls according to Moore neighborhood 'box' rule.
72  */
73  int
75  (
76  const BoolTable& world,
77  Lrud<OutsideRule> outside_rule,
78  int cx,
79  int cy,
80  int step,
81  bool include_self
82  );
83 
85  {
86  // von Neumann
87  manhattan,
88 
89  // extended vonNeumann
90  plus,
91 
92  // Moore
93  box
94  };
95 
96 
97  struct WallCounter
98  {
99  const BoolTable& world;
101  int cx;
102  int cy;
103 
105  (
106  const BoolTable& w,
108  int x,
109  int y
110  );
111 
112  [[nodiscard]] int
113  count(int step, bool include_self, NeighborhoodAlgorithm algorithm) const;
114  };
115 
116 
117  void
119  (
120  BoolTable* world,
121  Lrud<OutsideRule> outside_rule,
122  // return if occupied or not, or nullopt to keep old value
123  std::function<std::optional<bool>(bool, const WallCounter&)> smooth_function
124  );
125 
126 
128  // FloodFill
129 
130  std::vector<vec2i>
131  find_empty_blocks(const BoolTable& world);
132 
133  std::vector<vec2i>
135  (
136  const BoolTable& world,
137  const vec2i& start,
138  bool allow_diagonals
139  );
140 
141  std::vector<std::vector<vec2i>>
142  find_empty_regions(const BoolTable& world, bool allow_diagonals);
143 
145  // Rendering
146 
148  {
150 
151  explicit BorderSettings(const Rgbai& c);
152  };
153 
154  Image
155  draw
156  (
157  const BoolTable& world,
158  Rgbai wall_color,
159  Rgbai space_color,
160  int scale,
161  // if nullopt, no border
162  std::optional<BorderSettings> border
163  );
164 }
void make_smoother(BoolTable *world, Lrud< OutsideRule > outside_rule, std::function< std::optional< bool >(bool, const WallCounter &)> smooth_function)
Definition: table_bool.cc:327
int count_walls_manhattan(const BoolTable &world, Lrud< OutsideRule > outside_rule, int cx, int cy, int step, bool include_self)
Definition: table_bool.cc:146
NeighborhoodAlgorithm
Definition: table_bool.h:85
void set_white_noise(BoolTable *world, Lrud< BorderSetupRule > border_control, std::function< bool()> rng)
Definition: table_bool.cc:11
Table< bool > BoolTable
Definition: table_bool.h:15
int count_walls_box(const BoolTable &world, Lrud< OutsideRule > outside_rule, int cx, int cy, int step, bool include_self)
Definition: table_bool.cc:222
std::vector< vec2i > find_flood_fill_items(const BoolTable &world, const vec2i &start, bool allow_diagonals)
Definition: table_bool.cc:366
std::vector< vec2i > find_empty_blocks(const BoolTable &world)
Definition: table_bool.cc:346
int count_walls_plus(const BoolTable &world, Lrud< OutsideRule > outside_rule, int cx, int cy, int step, bool include_self)
Definition: table_bool.cc:183
Image draw(const BoolTable &world, Rgbai wall_color, Rgbai space_color, int scale, std::optional< BorderSettings > border)
Definition: table_bool.cc:459
BorderSetupRule
Definition: table_bool.h:21
std::vector< std::vector< vec2i > > find_empty_regions(const BoolTable &world, bool allow_diagonals)
Definition: table_bool.cc:422
Definition: rgb.h:45
BorderSettings(const Rgbai &c)
Definition: table_bool.cc:451
const BoolTable & world
Definition: table_bool.h:99
WallCounter(const BoolTable &w, Lrud< core::OutsideRule > r, int x, int y)
Definition: table_bool.cc:255
int count(int step, bool include_self, NeighborhoodAlgorithm algorithm) const
Definition: table_bool.cc:306
Lrud< core::OutsideRule > outside_rule
Definition: table_bool.h:100
Definition: vec2.h:72