Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / test / distance_constraint_test.cpp
1 #include <rive/file.hpp>
2 #include <rive/constraints/distance_constraint.hpp>
3 #include <rive/node.hpp>
4 #include <rive/math/vec2d.hpp>
5 #include <rive/shapes/shape.hpp>
6 #include "rive_file_reader.hpp"
7 #include "rive_testing.hpp"
8 #include <cstdio>
9
10 TEST_CASE("distance constraints moves items as expected", "[file]") {
11     auto file = ReadRiveFile("../../test/assets/distance_constraint.riv");
12
13     auto artboard = file->artboard();
14
15     REQUIRE(artboard->find<rive::Shape>("A") != nullptr);
16     auto a = artboard->find<rive::Shape>("A");
17
18     REQUIRE(artboard->find<rive::Shape>("B") != nullptr);
19     auto b = artboard->find<rive::Shape>("B");
20
21     REQUIRE(a->constraints().size() == 1);
22     REQUIRE(a->constraints()[0]->is<rive::DistanceConstraint>());
23
24     auto distanceConstraint = a->constraints()[0]->as<rive::DistanceConstraint>();
25     REQUIRE(distanceConstraint->modeValue() == 1);
26
27     b->x(259.31f);
28     b->y(137.87f);
29     artboard->advance(0.0f);
30
31     rive::Vec2D at = a->worldTranslation();
32     rive::Vec2D expectedTranslation(259.2808837890625f, 62.87000274658203f);
33     REQUIRE(rive::Vec2D::distance(at, expectedTranslation) < 0.001f);
34 }