Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / test / raw_path_test.cpp
1 /*
2  * Copyright 2022 Rive
3  */
4
5 #include <rive/math/aabb.hpp>
6 #include <rive/math/raw_path.hpp>
7 #include "no_op_renderer.hpp"
8
9 #include <catch.hpp>
10 #include <cstdio>
11
12 using namespace rive;
13
14 TEST_CASE("rawpath-basics", "[rawpath]") {
15     RawPath path;
16
17     REQUIRE(path.empty());
18     REQUIRE(path.bounds() == AABB{0, 0, 0, 0});
19
20     path.move({1, 2});
21     REQUIRE(!path.empty());
22     REQUIRE(path.bounds() == AABB{1, 2, 1, 2});
23
24     path = RawPath();
25     REQUIRE(path.empty());
26     REQUIRE(path.bounds() == AABB{0, 0, 0, 0});
27
28     path.move({1, -2});
29     path.line({3, 4});
30     path.line({-1, 5});
31     REQUIRE(!path.empty());
32     REQUIRE(path.bounds() == AABB{-1, -2, 3, 5});
33 }
34
35 TEST_CASE("rawpath-add-helpers", "[rawpath]") {
36     RawPath path;
37
38     path.addRect({1, 1, 5, 6});
39     REQUIRE(!path.empty());
40     REQUIRE(path.bounds() == AABB{1, 1, 5, 6});
41     REQUIRE(path.points().size() == 4);
42     REQUIRE(path.verbs().size() == 5); // move, line, line, line, close
43
44     path = RawPath();
45     path.addOval({0, 0, 3, 6});
46     REQUIRE(!path.empty());
47     REQUIRE(path.bounds() == AABB{0, 0, 3, 6});
48     REQUIRE(path.points().size() == 13);
49     REQUIRE(path.verbs().size() == 6); // move, cubic, cubic, cubic, cubic, close
50
51     const Vec2D pts[] = {
52         {1, 2},
53         {4, 5},
54         {3, 2},
55         {100, -100},
56     };
57     constexpr auto size = sizeof(pts) / sizeof(pts[0]);
58
59     for (auto isClosed : {false, true}) {
60         path = RawPath();
61         path.addPoly({pts, size}, isClosed);
62         REQUIRE(path.bounds() == AABB{1, -100, 100, 5});
63         REQUIRE(path.points().size() == size);
64         REQUIRE(path.verbs().size() == size + isClosed);
65
66         for (size_t i = 0; i < size; ++i) {
67             REQUIRE(path.points()[i] == pts[i]);
68         }
69         REQUIRE(path.verbs()[0] == PathVerb::move);
70         for (size_t i = 1; i < size; ++i) {
71             REQUIRE(path.verbs()[i] == PathVerb::line);
72         }
73         if (isClosed) {
74             REQUIRE(path.verbs()[size] == PathVerb::close);
75         }
76     }
77 }