From 522b2d9c6f42e61e59c852293d9a9108e66744fa Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 15 Apr 2012 20:29:37 +0200 Subject: powerstroke: fix inside of corners. (bzr r11254) --- src/live_effects/lpe-powerstroke.cpp | 90 ++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 50 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index a9cf22f6a..8d5888e37 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -238,10 +238,10 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise Geom::Point discontinuity_vec = B[i].at0() - B[prev_i].at1(); bool on_outside = ( dot(tang1, discontinuity_vec) >= 0. ); - switch (jointype) { - case LINEJOIN_ROUND: { - if (on_outside) { - // we are on the outside: round corner + if (on_outside) { + // we are on the outside: add some type of join! + switch (jointype) { + case LINEJOIN_ROUND: { /* for constant width paths, the rounding is a circular arc (rx == ry), for non-constant width paths, the rounding can be done with an ellipse but is hard and ambiguous. The elliptical arc should go through the discontinuity's start and end points (of course!) @@ -261,27 +261,10 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise Geom::Ellipse ellipse = find_ellipse(B[prev_i].at1(), B[i].at0(), *O); pb.arcTo( ellipse.ray(Geom::X), ellipse.ray(Geom::Y), ellipse.rot_angle(), false, width < 0, B[i].at0() ); - } else { - // we are on the inside, do a simple bevel to connect the paths - pb.lineTo(B[i].at0()); // default to bevel for too shallow cusp angles - } - break; - } -/* case LINEJOIN_NONE: { - if ( on_outside ) { - // we are on the outside - Geom::Point point_on_path = B[prev_i].at1() - rot90(tang1) * width; - pb.lineTo(point_on_path); - pb.lineTo(B[i].at0()); - } else { - // we are on the inside, do a simple bevel to connect the paths - pb.lineTo(B[i].at0()); // default to bevel for too shallow cusp angles - } - } */ - case LINEJOIN_EXTRP_MITER: { - if (on_outside) { - // we are on the outside, do something complicated to make it look good ;) + break; + } + case LINEJOIN_EXTRP_MITER: { Geom::D2 newcurve1 = B[prev_i] * Geom::reflection(rot90(tang1), B[prev_i].at1()); Geom::CubicBezier bzr1 = sbasis_to_cubicbezier( reverse(newcurve1) ); @@ -306,17 +289,9 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise pb.curveTo(sub2.second[1], sub2.second[2], sub2.second[3]); } } - - } else { - // we are on the inside, do a simple bevel to connect the paths - pb.lineTo(B[i].at0()); // default to bevel for too shallow cusp angles + break; } - break; - } - case LINEJOIN_MITER: { - if (on_outside) { - // we are on the outside, do something complicated to make it look good ;) - + case LINEJOIN_MITER: { boost::optional p = intersection_point( B[prev_i].at1(), tang1, B[i].at0(), tang2 ); if (p) { @@ -329,14 +304,9 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise } } pb.lineTo(B[i].at0()); - } else { - // we are on the inside, do a simple bevel to connect the paths - pb.lineTo(B[i].at0()); // default to bevel for too shallow cusp angles + break; } - break; - } - case LINEJOIN_SPIRO: { - if (on_outside) { + case LINEJOIN_SPIRO: { Geom::Point direction = B[i].at0() - B[prev_i].at1(); double tang1_sign = dot(direction,tang1); double tang2_sign = dot(direction,tang2); @@ -358,19 +328,39 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise Geom::Path spiro; Spiro::spiro_run(controlpoints, 4, spiro); pb.append(spiro.portion(1,spiro.size_open()-1), Geom::Path::STITCH_DISCONTINUOUS); + break; + } + case LINEJOIN_BEVEL: + default: + pb.lineTo(B[i].at0()); + break; + } + + build_from_sbasis(pb, B[i], tol, false); + + } else { + // we are on inside of corner! + Geom::Path bzr1 = path_from_sbasis( B[prev_i], tol ); + Geom::Path bzr2 = path_from_sbasis( B[i], tol ); + Geom::Crossings cross = crossings(bzr1, bzr2); + if (cross.empty()) { + // empty crossing: default to bevel + pb.lineTo(B[i].at0()); + pb.append(bzr2, Geom::Path::STITCH_DISCONTINUOUS); } else { - // we are on the inside, do a simple bevel to connect the paths - pb.lineTo(B[i].at0()); // default to bevel for too shallow cusp angles + // :-) quick hack: + for (unsigned i=0; i < bzr1.size_open(); ++i) { + pb.backspace(); + } + + pb.append( bzr1.portion(0, cross[0].ta), Geom::Path::STITCH_DISCONTINUOUS ); + pb.append( bzr2.portion(cross[0].tb, bzr2.size_open()), Geom::Path::STITCH_DISCONTINUOUS ); } - break; - } - case LINEJOIN_BEVEL: - default: - pb.lineTo(B[i].at0()); - break; } + } else { + build_from_sbasis(pb, B[i], tol, false); } - build_from_sbasis(pb, B[i], tol, false); + prev_i = i; } pb.finish(); -- cgit v1.2.3 From f8ae8770dd95f4a1102f6d50eb94c9ddc483a6d1 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Mon, 16 Apr 2012 00:50:37 -0700 Subject: Loop index type cleanup (bzr r11258) --- src/live_effects/lpe-powerstroke.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 8d5888e37..3b6af3cb6 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -209,7 +209,7 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise Geom::Piecewise const & y, // width path LineJoinType jointype, double miter_limit, - bool forward_direction, + bool /*forward_direction*/, double tol=Geom::EPSILON) { /* per definition, each discontinuity should be fixed with a join-ending, as defined by linejoin_type -- cgit v1.2.3 From 36e3c5550b49949729f2f23ab1796afdc53d6487 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Wed, 18 Apr 2012 00:02:24 -0700 Subject: Warning cleanup (bzr r11265) --- src/live_effects/lpe-knot.cpp | 3 ++- src/live_effects/lpe-rough-hatches.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 7a66b80c9..7ec103a85 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -94,7 +94,8 @@ findShadowedTime(Geom::Path const &patha, std::vector const &pt_and using namespace Geom; Point T = unit_vector(pt_and_dir[1]); Point N = T.cw(); - Point A = pt_and_dir[0]-3*width*T, B = A+6*width*T; + //Point A = pt_and_dir[0] - 3 * width * T; + //Point B = A+6*width*T; Affine mat = from_basis( T, N, pt_and_dir[0] ); mat = mat.inverse(); diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index f9ab72373..fb3d143aa 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -440,8 +440,8 @@ LPERoughHatches::smoothSnake(std::vector > const &linearSnake for (unsigned comp=0; comp=2){ Point last_pt = linearSnake[comp][0]; - Point last_top = linearSnake[comp][0]; - Point last_bot = linearSnake[comp][0]; + //Point last_top = linearSnake[comp][0]; + //Point last_bot = linearSnake[comp][0]; Point last_hdle = linearSnake[comp][0]; Point last_top_hdle = linearSnake[comp][0]; Point last_bot_hdle = linearSnake[comp][0]; @@ -482,8 +482,8 @@ LPERoughHatches::smoothSnake(std::vector > const &linearSnake if ( fat_output.get_value() ){ //double scaled_width = double((is_top ? stroke_width_top : stroke_width_bot))/(pt1[X]-pt0[X]); - double scaled_width = 1./(pt1[X]-pt0[X]); - Point hdle_offset = (pt1-pt0)*scaled_width; + //double scaled_width = 1./(pt1[X]-pt0[X]); + //Point hdle_offset = (pt1-pt0)*scaled_width; Point inside = new_pt; Point inside_hdle_in; Point inside_hdle_out; -- cgit v1.2.3 From 94dbdb9de139aa064e745630bb7bc6ed6d399730 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Wed, 25 Apr 2012 23:21:59 +0200 Subject: powerstroke: add errorhandling for rounded corners. Fixed bugs: - https://launchpad.net/bugs/986394 (bzr r11295) --- src/live_effects/lpe-powerstroke.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 3b6af3cb6..6f803c4ff 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -258,7 +258,17 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise break; } - Geom::Ellipse ellipse = find_ellipse(B[prev_i].at1(), B[i].at0(), *O); + Geom::Ellipse ellipse; + try { + ellipse = find_ellipse(B[prev_i].at1(), B[i].at0(), *O); + } + catch (Geom::LogicalError &e) { + // 2geom did not find a fitting ellipse, this happens for weird thick paths :) + // do bevel, and break + pb.lineTo(B[i].at0()); + break; + } + pb.arcTo( ellipse.ray(Geom::X), ellipse.ray(Geom::Y), ellipse.rot_angle(), false, width < 0, B[i].at0() ); -- cgit v1.2.3 From 41f82f5b2ba4513b274c52699771dc07cce8c0aa Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Wed, 25 Apr 2012 23:30:57 +0200 Subject: powerstroke: cautious fix. (bzr r11296) --- src/live_effects/lpe-powerstroke.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 6f803c4ff..44f9b9eb0 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -353,8 +353,8 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise Geom::Path bzr1 = path_from_sbasis( B[prev_i], tol ); Geom::Path bzr2 = path_from_sbasis( B[i], tol ); Geom::Crossings cross = crossings(bzr1, bzr2); - if (cross.empty()) { - // empty crossing: default to bevel + if (cross.size() != 1) { + // empty crossing or too many crossings: default to bevel pb.lineTo(B[i].at0()); pb.append(bzr2, Geom::Path::STITCH_DISCONTINUOUS); } else { -- cgit v1.2.3