Skip to content

Commit

Permalink
Applied clang-format.
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton authored and github-actions[bot] committed Nov 8, 2023
1 parent 0b363c8 commit 588d44d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
18 changes: 10 additions & 8 deletions include/utils/SVG.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Copyright (c) 2022 Ultimaker B.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.
// Copyright (c) 2022 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef SVG_H
#define SVG_H
Expand All @@ -19,7 +19,8 @@ class FPoint3;
class SVG : NoCopy
{
public:
enum class Color {
enum class Color
{
BLACK,
WHITE,
GRAY,
Expand All @@ -42,16 +43,18 @@ class SVG : NoCopy
ColorObject(Color color)
: is_enum(true)
, color(color)
{}
{
}
ColorObject(int r, int g, int b)
: is_enum(false)
, r(r)
, g(g)
, b(b)
{}
{
}
};
private:

private:
std::string toString(const Color color) const;
std::string toString(const ColorObject& color) const;

Expand Down Expand Up @@ -129,7 +132,7 @@ class SVG : NoCopy
* \param b The ending endpoint of the line.
* \param color The stroke colour of the line.
*/
void writeDashedLine(const Point& a,const Point& b, ColorObject color = Color::BLACK) const;
void writeDashedLine(const Point& a, const Point& b, ColorObject color = Color::BLACK) const;

template<typename... Args>
void printf(const char* txt, Args&&... args) const;
Expand Down Expand Up @@ -187,7 +190,6 @@ class SVG : NoCopy
* \param font_size The size of the font to write the coordinates with.
*/
void writeCoordinateGrid(const coord_t grid_size = MM2INT(1), const Color color = Color::BLACK, const float stroke_width = 0.1, const float font_size = 10) const;

};

template<typename... Args>
Expand Down
64 changes: 55 additions & 9 deletions src/utils/SVG.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) 2022 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher

#include "utils/SVG.h"

#include <sstream>

#include <spdlog/spdlog.h>

#include "utils/ExtrusionLine.h"
#include "utils/SVG.h"
#include "utils/floatpoint.h"
#include "utils/polygon.h"

Expand Down Expand Up @@ -59,15 +60,26 @@ std::string SVG::toString(const ColorObject& color) const


SVG::SVG(std::string filename, AABB aabb, Point canvas_size, ColorObject background)
: SVG(filename, aabb, std::min(double(canvas_size.X - canvas_size.X / 5 * 2) / (aabb.max.X - aabb.min.X), double(canvas_size.Y - canvas_size.Y / 5) / (aabb.max.Y - aabb.min.Y)), canvas_size, background)
: SVG(
filename,
aabb,
std::min(double(canvas_size.X - canvas_size.X / 5 * 2) / (aabb.max.X - aabb.min.X), double(canvas_size.Y - canvas_size.Y / 5) / (aabb.max.Y - aabb.min.Y)),
canvas_size,
background)
{
}

SVG::SVG(std::string filename, AABB aabb, double scale, ColorObject background) : SVG(filename, aabb, scale, (aabb.max - aabb.min) * scale, background)
SVG::SVG(std::string filename, AABB aabb, double scale, ColorObject background)
: SVG(filename, aabb, scale, (aabb.max - aabb.min) * scale, background)
{
}

