From 29bb56d8dfc27e5f69a4211750b3971c975aa6f3 Mon Sep 17 00:00:00 2001 From: jfbarraud Date: Wed, 11 Mar 2009 00:22:40 +0000 Subject: [PATCH] bug fix about closed path. --- src/live_effects/lpe-knot.cpp | 104 +++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 38 deletions(-) diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index f362afab8..65c642afa 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -20,11 +20,10 @@ #include <2geom/d2.h> #include <2geom/d2-sbasis.h> #include <2geom/path.h> -#include <2geom/crossing.h> +//#include <2geom/crossing.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/basic-intersection.h> #include <2geom/exception.h> -//#include "2geom/recursive-bezier-intersection.cpp" #include @@ -79,11 +78,13 @@ findShadowedTime(Geom::Path const &patha, std::vector const &pt_and Matrix mat = from_basis( T, N, pt_and_dir[0] ); mat = mat.inverse(); Path p = patha * mat; + std::vector times; - for (unsigned i = 0; i f = p[i].toSBasis(); std::vector times_i, temptimes; - //TODO: explore the path fwd/backward from ta to avoid all those useless computations. temptimes = roots(f[Y]-width); times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() ); temptimes = roots(f[Y]+width); @@ -98,7 +99,9 @@ findShadowedTime(Geom::Path const &patha, std::vector const &pt_and times.insert(times.end(), times_i.begin(), times_i.end() ); } std::sort( times.begin(), times.end() ); - std::unique( times.begin(), times.end() ); + std::vector::iterator new_end = std::unique( times.begin(), times.end() ); + times.resize( new_end - times.begin() ); + double tmin = 0, tmax = patha.size(); double period = patha.size();//hm... Should this be patha.size()+1? if (times.size()>0){ @@ -128,7 +131,7 @@ findShadowedTime(Geom::Path const &patha, std::vector const &pt_and namespace LPEKnotNS {//just in case... CrossingPoints::CrossingPoints(std::vector const &paths) : std::vector(){ - //std::cout<<"\nCrossingPoints creation from path vector\n"; +// std::cout<<"\nCrossingPoints creation from path vector\n"; for( unsigned i=0; i const &path_in) } } } + + //If the all component is hidden, continue. + if ( dom.size() == 0){ + continue; + } + //If the current path is closed and the last/first point is still there, glue first and last piece. unsigned beg_comp = 0, end_comp = dom.size(); - if ( gpaths[i0].closed() && dom.size() > 1 && dom.front().min() == 0 && dom.back().max() == gpaths[i0].size() ){ - beg_comp++; - end_comp--; - Path first = gpaths[i0].portion(dom.back()); - first.append(gpaths[i0].portion(dom.front()), Path::STITCH_DISCONTINUOUS);//FIXME: STITCH_DISCONTINUOUS should not be necessary. - path_out.push_back(first); + if ( gpaths[i0].closed() && dom.front().min() == 0 && dom.back().max() == gpaths[i0].size() ){ + if ( dom.size() == 1){ + path_out.push_back(gpaths[i0]); + continue; + }else{ +// std::cout<<"fusing first and last component\n"; + beg_comp++; + end_comp--; + Path first = gpaths[i0].portion(dom.back()); + //FIXME: STITCH_DISCONTINUOUS should not be necessary (?!?) + first.append(gpaths[i0].portion(dom.front()), Path::STITCH_DISCONTINUOUS); + path_out.push_back(first); + } } for (unsigned comp = beg_comp; comp < end_comp; comp++){ assert(dom.at(comp).min() >=0 and dom.at(comp).max() <= gpaths.at(i0).size()); @@ -493,36 +509,48 @@ LPEKnot::doBeforeEffect (SPLPEItem *lpeitem) gstroke_widths = std::vector(); collectPathsAndWidths(lpeitem, gpaths, gstroke_widths); +// std::cout<<"\nPaths on input:\n"; +// for (unsigned i=0; i 0 ) std::cout<<"first crossing sign = "<