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"
10 TEST_CASE("distance constraints moves items as expected", "[file]") {
11 auto file = ReadRiveFile("../../test/assets/distance_constraint.riv");
13 auto artboard = file->artboard();
15 REQUIRE(artboard->find<rive::Shape>("A") != nullptr);
16 auto a = artboard->find<rive::Shape>("A");
18 REQUIRE(artboard->find<rive::Shape>("B") != nullptr);
19 auto b = artboard->find<rive::Shape>("B");
21 REQUIRE(a->constraints().size() == 1);
22 REQUIRE(a->constraints()[0]->is<rive::DistanceConstraint>());
24 auto distanceConstraint = a->constraints()[0]->as<rive::DistanceConstraint>();
25 REQUIRE(distanceConstraint->modeValue() == 1);
29 artboard->advance(0.0f);
31 rive::Vec2D at = a->worldTranslation();
32 rive::Vec2D expectedTranslation(259.2808837890625f, 62.87000274658203f);
33 REQUIRE(rive::Vec2D::distance(at, expectedTranslation) < 0.001f);