16 static std::vector<Polygon>
load(
const std::string &filename) {
17 std::ifstream input_file(filename);
19 std::vector<Polygon> polygons;
20 if (input_file.fail()) {
21 std::cerr <<
"Cannot load SVG file from " << filename
22 <<
". Make sure the file exists." << std::endl;
26 double offset_x = 0, offset_y = 0;
27 while (getline(input_file,
line)) {
29 if (
line.substr(0, 21) ==
"transform=\"translate(") {
30 std::stringstream ss(
line.substr(21,
line.length() - 21));
35 std::cout <<
"SVG group: using offset_x=" << offset_x
36 <<
" offset_y=" << offset_y << std::endl;
37 }
else if (
line.substr(0, 2) ==
"d=") {
42 std::cerr <<
"Warning: found nonconvex polygon in " << filename
43 <<
". Using its convex hull instead." << std::endl;
46 std::cerr << std::boolalpha <<
"Hull is convex? " << poly.
isConvex()
50 polygons.emplace_back(poly);
57 static inline void trim(std::string &s) {
58 s.erase(s.begin(), std::find_if(s.begin(), s.end(),
59 [](
int ch) { return !std::isspace(ch); }));
60 s.erase(std::find_if(s.rbegin(), s.rend(),
61 [](
int ch) { return !std::isspace(ch); })
This class loads polygons from an SVG file.
Definition: SvgPolygonLoader.hpp:14
static std::vector< Polygon > load(const std::string &filename)
Definition: SvgPolygonLoader.hpp:16
bool line(double x0, double y0, double y1, double x1)
Definition: gnode_base.cpp:23
Definition: Primitives.h:42
Definition: Primitives.h:145
Polygon convexHull() const
Definition: Primitives.cpp:106
void translate(const Point &t)
Definition: Primitives.h:235
bool isConvex() const
Definition: Primitives.cpp:69
static Polygon loadFromSvgPathStr(std::string path_str)
Loads polygon from a path tag inside an SVG file.
Definition: Primitives.h:181