Adding a test for the ellipse path.

This commit is contained in:
Luigi Rosso
2020-07-22 18:44:23 -07:00
parent 96328c68cd
commit b28d43f926

View File

@@ -5,7 +5,9 @@
#include "no_op_renderer.hpp"
#include "node.hpp"
#include "shapes/rectangle.hpp"
#include "shapes/ellipse.hpp"
#include "shapes/shape.hpp"
#include "math/circle_constant.hpp"
#include <cstdio>
TEST_CASE("rectangle path builds expected commands", "[path]")
@@ -98,5 +100,87 @@ TEST_CASE("rounded rectangle path builds expected commands", "[path]")
REQUIRE(path->commands[9].command == rive::NoOpPathCommandType::Close);
delete artboard;
}
TEST_CASE("ellipse path builds expected commands", "[path]")
{
rive::Artboard* artboard = new rive::Artboard();
rive::Ellipse* ellipse = new rive::Ellipse();
ellipse->x(0.0f);
ellipse->y(0.0f);
ellipse->width(100.0f);
ellipse->height(200.0f);
artboard->addObject(artboard);
artboard->addObject(ellipse);
artboard->initialize();
artboard->advance(0.0f);
REQUIRE(ellipse->renderPath() != nullptr);
auto path =
reinterpret_cast<rive::NoOpRenderPath*>(ellipse->renderPath());
// reset
// moveTo
// cubic - for 1st corner
// lineTo, cubicTo for 2nd corner
// lineTo, cubicTo for 3rd corner
// lineTo, cubicTo for 4th corner
// close
REQUIRE(path->commands.size() == 7);
// Init
REQUIRE(path->commands[0].command == rive::NoOpPathCommandType::Reset);
REQUIRE(path->commands[1].command == rive::NoOpPathCommandType::MoveTo);
REQUIRE(path->commands[1].x == 0.0f);
REQUIRE(path->commands[1].y == -100.0f);
// 1st
REQUIRE(path->commands[2].command == rive::NoOpPathCommandType::CubicTo);
REQUIRE(path->commands[2].outX == 50.0f * rive::circleConstant);
REQUIRE(path->commands[2].outY == -100.0f);
REQUIRE(path->commands[2].inX == 50.0f);
REQUIRE(path->commands[2].inY == -100.0f * rive::circleConstant);
REQUIRE(path->commands[2].x == 50.0f);
REQUIRE(path->commands[2].y == 0.0f);
// 2nd
REQUIRE(path->commands[3].command == rive::NoOpPathCommandType::CubicTo);
REQUIRE(path->commands[3].outX == 50.0f);
REQUIRE(path->commands[3].outY == 100.0f * rive::circleConstant);
REQUIRE(path->commands[3].inX == 50.0f * rive::circleConstant);
REQUIRE(path->commands[3].inY == 100.0f);
REQUIRE(path->commands[3].x == 0.0f);
REQUIRE(path->commands[3].y == 100.0f);
// 3rd
REQUIRE(path->commands[4].command == rive::NoOpPathCommandType::CubicTo);
REQUIRE(path->commands[4].outX == -50.0f * rive::circleConstant);
REQUIRE(path->commands[4].outY == 100.0f);
REQUIRE(path->commands[4].inX == -50.0f);
REQUIRE(path->commands[4].inY == 100.0f * rive::circleConstant);
REQUIRE(path->commands[4].x == -50.0f);
REQUIRE(path->commands[4].y == 0.0f);
// 4th
REQUIRE(path->commands[5].command == rive::NoOpPathCommandType::CubicTo);
REQUIRE(path->commands[5].outX == -50.0f);
REQUIRE(path->commands[5].outY == -100.0f * rive::circleConstant);
REQUIRE(path->commands[5].inX == -50.0f * rive::circleConstant);
REQUIRE(path->commands[5].inY == -100.0f);
REQUIRE(path->commands[5].x == 0.0f);
REQUIRE(path->commands[5].y == -100.0f);
REQUIRE(path->commands[6].command == rive::NoOpPathCommandType::Close);
delete artboard;
}