SVG::SVG(std::string filename, AABB aabb, double scale, Point canvas_size, ColorObject background) : aabb(aabb), aabb_size(aabb.max - aabb.min), canvas_size(canvas_size), scale(scale), background(background)
SVG::SVG(std::string filename, AABB aabb, double scale, Point canvas_size, ColorObject background)
: aabb(aabb)
, aabb_size(aabb.max - aabb.min)
, canvas_size(canvas_size)
, scale(scale)
, background(background)
{
output_is_html = strcmp(filename.c_str() + strlen(filename.c_str()) - 4, "html") == 0;
out = fopen(filename.c_str(), "w");
Expand Down Expand Up @@ -165,7 +177,12 @@ void SVG::writeAreas(const Polygons& polygons, const ColorObject color, const Co

void SVG::writeAreas(ConstPolygonRef polygon, const ColorObject color, const ColorObject outline_color, const float stroke_width) const
{
fprintf(out, "<polygon fill=\"%s\" stroke=\"%s\" stroke-width=\"%f\" points=\"", toString(color).c_str(), toString(outline_color).c_str(), stroke_width); // The beginning of the polygon tag.
fprintf(
out,
"<polygon fill=\"%s\" stroke=\"%s\" stroke-width=\"%f\" points=\"",
toString(color).c_str(),
toString(outline_color).c_str(),
stroke_width); // The beginning of the polygon tag.
for (const Point& point : polygon) // Add every point to the list of points.
{
FPoint3 transformed = transformF(point);
Expand Down Expand Up @@ -209,7 +226,12 @@ void SVG::writeLines(const std::vector<Point>& polyline, const ColorObject color
}

FPoint3 transformed = transformF(polyline[0]); // Element 0 must exist due to the check above.
fprintf(out, "<path fill=\"none\" stroke=\"%s\" stroke-width=\"1\" d=\"M%f,%f", toString(color).c_str(), transformed.x, transformed.y); // Write the start of the path tag and the first endpoint.
fprintf(
out,
"<path fill=\"none\" stroke=\"%s\" stroke-width=\"1\" d=\"M%f,%f",
toString(color).c_str(),
transformed.x,
transformed.y); // Write the start of the path tag and the first endpoint.
for (size_t point = 1; point < polyline.size(); point++)
{
transformed = transformF(polyline[point]);
Expand All @@ -236,7 +258,20 @@ void SVG::writeArrow(const Point& a, const Point& b, const ColorObject color, co
FPoint3 tip = fb + normal * head_size - direction * head_size;
FPoint3 b_base = fb + normal * stroke_width - direction * stroke_width * 2.41;
FPoint3 a_base = fa + normal * stroke_width;
fprintf(out, "<polygon fill=\"%s\" points=\"%f,%f %f,%f %f,%f %f,%f %f,%f\" />", toString(color).c_str(), fa.x, fa.y, fb.x, fb.y, tip.x, tip.y, b_base.x, b_base.y, a_base.x, a_base.y);
fprintf(
out,
"<polygon fill=\"%s\" points=\"%f,%f %f,%f %f,%f %f,%f %f,%f\" />",
toString(color).c_str(),
fa.x,
fa.y,
fb.x,
fb.y,
tip.x,
tip.y,
b_base.x,
b_base.y,
a_base.x,
a_base.y);
}

void SVG::writeLineRGB(const Point& from, const Point& to, const int r, const int g, const int b, const float stroke_width) const
Expand Down Expand Up @@ -369,7 +404,7 @@ void SVG::writeLine(const ExtrusionLine& line, const ColorObject color, const fl
{
ExtrusionJunction end_vertex = line.junctions[index];

// Compute the corners of the trapezoid for this variable-width line segment.
// Compute the corners of the trapezoid for this variable-width line segment.
const Point direction_vector = end_vertex.p - start_vertex.p;
const Point direction_left = turn90CCW(direction_vector);
const Point direction_right = -direction_left; // Opposite of left.
Expand All @@ -378,7 +413,18 @@ void SVG::writeLine(const ExtrusionLine& line, const ColorObject color, const fl
const FPoint3 end_left = transformF(end_vertex.p + normal(direction_left, std::max(minimum_line_width, end_vertex.w * width_factor)));
const FPoint3 end_right = transformF(end_vertex.p + normal(direction_right, std::max(minimum_line_width, end_vertex.w * width_factor)));

fprintf(out, "<polygon fill=\"%s\" points=\"%f,%f %f,%f %f,%f %f,%f\" />\n", toString(color).c_str(), start_left.x, start_left.y, start_right.x, start_right.y, end_right.x, end_right.y, end_left.x, end_left.y);
fprintf(
out,
"<polygon fill=\"%s\" points=\"%f,%f %f,%f %f,%f %f,%f\" />\n",
toString(color).c_str(),
start_left.x,
start_left.y,
start_right.x,
start_right.y,
end_right.x,
end_right.y,
end_left.x,
end_left.y);

start_vertex = end_vertex; // For the next line segment.
}
Expand Down

0 comments on commit 588d44d

Please sign in to comment.