summaryrefslogtreecommitdiffhomepage
path: root/test/hole.cpp
blob: 7ccc86c353850e42df5d88bfa56bb7ef777c4048 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "app.hpp"
#include "src/hole.hpp"

namespace floormat {
namespace {

using bbox = CutResult<Int>::bbox;

auto cut(bbox rect, bbox hole, Vector2i offset)
{
    auto rectʹ = bbox { rect.position + offset, rect.bbox_size };
    auto holeʹ = bbox { hole.position + offset, hole.bbox_size };
    return CutResult<Int>::cut(rectʹ, holeʹ).size;
}

void test1(Vector2i offset)
{
    constexpr auto rect = bbox{{}, {50, 50}};
#if 1
    fm_assert_not_equal(0, cut(rect, {{ 49,   0}, {50, 50}}, offset));
    fm_assert_not_equal(0, cut(rect, {{  0,  49}, {50, 50}}, offset));
    fm_assert_not_equal(0, cut(rect, {{ 49,  49}, {50, 50}}, offset));
#endif
#if 1
    fm_assert_not_equal(0, cut(rect, {{-49,   0}, {50, 50}}, offset));
    fm_assert_not_equal(0, cut(rect, {{  0, -49}, {50, 50}}, offset));
    fm_assert_not_equal(0, cut(rect, {{ 49, -49}, {50, 50}}, offset));
#endif
#if 1
    fm_assert_equal(0, cut(rect, {{ 0,  0}, {50, 50}}, offset));
    fm_assert_equal(1, cut(rect, {{ 0,  0}, {49, 50}}, offset));
    fm_assert_equal(1, cut(rect, {{ 1,  0}, {50, 50}}, offset));
    fm_assert_equal(1, cut(rect, {{50,  0}, {50, 50}}, offset));
    fm_assert_equal(1, cut(rect, {{ 0, 50}, {50, 50}}, offset));
    fm_assert_equal(1, cut(rect, {{50, 50}, {50, 50}}, offset));
#endif
#if 1
    fm_assert_equal(0, cut(rect, {{ 9,  9}, {70, 70}}, offset));
    fm_assert_equal(2, cut(rect, {{11, 11}, {70, 70}}, offset));
    fm_assert_equal(1, cut(rect, {{10, 11}, {70, 70}}, offset));
    fm_assert_equal(0, cut(rect, {{10, 10}, {70, 70}}, offset));
    fm_assert_equal(2, cut(rect, {{20, 20}, {70, 70}}, offset));
#endif
#if 1
    fm_assert_equal(1, cut(rect, {{ 1,  0}, {50, 50}}, offset));
    fm_assert_equal(1, cut(rect, {{ 0,  1}, {50, 50}}, offset));
    fm_assert_equal(2, cut(rect, {{ 1,  1}, {50, 50}}, offset));
    fm_assert_equal(2, cut(rect, {{49, 49}, {50, 50}}, offset));
    fm_assert_equal(1, cut(rect, {{50, 50}, {50, 50}}, offset));
#endif
#if 1
    // todo! coverage
#endif
}

} // namespace

void Test::test_hole()
{
    constexpr Vector2i offsets[] = {
        {  0,     0},
        { 110,  105},
        {  15,  110},
        {- 15, -110},
        {-110,  -15},
    };

    for (auto offset : offsets)
        test1(offset);
}

} // namespace floormat