aboutsummaryrefslogtreecommitdiff
path: root/src/box_indicator.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-12-10 15:39:39 +0100
committerAdrian Kummerlaender2016-12-10 15:39:39 +0100
commitefe0aeed5f1854628df8bace645a072d569fe7b9 (patch)
tree290402d8cb55e6599cac6b452ef04c2ce26d485b /src/box_indicator.h
parent839e1335d9f58cd4b681163e14299efe1eec5eb1 (diff)
downloadtermlife-efe0aeed5f1854628df8bace645a072d569fe7b9.tar
termlife-efe0aeed5f1854628df8bace645a072d569fe7b9.tar.gz
termlife-efe0aeed5f1854628df8bace645a072d569fe7b9.tar.bz2
termlife-efe0aeed5f1854628df8bace645a072d569fe7b9.tar.lz
termlife-efe0aeed5f1854628df8bace645a072d569fe7b9.tar.xz
termlife-efe0aeed5f1854628df8bace645a072d569fe7b9.tar.zst
termlife-efe0aeed5f1854628df8bace645a072d569fe7b9.zip
Introduce `BoxIndicator` and `BoxTraverser` helper classes
`BoxIndicator` implements an indicator function for the world area. Together with `BoxTraverser` it is used to simplifiy action validation and area traversion.
Diffstat (limited to 'src/box_indicator.h')
-rw-r--r--src/box_indicator.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/box_indicator.h b/src/box_indicator.h
new file mode 100644
index 0000000..db750e4
--- /dev/null
+++ b/src/box_indicator.h
@@ -0,0 +1,40 @@
+#ifndef LIFE_SRC_BOX_INDICATOR_
+#define LIFE_SRC_BOX_INDICATOR_
+
+namespace life {
+namespace util {
+
+class BoxIndicator {
+ public:
+ BoxIndicator(
+ const std::size_t offset_x,
+ const std::size_t offset_y,
+ const std::size_t size_x,
+ const std::size_t size_y):
+ a_x_{offset_x},
+ a_y_{offset_y},
+ b_x_{a_x_ + size_x},
+ b_y_{a_y_ + size_y} { }
+
+ BoxIndicator(const std::size_t size_x, const std::size_t size_y):
+ BoxIndicator(0, 0, size_x, size_y) { }
+
+ bool operator()(const std::size_t x, const std::size_t y) const {
+ return x >= this->a_x_
+ && x < this->b_x_
+ && y >= this->a_y_
+ && y < this->b_y_;
+ }
+
+ protected:
+ const std::size_t a_x_;
+ const std::size_t a_y_;
+ const std::size_t b_x_;
+ const std::size_t b_y_;
+
+};
+
+}
+}
+
+#endif // LIFE_SRC_BOX_INDICATOR_