Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / test / hittest_test.cpp
1 /*
2  * Copyright 2022 Rive
3  */
4
5 #include <rive/math/aabb.hpp>
6 #include <rive/math/hit_test.hpp>
7
8 #include <catch.hpp>
9 #include <cstdio>
10
11 using namespace rive;
12
13 TEST_CASE("hittest-basics", "[hittest]") {
14     HitTester tester;
15     tester.reset({10, 10, 12, 12});
16     tester.move({0, 0});
17     tester.line({20, 0});
18     tester.line({20, 20});
19     tester.line({0, 20});
20     tester.close();
21     REQUIRE(tester.test());
22
23     IAABB area = {81, 156, 84, 159};
24
25     Vec2D pts[] = {
26         {29.9785, 32.5261},
27         {231.102, 32.5261},
28         {231.102, 269.898},
29         {29.9785, 269.898},
30     };
31     tester.reset(area);
32
33     tester.move(pts[0]);
34     for (int i = 1; i < 4; ++i) {
35         tester.line(pts[i]);
36     }
37     tester.close();
38     REQUIRE(tester.test());
39 }
40
41 TEST_CASE("hittest-mesh", "[hittest]") {
42
43     const IAABB area{10, 10, 12, 12};
44
45     Vec2D verts[] = {
46         {0, 0},
47         {20, 10},
48         {0, 20},
49     };
50     uint16_t indices[] = {
51         0,
52         1,
53         2,
54     };
55     REQUIRE(HitTester::testMesh(area, Span(verts, 3), Span(indices, 3)));
56 }