aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/svg_pattern.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-04-16 20:12:59 +0200
committerjaseg <git@jaseg.de>2023-04-16 20:12:59 +0200
commit4aa448a5a37889d80fbf6ef006c5db1dd7c55f39 (patch)
treef26c719a393ad307c8a684e08002893d88dbd504 /svg-flatten/src/svg_pattern.cpp
parent384c91730756bf9ca07225e7d6d98b24af807028 (diff)
downloadgerbolyze-4aa448a5a37889d80fbf6ef006c5db1dd7c55f39.tar.gz
gerbolyze-4aa448a5a37889d80fbf6ef006c5db1dd7c55f39.tar.bz2
gerbolyze-4aa448a5a37889d80fbf6ef006c5db1dd7c55f39.zip
svg-flatten: Fix pattern clipping for rotated/skewed transforms
Diffstat (limited to 'svg-flatten/src/svg_pattern.cpp')
-rw-r--r--svg-flatten/src/svg_pattern.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/svg-flatten/src/svg_pattern.cpp b/svg-flatten/src/svg_pattern.cpp
index e8fb851..db740cf 100644
--- a/svg-flatten/src/svg_pattern.cpp
+++ b/svg-flatten/src/svg_pattern.cpp
@@ -60,8 +60,8 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
* patternTransform. This is necessary so we iterate over the correct bounds when tiling below */
d2p pos_xf = ctx.mat().doc2phys(d2p{x, y});
double inst_x = pos_xf[0], inst_y = pos_xf[1];
- double inst_w = ctx.mat().doc2phys_dist(w);
- double inst_h = ctx.mat().doc2phys_dist(h);
+ double inst_w = w;
+ double inst_h = h;
ClipperLib::IntRect clip_bounds = get_paths_bounds(ctx.clip());
double bx = clip_bounds.left / clipper_scale;
@@ -70,12 +70,14 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
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});
+ d2p clip_p1 = patternTransform_inv.doc2phys(d2p{bx+bw, by});
+ d2p clip_p2 = patternTransform_inv.doc2phys(d2p{bx+bw, by+bh});
+ d2p clip_p3 = patternTransform_inv.doc2phys(d2p{bx, 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;
+ bx = fmin(fmin(clip_p0[0], clip_p1[0]), fmin(clip_p2[0], clip_p3[0]));
+ by = fmin(fmin(clip_p0[1], clip_p1[1]), fmin(clip_p2[1], clip_p3[1]));
+ bw = fmax(fmax(clip_p0[0], clip_p1[0]), fmax(clip_p2[0], clip_p3[0])) - bx;
+ bh = fmax(fmax(clip_p0[1], clip_p1[1]), fmax(clip_p2[1], clip_p3[1])) - by;
if (patternUnits == SVG_ObjectBoundingBox) {
inst_x *= bw;
@@ -102,11 +104,9 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
for (double inst_off_x = fmod(inst_x, inst_w) - 2*inst_w;
inst_off_x < bx + bw + 2*inst_w;
inst_off_x += inst_w) {
-
for (double inst_off_y = fmod(inst_y, inst_h) - 2*inst_h;
inst_off_y < by + bh + 2*inst_h;
inst_off_y += inst_h) {
-
xform2d elem_xf;
/* Change into this individual tile's coordinate system */
elem_xf.translate(inst_off_x, inst_off_y);