summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-26 10:19:37 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-26 11:12:07 +0200
commit0978386d9938a7d3f205ec4419bd5213d5f0a579 (patch)
treeb949cf33108e9d55ae32d0a50a404b80a9f1847f
parent67bec06c00b10f57d0d4701a357f29efe7520e3b (diff)
w a
-rw-r--r--src/hole.cpp16
-rw-r--r--test/hole.cpp27
2 files changed, 22 insertions, 21 deletions
diff --git a/src/hole.cpp b/src/hole.cpp
index aba4e7f3..5551b780 100644
--- a/src/hole.cpp
+++ b/src/hole.cpp
@@ -112,12 +112,10 @@ constexpr element make_element(uint8_t s)
}
fm_assert(false);
}
-constexpr auto elements = map(make_element, iota_array<uint8_t, 16>);
-static_assert(array_size(elements) == 16);
-} // namespace
+constexpr auto elements = map(make_element, iota_array<uint8_t, 16>);
-constexpr cut_rectangle_result cut_rectangle(bbox input, bbox hole)
+constexpr cut_rectangle_result cut_rectangleʹ(bbox input, bbox hole)
{
auto ihalf = Vector2i{input.bbox_size/2};
auto r0 = input.position - ihalf;
@@ -167,10 +165,14 @@ constexpr cut_rectangle_result cut_rectangle(bbox input, bbox hole)
res.array[i] = { {x0, y0}, {x1, y1}, };
}
- fm_assert(false);
- std::unreachable();
+ return res;
+}
+
+} // namespace
- //return -1;
+cut_rectangle_result cut_rectangle(bbox input, bbox hole)
+{
+ return cut_rectangleʹ(input, hole);
}
} // namespace floormat
diff --git a/test/hole.cpp b/test/hole.cpp
index 4ad3c21a..6cc39af1 100644
--- a/test/hole.cpp
+++ b/test/hole.cpp
@@ -1,7 +1,7 @@
#include "app.hpp"
#include "src/hole.hpp"
-namespace floormat::Hole {
+namespace floormat {
namespace {
using bbox = cut_rectangle_result::bbox;
@@ -10,7 +10,8 @@ template<Int x, Int y>
void test1()
{
static constexpr auto vec = Vector2i{x, y};
- constexpr auto rect = bbox{{}, {50, 50}};
+ static constexpr auto rect = bbox{{}, {50, 50}};
+
constexpr auto cutʹ = [](bbox rect, bbox hole) {
auto rectʹ = bbox { rect.position + vec, rect.bbox_size };
auto holeʹ = bbox { hole.position + vec, hole.bbox_size };
@@ -32,13 +33,13 @@ void test1()
fm_assert_equal(0, cutʹ(rect, {{50, 50}, {50, 50}}));
#endif
#if 1
- fm_assert_equal(9, cutʹ(rect, {{ 9, 9}, {70, 70}}));
- fm_assert_equal(9, cutʹ(rect, {{10, 10}, {70, 70}}));
+ fm_assert_equal(1, cutʹ(rect, {{ 9, 9}, {70, 70}}));
+ fm_assert_equal(1, cutʹ(rect, {{10, 10}, {70, 70}}));
#endif
#if 1
- fm_assert_equal(12, cutʹ(rect, {{1, 0}, {50, 50}}));
- fm_assert_equal(12, cutʹ(rect, {{0, 1}, {50, 50}}));
- fm_assert_equal(11, cutʹ(rect, {{1, 1}, {50, 50}}));
+ fm_assert_equal(1, cutʹ(rect, {{1, 0}, {50, 50}}));
+ fm_assert_equal(1, cutʹ(rect, {{0, 1}, {50, 50}}));
+ fm_assert_equal(2, cutʹ(rect, {{1, 1}, {50, 50}}));
#endif
#if 1
// todo! coverage
@@ -46,16 +47,14 @@ void test1()
}
} // namespace
-} // namespace floormat::Hole
-namespace floormat {
void Test::test_hole()
{
- Hole::test1< 0, 0 >();
- Hole::test1< 110, 105 >();
- Hole::test1< 15, 110 >();
- Hole::test1< - 15, -110 >();
- Hole::test1< -110, -15 >();
+ test1< 0, 0 >();
+ test1< 110, 105 >();
+ test1< 15, 110 >();
+ test1< - 15, -110 >();
+ test1< -110, -15 >();
}
} // namespace floormat