Add path rendering and svg line output.

This commit is contained in:
jmsgrogan 2023-01-24 11:04:47 +00:00
parent 73051a5f27
commit 6274c41a80
15 changed files with 281 additions and 79 deletions

View file

@ -7,14 +7,14 @@
#include "LineNode.h"
#include "PathNode.h"
void addRect(const Point& loc, std::vector<std::unique_ptr<AbstractVisualNode> >& nodes, double radius = 0.0)
void addRect(const Point& loc, std::vector<std::unique_ptr<MaterialNode> >& nodes, double radius = 0.0)
{
auto node = std::make_unique<RectangleNode>(loc, 150.0, 100.0);
node->setRadius(radius);
nodes.push_back(std::move(node));
}
void addCircle(const Point& loc, std::vector<std::unique_ptr<AbstractVisualNode> >& nodes, double minorRadius = 0.0)
void addCircle(const Point& loc, std::vector<std::unique_ptr<MaterialNode> >& nodes, double minorRadius = 0.0)
{
const auto radius = 50.0;
auto centre_loc = loc;
@ -30,26 +30,25 @@ void addCircle(const Point& loc, std::vector<std::unique_ptr<AbstractVisualNode>
nodes.push_back(std::move(node));
}
void addLine(const Point& loc, std::vector<std::unique_ptr<AbstractVisualNode> >& nodes)
void addLine(const Point& loc, std::vector<std::unique_ptr<MaterialNode> >& nodes)
{
std::vector<Point> points = { Point(150.0, 100.0) };
auto node = std::make_unique<LineNode>(loc, points);
nodes.push_back(std::move(node));
}
void addPath(const Point& loc, const std::string& path, std::vector<std::unique_ptr<AbstractVisualNode> >& nodes)
void addPath(const Point& loc, const std::string& path, std::vector<std::unique_ptr<MaterialNode> >& nodes)
{
auto node = std::make_unique<PathNode>(loc, path);
nodes.push_back(std::move(node));
}
TEST_CASE(TestD2dOffScreenRendering, "graphics")
void addShapes(const Point& start_loc, std::vector<std::unique_ptr<MaterialNode> >& nodes, bool use_fill = false)
{
TestRenderer renderer(800, 800);
auto loc = start_loc;
std::vector<std::unique_ptr<AbstractVisualNode> > nodes;
auto fill_color = Color(200, 0, 200);
auto loc = Point(10, 10);
addRect(loc, nodes);
loc.move(250, 0);
@ -67,10 +66,60 @@ TEST_CASE(TestD2dOffScreenRendering, "graphics")
loc.move(100, 0);
addPath(loc, "M0 0 h150 v100 h-150Z", nodes);
loc = Point(10, 300);
addPath(loc, "M0 0 h150 q50 50 0 100 h-150Z", nodes);
loc.move(250, 0);
addPath(loc, "M0 0 h150 c25 25 25 75 0 100 h-150Z", nodes);
loc.move(250, 0);
addPath(loc, "M0 0 h150 a50 50 0 0 1 0 100 h-150Z", nodes);
if (use_fill)
{
for (auto& node : nodes)
{
node->setFillColor(fill_color);
}
}
}
TEST_CASE(TestD2dOffScreenRendering_Outlines, "graphics")
{
TestRenderer renderer(800, 800);
std::vector<std::unique_ptr<MaterialNode> > nodes;
auto loc = Point(10, 10);
addShapes(loc, nodes, false);
auto scene = renderer.getScene();
for (const auto& node : nodes)
{
scene->addNode(node.get());
}
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "out.png");
renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "outlines.svg");
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "outlines.png");
};
TEST_CASE(TestD2dOffScreenRendering_Fill, "graphics")
{
TestRenderer renderer(800, 800);
std::vector<std::unique_ptr<MaterialNode> > nodes;
auto loc = Point(10, 10);
addShapes(loc, nodes, true);
auto scene = renderer.getScene();
for (const auto& node : nodes)
{
scene->addNode(node.get());
}
renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "fill.svg");
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "fill.png");
};