From b9b48276fdbbd05d8aa4b14d39b7e6edea449193 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Thu, 4 Feb 2010 22:33:19 +0100 Subject: [PATCH] improve LPE extrude such that cusps work for closed paths too --- src/live_effects/lpe-extrude.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 093f7a05a..c861515aa 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -40,7 +40,8 @@ static bool are_colinear(Geom::Point a, Geom::Point b) { return Geom::are_near(cross(a,b), 0., 0.5); } -// find cusps, this should be factored out later. +// find cusps, except at start/end for closed paths. +// this should be factored out later. static std::vector find_cusps( Geom::Piecewise > const & pwd2_in ) { using namespace Geom; Piecewise > deriv = derivative(pwd2_in); @@ -102,13 +103,22 @@ LPEExtrude::doEffect_pwd2 (Geom::Piecewise > const & pwd2 */ Piecewise > pwd2_out; - bool closed_path = are_near(pwd2_in.firstValue(), pwd2_in.lastValue()); // split input path in pieces between points where deriv == vector Piecewise > deriv = derivative(pwd2_in); std::vector rts = roots(dot(deriv, rot90(extrude_vector.getVector()))); std::vector cusps = find_cusps(pwd2_in); + // see if we should treat the path as being closed. + bool closed_path = false; + if ( are_near(pwd2_in.firstValue(), pwd2_in.lastValue()) ) { + // the path is closed, however if there is a cusp at the closing point, we should treat it as being an open path. + if ( are_colinear(deriv.firstValue(), deriv.lastValue()) ) { + // there is no jump in the derivative, so treat path as being closed + closed_path = true; + } + } + std::vector connector_pts; if (rts.size() < 1) { connector_pts = cusps; -- 2.30.2