diff options
author | jaseg <git@jaseg.de> | 2022-06-20 10:24:26 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-06-20 10:24:26 +0200 |
commit | d09cf6ef3b6ea82f7ff67719527cd563569e0893 (patch) | |
tree | 4175218f4fdd6a1a36c8fd835c87639353a3c1c5 /svg-flatten/src/svg_pattern.cpp | |
parent | f58cca0ba66e66e924caf96545a348584d4f48ee (diff) | |
download | gerbolyze-d09cf6ef3b6ea82f7ff67719527cd563569e0893.tar.gz gerbolyze-d09cf6ef3b6ea82f7ff67719527cd563569e0893.tar.bz2 gerbolyze-d09cf6ef3b6ea82f7ff67719527cd563569e0893.zip |
svg-flatten: Add 'complete pattern tiles only' switch
This is not part of the SVG spec, but it is useful for generating proto
boards using SVG patterns.
Diffstat (limited to 'svg-flatten/src/svg_pattern.cpp')
-rw-r--r-- | svg-flatten/src/svg_pattern.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/svg-flatten/src/svg_pattern.cpp b/svg-flatten/src/svg_pattern.cpp index cdff7a7..fc74d73 100644 --- a/svg-flatten/src/svg_pattern.cpp +++ b/svg-flatten/src/svg_pattern.cpp @@ -108,6 +108,29 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) { /* Export the pattern tile's content like a group */ RenderContext elem_ctx(pat_ctx, elem_xf); + + if (ctx.settings().pattern_complete_tiles_only) { + ClipperLib::Clipper c; + + double eps = 1e-6; + Polygon poly = {{eps, eps}, {inst_w-eps, eps}, {inst_w-eps, inst_h-eps}, {eps, inst_h-eps}}; + elem_ctx.mat().transform_polygon(poly); + ClipperLib::Path path(poly.size()); + for (size_t i=0; i<poly.size(); i++) { + long long int x = poly[i][0] * clipper_scale, y = poly[i][1] * clipper_scale; + path[i] = {x, y}; + } + + ClipperLib::Paths out; + c.StrictlySimple(true); + c.AddPath(path, ClipperLib::ptSubject, /* closed */ true); + c.AddPaths(elem_ctx.clip(), ClipperLib::ptClip, /* closed */ true); + c.Execute(ClipperLib::ctDifference, out, ClipperLib::pftNonZero); + if (out.size() > 0) { + continue; + } + } + doc->export_svg_group(elem_ctx, _node); } } |