index b3aa2df459e1961a975b9a168ffed6ddcbe54775..fef4e1f8777573e3e58e7ceadcd65caff833d2e7 100644 (file)
*/
/* Authors:
* Jean-Francois Barraud <jf.barraud@gmail.com>
+ * Abhishek Sharma
*
* Copyright (C) 2007 Authors
*
};
+Geom::Path::size_type size_nondegenerate(Geom::Path const &path) {
+ Geom::Path::size_type retval = path.size_open();
+
+ // if path is closed and closing segment is not degenerate
+ if (path.closed() && !path.back_closed().isDegenerate()) {
+ retval = path.size_closed();
+ }
+
+ return retval;
+}
+
//---------------------------------------------------------------------------
//LPEKnot specific Interval manipulation.
//---------------------------------------------------------------------------
static
std::vector<Geom::Interval> complementOf(Geom::Interval I, std::vector<Geom::Interval> domain){
std::vector<Geom::Interval> ret;
- double min = domain.front().min();
- double max = domain.back().max();
- Geom::Interval I1 = Geom::Interval(min,I.min());
- Geom::Interval I2 = Geom::Interval(I.max(),max);
-
- for (unsigned i = 0; i<domain.size(); i++){
- boost::optional<Geom::Interval> I1i = intersect(domain.at(i),I1);
- if (I1i && !I1i->isSingular()) ret.push_back(I1i.get());
- boost::optional<Geom::Interval> I2i = intersect(domain.at(i),I2);
- if (I2i && !I2i->isSingular()) ret.push_back(I2i.get());
- }
+ if (!domain.empty()) {
+ double min = domain.front().min();
+ double max = domain.back().max();
+ Geom::Interval I1 = Geom::Interval(min,I.min());
+ Geom::Interval I2 = Geom::Interval(I.max(),max);
+
+ for (unsigned i = 0; i<domain.size(); i++){
+ boost::optional<Geom::Interval> I1i = intersect(domain.at(i),I1);
+ if (I1i && !I1i->isSingular()) ret.push_back(I1i.get());
+ boost::optional<Geom::Interval> I2i = intersect(domain.at(i),I2);
+ if (I2i && !I2i->isSingular()) ret.push_back(I2i.get());
+ }
+ }
return ret;
}
std::vector<double> times;
//TODO: explore the path fwd/backward from ta (worth?)
- for (unsigned i=0; i<patha.size(); i++){
+ for (unsigned i = 0; i < size_nondegenerate(patha); i++){
D2<SBasis> f = p[i].toSBasis();
std::vector<double> times_i, temptimes;
temptimes = roots(f[Y]-width);
@@ -108,8 +122,8 @@ findShadowedTime(Geom::Path const &patha, std::vector<Geom::Point> const &pt_and
std::vector<double>::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?
+ double tmin = 0, tmax = size_nondegenerate(patha);
+ double period = size_nondegenerate(patha);
if (times.size()>0){
unsigned rk = upper_bound( times.begin(), times.end(), ta ) - times.begin();
if ( rk < times.size() )
CrossingPoints::CrossingPoints(std::vector<Geom::Path> const &paths) : std::vector<CrossingPoint>(){
// std::cout<<"\nCrossingPoints creation from path vector\n";
for( unsigned i=0; i<paths.size(); i++){
- for( unsigned ii=0; ii<paths[i].size(); ii++){
+ for( unsigned ii=0; ii < size_nondegenerate(paths[i]); ii++){
for( unsigned j=i; j<paths.size(); j++){
- for( unsigned jj=(i==j?ii:0); jj<paths[j].size(); jj++){
+ for( unsigned jj=(i==j?ii:0); jj < size_nondegenerate(paths[j]); jj++){
std::vector<std::pair<double,double> > times;
if ( i==j && ii==jj){
@@ -167,7 +181,7 @@ CrossingPoints::CrossingPoints(std::vector<Geom::Path> const &paths) : std::vect
if ( i==j && fabs(times[k].first+ii - times[k].second-jj)<=zero ){//this is just end=start of successive curves in a path.
continue;
}
- if ( i==j && ii == 0 && jj==paths[i].size()-1 &&
+ if ( i==j && ii == 0 && jj == size_nondegenerate(paths[i])-1 &&
paths[i].closed() &&
fabs(times[k].first) <= zero &&
fabs(times[k].second - 1) <= zero ){//this is just end=start of a closed path.
LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
// initialise your parameters here:
- interruption_width(_("Fixed width"), _("Size of hidden region of lower string"), "interruption_width", &wr, this, 3),
+ interruption_width(_("Fixed width:"), _("Size of hidden region of lower string"), "interruption_width", &wr, this, 3),
prop_to_stroke_width(_("In units of stroke width"), _("Consider 'Interruption width' as a ratio of stroke width"), "prop_to_stroke_width", &wr, this, true),
add_stroke_width(_("Stroke width"), _("Add the stroke width to the interruption size"), "add_stroke_width", &wr, this, true),
add_other_stroke_width(_("Crossing path stroke width"), _("Add crossed stroke width to the interruption size"), "add_other_stroke_width", &wr, this, true),
- switcher_size(_("Switcher size"), _("Orientation indicator/switcher size"), "switcher_size", &wr, this, 15),
+ switcher_size(_("Switcher size:"), _("Orientation indicator/switcher size"), "switcher_size", &wr, this, 15),
crossing_points_vector(_("Crossing Signs"), _("Crossings signs"), "crossing_points_vector", &wr, this),
gpaths(),gstroke_widths()
{
if (i0 == gpaths.size() ) {THROW_EXCEPTION("lpe-knot error: group member not recognized");}// this should not happen...
std::vector<Interval> dom;
- dom.push_back(Interval(0.,gpaths[i0].size()));
+ dom.push_back(Interval(0., size_nondegenerate(gpaths[i0])));
for (unsigned p = 0; p < crossing_points.size(); p++){
if (crossing_points[p].i == i0 || crossing_points[p].j == i0){
unsigned i = crossing_points[p].i;
double curveidx, t;
t = modf(ti, &curveidx);
- if(curveidx == gpaths[i].size() ) { curveidx--; t = 1.;}
- assert(curveidx >= 0 && curveidx < gpaths[i].size());
+ if(curveidx == size_nondegenerate(gpaths[i]) ) { curveidx--; t = 1.;}
+ assert(curveidx >= 0 && curveidx < size_nondegenerate(gpaths[i]));
std::vector<Point> flag_i = gpaths[i][curveidx].pointAndDerivatives(t,1);
t = modf(tj, &curveidx);
- if(curveidx == gpaths[j].size() ) { curveidx--; t = 1.;}
- assert(curveidx >= 0 && curveidx < gpaths[j].size());
+ if(curveidx == size_nondegenerate(gpaths[j]) ) { curveidx--; t = 1.;}
+ assert(curveidx >= 0 && curveidx < size_nondegenerate(gpaths[j]));
std::vector<Point> flag_j = gpaths[j][curveidx].pointAndDerivatives(t,1);
width += gstroke_widths[j];
}
Interval hidden = findShadowedTime(gpaths[i0], flag_j, ti, width/2);
- double period = gpaths[i0].size();//hm... Should this be gpaths[i0].size()+1?
+ double period = size_nondegenerate(gpaths[i0]);
if (hidden.max() > period ) hidden -= period;
if (hidden.min()<0){
dom = complementOf( Interval(0,hidden.max()) ,dom);
//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.front().min() == 0 && dom.back().max() == gpaths[i0].size() ){
+ if ( gpaths[i0].closed() && dom.front().min() == 0 && dom.back().max() == size_nondegenerate(gpaths[i0]) ){
if ( dom.size() == 1){
path_out.push_back(gpaths[i0]);
continue;
}
}
for (unsigned comp = beg_comp; comp < end_comp; comp++){
- assert(dom.at(comp).min() >=0 and dom.at(comp).max() <= gpaths.at(i0).size());
+ assert(dom.at(comp).min() >=0 and dom.at(comp).max() <= size_nondegenerate(gpaths.at(i0)));
path_out.push_back(gpaths[i0].portion(dom.at(comp)));
}
}
@@ -496,7 +510,7 @@ void collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector<Geom::Path> &p
if (SP_IS_PATH(lpeitem)) {
c = sp_path_get_curve_for_edit(SP_PATH(lpeitem));
} else {
- c = sp_shape_get_curve(SP_SHAPE(lpeitem));
+ c = SP_SHAPE(lpeitem)->getCurve();
}
if (c) {
Geom::PathVector subpaths = c->get_pathvector();
//std::cout<<"crossing set to"<<lpe->crossing_points[s].sign<<".\n";
}
lpe->crossing_points_vector.param_set_and_write_new_value(lpe->crossing_points.to_vector());
- sp_document_done(lpe->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, /// @todo Is this the right verb?
- _("Change knot crossing"));
+ DocumentUndo::done(lpe->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, /// @todo Is this the right verb?
+ _("Change knot crossing"));
// FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
// sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
+