From: mathog <ma...@ca...> - 2012-09-04 22:47:12
|
This may not be the most efficient way to do this, but it works pretty well (sorry about any wrapping that may occur when it is posted): // convert the path, gets its complete length, and then make a new path with parameter length instead of t Geom::Piecewise<Geom::D2<Geom::SBasis> > tmp_pathpw; // pathv-> sbasis Geom::Piecewise<Geom::D2<Geom::SBasis> > tmp_pathpw2; // sbasis using arc length parameter Geom::Piecewise<Geom::D2<Geom::SBasis> > tmp_pathpw3; // new (discontinuous) path, composed of dots/dashes int n_dash = style->stroke_dash.n_dash; int i=0; //dash index double tlength; // length of tmp_pathpw double slength=0.0; // start of gragment double elength; // end of gragment for (unsigned int i=0; i < pathv.size(); i++) { tmp_pathpw.concat(pathv[i].toPwSb()); } tlength = length(tmp_pathpw,0.1); tmp_pathpw2 = arc_length_parametrization(tmp_pathpw); std::cout << "length of pathpw:"<< tlength << std::endl; // go around the dash array repeatedly until the entire path is consumed (but not beyond). while(slength < tlength){ elength = slength + style->stroke_dash.dash[i++]; if(elength > tlength)elength = tlength; Geom::Piecewise<Geom::D2<Geom::SBasis> > fragment(portion(tmp_pathpw2, slength, elength)); slength = elength; slength += style->stroke_dash.dash[i++]; // the gap if(i>=n_dash)i=0; tmp_pathpw3.concat(fragment); } Geom::PathVector out_pathv = Geom::path_from_piecewise(tmp_pathpw3, 0.01); The only thing it does poorly is the handling of the dash located at P.begin(), which is always broken into two pieces. When viewed in inkscape it looks better, as if it was wrapped around that corner. In terms of efficiency this code may not be so good since the portion() method presumably has to repeat position calculations from 0 to the previous elength, since it does not save the end point of the previous fragment. Anyway, good enough. Now on to the boolops, which is going to be harder since the underlying 2geom function is apparently broken... Thanks, David Mathog ma...@ca... Manager, Sequence Analysis Facility, Biology Division, Caltech |