Adding artboard clip test. Adds a test for the issue fixed in #4281 (the duolingo artboard clipping issue). Diffs= 0ffa502c4 Adding artboard clip test. (#4283)
diff --git a/.rive_head b/.rive_head index c815147..ec72cc2 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -99c5590bcfe896005fa805bb3aba8b817ce22b4b +0ffa502c470709177f941dca669e3a9cfb9612bf
diff --git a/include/rive/artboard.hpp b/include/rive/artboard.hpp index e788a07..0c27741 100644 --- a/include/rive/artboard.hpp +++ b/include/rive/artboard.hpp
@@ -98,9 +98,10 @@ }; void draw(Renderer* renderer, DrawOption = DrawOption::kNormal); - // TODO: can we remove these getters? Who is calling them? +#ifdef TESTING RenderPath* clipPath() const { return m_ClipPath.get(); } RenderPath* backgroundPath() const { return m_BackgroundPath.get(); } +#endif const std::vector<Core*>& objects() const { return m_Objects; } const std::vector<NestedArtboard*> nestedArtboards() const { return m_NestedArtboards; }
diff --git a/test/assets/artboardclipping.riv b/test/assets/artboardclipping.riv new file mode 100644 index 0000000..16768b8 --- /dev/null +++ b/test/assets/artboardclipping.riv Binary files differ
diff --git a/test/clip_test.cpp b/test/clip_test.cpp index f0e4331..fac5a6d 100644 --- a/test/clip_test.cpp +++ b/test/clip_test.cpp
@@ -26,3 +26,65 @@ rive::NoOpRenderer renderer; file->artboard()->draw(&renderer); } + +class ClipTestRenderPath : public rive::RenderPath +{ +public: + rive::RawPath rawPath; + ClipTestRenderPath(rive::RawPath& path) : rawPath(path) {} + + void reset() override {} + + void fillRule(rive::FillRule value) override {} + void addPath(rive::CommandPath* path, const rive::Mat2D& transform) override {} + void addRenderPath(rive::RenderPath* path, const rive::Mat2D& transform) override {} + + void moveTo(float x, float y) override {} + void lineTo(float x, float y) override {} + void cubicTo(float ox, float oy, float ix, float iy, float x, float y) override {} + void close() override {} +}; + +class ClippingFactory : public rive::NoOpFactory +{ + std::unique_ptr<rive::RenderPath> makeRenderPath(rive::RawPath& rawPath, + rive::FillRule) override + { + return std::make_unique<ClipTestRenderPath>(rawPath); + } +}; + +TEST_CASE("artboard is clipped correctly", "[clipping]") +{ + ClippingFactory factory; + auto file = ReadRiveFile("../../test/assets/artboardclipping.riv", &factory); + + auto artboard = file->artboard("Center"); + REQUIRE(artboard != nullptr); + artboard->updateComponents(); + REQUIRE(artboard->originX() == 0.5); + REQUIRE(artboard->originY() == 0.5); + { + auto clipPath = reinterpret_cast<ClipTestRenderPath*>(artboard->clipPath()); + auto points = clipPath->rawPath.points(); + REQUIRE(points.size() == 4); + + REQUIRE(points[0] == rive::Vec2D(0.0f, 0.0f)); + REQUIRE(points[1] == rive::Vec2D(500.0f, 0.0f)); + REQUIRE(points[2] == rive::Vec2D(500.0f, 500.0f)); + REQUIRE(points[3] == rive::Vec2D(0.0f, 500.0f)); + } + // Now disable framing the origin so that the points are in origin space. + artboard->frameOrigin(false); + artboard->updateComponents(); + { + auto clipPath = reinterpret_cast<ClipTestRenderPath*>(artboard->clipPath()); + auto points = clipPath->rawPath.points(); + REQUIRE(points.size() == 4); + + REQUIRE(points[0] == rive::Vec2D(-250.0f, -250.0f)); + REQUIRE(points[1] == rive::Vec2D(250.0f, -250.0f)); + REQUIRE(points[2] == rive::Vec2D(250.0f, 250.0f)); + REQUIRE(points[3] == rive::Vec2D(-250.0f, 250.0f)); + } +}