diff options
author | jaseg <git@jaseg.de> | 2021-04-25 18:42:43 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2021-04-25 18:42:43 +0200 |
commit | 5bb733e55948e9a4273ae0f7cee8e81e38c23206 (patch) | |
tree | 6b04b36b8df3f9da655db8b8764dfc3e95e33b55 /svg-flatten/src/svg_pattern.cpp | |
parent | 6eb2c967a05a698b3da81168bcbcdc8c8368b490 (diff) | |
download | gerbolyze-5bb733e55948e9a4273ae0f7cee8e81e38c23206.tar.gz gerbolyze-5bb733e55948e9a4273ae0f7cee8e81e38c23206.tar.bz2 gerbolyze-5bb733e55948e9a4273ae0f7cee8e81e38c23206.zip |
Fix pattern rendering and some xform bugs
Diffstat (limited to 'svg-flatten/src/svg_pattern.cpp')
-rw-r--r-- | svg-flatten/src/svg_pattern.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/svg-flatten/src/svg_pattern.cpp b/svg-flatten/src/svg_pattern.cpp index a122975..cbdf4dd 100644 --- a/svg-flatten/src/svg_pattern.cpp +++ b/svg-flatten/src/svg_pattern.cpp @@ -59,10 +59,10 @@ void gerbolyze::Pattern::tile (xform2d &mat, const gerbolyze::RenderSettings &rs /* Transform x, y, w, h from pattern coordinate space into parent coordinates by applying the inverse * patternTransform. This is necessary so we iterate over the correct bounds when tiling below */ - d2p pos_xf = patternTransform_inv.doc2phys(d2p{x, y}); + d2p pos_xf = mat.doc2phys(d2p{x, y}); double inst_x = pos_xf[0], inst_y = pos_xf[1]; - double inst_w = patternTransform_inv.doc2phys_dist(w); - double inst_h = patternTransform_inv.doc2phys_dist(h); + double inst_w = mat.doc2phys_dist(w); + double inst_h = mat.doc2phys_dist(h); ClipperLib::IntRect clip_bounds = get_paths_bounds(clip); double bx = clip_bounds.left / clipper_scale; @@ -70,6 +70,14 @@ void gerbolyze::Pattern::tile (xform2d &mat, const gerbolyze::RenderSettings &rs double bw = (clip_bounds.right - clip_bounds.left) / clipper_scale; double bh = (clip_bounds.bottom - clip_bounds.top) / clipper_scale; + d2p clip_p0 = patternTransform_inv.doc2phys(d2p{bx, by}); + d2p clip_p1 = patternTransform_inv.doc2phys(d2p{bx+bw, by+bh}); + + bx = fmin(clip_p0[0], clip_p1[0]); + by = fmin(clip_p0[1], clip_p1[1]); + bw = fmax(clip_p0[0], clip_p1[0]) - bx; + bh = fmax(clip_p0[1], clip_p1[1]) - by; + if (patternUnits == SVG_ObjectBoundingBox) { inst_x *= bw; inst_y *= bh; @@ -79,16 +87,15 @@ void gerbolyze::Pattern::tile (xform2d &mat, const gerbolyze::RenderSettings &rs /* Switch to pattern coordinates */ xform2d local_xf(mat); - local_xf.translate(bx, by); local_xf.transform(patternTransform); /* Iterate over all pattern tiles in pattern coordinates */ - for (double inst_off_x = fmod(inst_x, inst_w) - inst_w; - inst_off_x < bw + inst_w; + for (double inst_off_x = fmod(inst_x, inst_w) - 2*inst_w; + inst_off_x < bw + 2*inst_w; inst_off_x += inst_w) { - for (double inst_off_y = fmod(inst_y, inst_h) - inst_h; - inst_off_y < bh + inst_h; + for (double inst_off_y = fmod(inst_y, inst_h) - 2*inst_h; + inst_off_y < bh + 2*inst_h; inst_off_y += inst_h) { xform2d elem_xf(local_xf); |