File: testrect.cpp

package info (click to toggle)
fcitx5 5.1.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,356 kB
  • sloc: cpp: 75,670; sh: 1,770; xml: 1,545; python: 1,052; ansic: 71; makefile: 11
file content (78 lines) | stat: -rw-r--r-- 2,072 bytes parent folder | download | duplicates (5)
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
73
74
75
76
77
78
/*
 * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 */
#include "fcitx-utils/log.h"
#include "fcitx-utils/rect.h"

using namespace fcitx;

int main() {
    Rect rect;
    FCITX_ASSERT(rect.width() == 0);
    FCITX_ASSERT(rect.height() == 0);
    FCITX_ASSERT(rect.top() == 0);
    FCITX_ASSERT(rect.left() == 0);

    rect.setPosition(-1, -2).setSize(10, 20);

    FCITX_ASSERT(rect.width() == 10);
    FCITX_ASSERT(rect.height() == 20);
    FCITX_ASSERT(rect.left() == -1);
    FCITX_ASSERT(rect.top() == -2);
    FCITX_ASSERT(rect.right() == 9);
    FCITX_ASSERT(rect.bottom() == 18);

    {
        Rect other;
        other.setSize(5, 5);
        FCITX_ASSERT(rect.intersected(other) == other);
        FCITX_ASSERT(other.intersected(rect) == other);
    }

    {
        Rect other;
        other.setSize(100, 100);
        Rect expect(0, 0, 9, 18);
        FCITX_ASSERT(rect.intersected(other) == expect);
        FCITX_ASSERT(other.intersected(rect) == expect);
    }

    {
        Rect other;
        other.setSize(100, 100);
        other = other.translated(-100, -100);
        Rect expect(-1, -2, 0, 0);
        FCITX_ASSERT(rect.intersected(other) == expect);
        FCITX_ASSERT(other.intersected(rect) == expect);
    }

    {
        Rect other;
        other.setSize(100, 100);
        other = other.translated(0, -100);
        Rect expect(0, -2, 9, 0);
        FCITX_ASSERT(rect.intersected(other) == expect)
            << rect.intersected(other);
        FCITX_ASSERT(other.intersected(rect) == expect);
    }

    {
        Rect other;
        other.setSize(3, 100);
        Rect expect(0, 0, 3, 18);
        FCITX_ASSERT(rect.intersected(other) == expect)
            << rect.intersected(other);
        FCITX_ASSERT(other.intersected(rect) == expect);
    }

    FCITX_ASSERT(rect.contains(0, 0));
    FCITX_ASSERT(rect.contains(-1, -2));
    FCITX_ASSERT(rect.contains(9, -2));
    FCITX_ASSERT(!rect.contains(10, -2));
    FCITX_ASSERT(rect.contains(8, -2));

    return 0;
}