summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-powerstroke.cpp
diff options
context:
space:
mode:
authorDenis Declara <declara91@gmail.com>2012-04-26 11:14:34 +0000
committerDenis Declara <declara91@gmail.com>2012-04-26 11:14:34 +0000
commit95a8ad7bfec98f7cede15c4e8856ce547aaf4aa4 (patch)
tree506de5a8437cb39917a66d74b68d78692d10a993 /src/live_effects/lpe-powerstroke.cpp
parentAdded first support for elliptical arrangements (diff)
parentpowerstroke: cautious fix. (diff)
downloadinkscape-95a8ad7bfec98f7cede15c4e8856ce547aaf4aa4.tar.gz
inkscape-95a8ad7bfec98f7cede15c4e8856ce547aaf4aa4.zip
Trunk merge
(bzr r11073.1.20)
Diffstat (limited to '')
-rw-r--r--src/live_effects/lpe-powerstroke.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp
index a9cf22f6a..44f9b9eb0 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::D2<Geom::SBasis>
Geom::Piecewise<Geom::SBasis> 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
@@ -238,10 +238,10 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise<Geom::D2<Geom::SBasis>
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!)
@@ -258,30 +258,23 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise<Geom::D2<Geom::SBasis>
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() );
- } 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<Geom::SBasis> newcurve1 = B[prev_i] * Geom::reflection(rot90(tang1), B[prev_i].at1());
Geom::CubicBezier bzr1 = sbasis_to_cubicbezier( reverse(newcurve1) );
@@ -306,17 +299,9 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise<Geom::D2<Geom::SBasis>
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<Geom::Point> p = intersection_point( B[prev_i].at1(), tang1,
B[i].at0(), tang2 );
if (p) {
@@ -329,14 +314,9 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise<Geom::D2<Geom::SBasis>
}
}
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 +338,39 @@ Geom::Path path_from_piecewise_fix_cusps( Geom::Piecewise<Geom::D2<Geom::SBasis>
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.size() != 1) {
+ // empty crossing or too many crossings: 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();