From 6cf3f3c4fa0309fbe2af3849cbb0c1f3e9d2b2e7 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sat, 19 Apr 2014 21:14:39 -0400 Subject: remove easter eggs (bzr r13090.1.62) --- src/live_effects/lpe-jointype.cpp | 7 +- src/live_effects/lpe-powerstroke.cpp | 3 + src/live_effects/lpe-taperstroke.cpp | 108 ++++++++++++++++++++----------- src/live_effects/pathoutlineprovider.cpp | 58 ++++++++++++----- 4 files changed, 119 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index 3b2887bb5..f3ec02530 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -52,9 +52,9 @@ static const Util::EnumDataConverter JoinTypeConverter(JoinTypeData, s LPEJoinType::LPEJoinType(LivePathEffectObject *lpeobject) : Effect(lpeobject), - line_width(_("Line width"), _("Thickness of the stroke"), "line_width", &wr, this, 10.), + line_width(_("Line width"), _("Thickness of the stroke"), "line_width", &wr, this, 1.), linecap_type(_("Line cap"), _("The end shape of the stroke"), "linecap_type", CapTypeConverter, &wr, this, butt_straight), - linejoin_type(_("Join:"), _("Determines the shape of the path's corners"), "linejoin_type", JoinTypeConverter, &wr, this, join_pointy), + linejoin_type(_("Join:"), _("Determines the shape of the path's corners"), "linejoin_type", JoinTypeConverter, &wr, this, LINEJOIN_EXTRAPOLATED), miter_limit(_("Miter limit:"), _("Maximum length of the miter join (in units of stroke width)"), "miter_limit", &wr, this, 100.), attempt_force_join(_("Force miter"), _("Overrides the miter limit and forces a join."), "attempt_force_join", &wr, this, true) { @@ -164,7 +164,8 @@ void LPEJoinType::doOnRemove(SPLPEItem const* lpeitem) std::vector LPEJoinType::doEffect_path(std::vector const & path_in) { return Outline::PathVectorOutline(path_in, line_width, static_cast(linecap_type.get_value()), - static_cast(linejoin_type.get_value()), miter_limit); + static_cast(linejoin_type.get_value()), + (attempt_force_join ? std::numeric_limits::max() : miter_limit)); } } //namespace LivePathEffect diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index d17def471..b63a2bf01 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -662,6 +662,9 @@ LPEPowerStroke::doEffect_path (std::vector const & path_in) if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast(interpolator)) { johan->setBeta(interpolator_beta); } + if (Geom::Interpolate::CubicBezierSmooth *smooth = dynamic_cast(interpolator)) { + smooth->setBeta(interpolator_beta); + } Geom::Path strokepath = interpolator->interpolateToPath(ts); delete interpolator; diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 8316daf71..c29690d4f 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -34,6 +34,11 @@ #include "knot-holder-entity.h" #include "knotholder.h" +template +inline bool withinRange(T value, T low, T high) { + return (value > low && value < high); +} + namespace Inkscape { namespace LivePathEffect { @@ -65,12 +70,12 @@ static const Util::EnumDataConverter JoinTypeConverter(JoinType, sizeo LPETaperStroke::LPETaperStroke(LivePathEffectObject *lpeobject) : Effect(lpeobject), - line_width(_("Stroke width"), _("The (non-tapered) width of the path"), "stroke_width", &wr, this, 3), + line_width(_("Stroke width"), _("The (non-tapered) width of the path"), "stroke_width", &wr, this, 1.), attach_start(_("Start offset"), _("Taper distance from path start"), "attach_start", &wr, this, 0.2), attach_end(_("End offset"), _("The ending position of the taper"), "end_offset", &wr, this, 0.2), smoothing(_("Taper smoothing"), _("Amount of smoothing to apply to the tapers"), "smoothing", &wr, this, 0.5), join_type(_("Join type"), _("Join type for non-smooth nodes"), "jointype", JoinTypeConverter, &wr, this, LINEJOIN_EXTRAPOLATED), - miter_limit(_("Miter limit"), _("Limit for miter joins"), "miter_limit", &wr, this, 30.) + miter_limit(_("Miter limit"), _("Limit for miter joins"), "miter_limit", &wr, this, 100.) { show_orig_path = true; _provides_knotholder_entities = true; @@ -205,43 +210,47 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) unsigned size = path_in[0].size(); if (size == first_cusp.size()) { //check to see if the knots were dragged over each other - //if so, reset the end offset + //if so, reset the end offset, but still allow the start offset. if ( attach_start >= (size - attach_end) ) { attach_end.param_set_value( size - attach_start ); } } - if (attach_start == size - attach_end) { + if (attach_end == size - attach_start) { metInMiddle = true; } - //don't let it be zero - if (attach_start <= 0.00000001) { - attach_start.param_set_value( 0.00000001 ); - zeroStart = true; - } - if (attach_end <= 0.00000001) { - attach_end.param_set_value( 0.00000001 ); - zeroEnd = true; - } - //don't let it be integer - if (double(unsigned(attach_start)) == attach_start) { - attach_start.param_set_value(attach_start - 0.00001); - } - if (double(unsigned(attach_end)) == attach_end) { - attach_end.param_set_value(attach_end - 0.00001); + { + if (double(unsigned(attach_start)) == attach_start) { + attach_start.param_set_value(attach_start - 0.00001); + } + if (double(unsigned(attach_end)) == attach_end) { + attach_end.param_set_value(attach_end - 0.00001); + } } unsigned allowed_start = first_cusp.size(); unsigned allowed_end = last_cusp.size(); //don't let the knots be farther than they are allowed to be - if ((unsigned)attach_start >= allowed_start) { - attach_start.param_set_value((double)allowed_start - 0.00001); + { + if ((unsigned)attach_start >= allowed_start) { + attach_start.param_set_value((double)allowed_start - 0.00001); + } + if ((unsigned)attach_end >= allowed_end) { + attach_end.param_set_value((double)allowed_end - 0.00001); + } + } + + //don't let it be zero + if (attach_start < 0.0000001 || withinRange(double(attach_start), 0.00000001, 0.000001)) { + attach_start.param_set_value( 0.0000001 ); + zeroStart = true; } - if ((unsigned)attach_end >= allowed_end) { - attach_end.param_set_value((double)allowed_end - 0.00001); + if (attach_end < 0.0000001 || withinRange(double(attach_end), 0.00000001, 0.000001)) { + attach_end.param_set_value( 0.0000001 ); + zeroEnd = true; } //remember, Path::operator () means get point at time t @@ -252,7 +261,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) //the following function just splits it up into three pieces. pathv_out = doEffect_simplePath(path_in); - //now for the actual tapering. We use a Pattern Along Path method to get this done. + //now for the actual tapering. We use the stretch_along method to get this done. Geom::PathVector real_pathv; Geom::Path real_path; @@ -261,13 +270,13 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) Geom::Path throwaway_path; if (!zeroStart) { - //Construct the pattern (pat_str stands for pattern string) (yes, this is easier, trust me) + //Construct the pattern (pat_str stands for pattern string) (and yes, this is easier, trust me) std::stringstream pat_str; pat_str << "M 1,0 C " << 1 - (double)smoothing << ",0 0,0.5 0,0.5 0,0.5 " << 1 - (double)smoothing << ",1 1,1"; pat_vec = sp_svg_read_pathv(pat_str.str().c_str()); pwd2.concat(stretch_along(pathv_out[0].toPwSb(), pat_vec[0], -fabs(line_width))); - throwaway_path = Geom::path_from_piecewise(pwd2, 0.001)[0]; + throwaway_path = Geom::path_from_piecewise(pwd2, LPE_CONVERSION_TOLERANCE)[0]; real_path.append(throwaway_path); } @@ -276,29 +285,52 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) //append the outside outline of the path (with direction) throwaway_path = Outline::PathOutsideOutline(pathv_out[1], -fabs(line_width), static_cast(join_type.get_value()), miter_limit); - - real_path.append(throwaway_path, Geom::Path::STITCH_DISCONTINUOUS); + if (!zeroStart) { + if (Geom::distance(real_path.finalPoint(), throwaway_path.initialPoint()) > 0.0000001) { + real_path.appendNew(throwaway_path.initialPoint()); + } else { + real_path.setFinal(throwaway_path.initialPoint()); + } + } + real_path.append(throwaway_path); } if (!zeroEnd) { //append the ending taper std::stringstream pat_str_1; - pat_str_1 << "M 0,0 0,1 C " << (double)smoothing << ",1 1,0.5 1,0.5 1,0.5 " << double(smoothing) << ",0 0,0"; + pat_str_1 << "M 0,1 C " << (double)smoothing << ",1 1,0.5 1,0.5 1,0.5 " << double(smoothing) << ",0 0,0"; pat_vec = sp_svg_read_pathv(pat_str_1.str().c_str()); pwd2 = Geom::Piecewise > (); pwd2.concat(stretch_along(pathv_out[2].toPwSb(), pat_vec[0], -fabs(line_width))); - throwaway_path = Geom::path_from_piecewise(pwd2, 0.001)[0]; - real_path.append(throwaway_path, Geom::Path::STITCH_DISCONTINUOUS); + throwaway_path = Geom::path_from_piecewise(pwd2, LPE_CONVERSION_TOLERANCE)[0]; + if (Geom::distance(real_path.finalPoint(), throwaway_path.initialPoint()) > 0.0000001) { + real_path.appendNew(throwaway_path.initialPoint()); + } else { + real_path.setFinal(throwaway_path.initialPoint()); + } + real_path.append(throwaway_path); + } + + if (!metInMiddle) { + //append the inside outline of the path (against direction) + throwaway_path = Outline::PathOutsideOutline(pathv_out[1].reverse(), + -fabs(line_width), static_cast(join_type.get_value()), miter_limit); + + if (Geom::distance(real_path.finalPoint(), throwaway_path.initialPoint()) > 0.0000001) { + real_path.appendNew(throwaway_path.initialPoint()); + } else { + real_path.setFinal(throwaway_path.initialPoint()); + } + real_path.append(throwaway_path); + } + + if (Geom::distance(real_path.finalPoint(), real_path.initialPoint()) > 0.0000001) { + real_path.appendNew(real_path.initialPoint()); + } else { + real_path.setFinal(real_path.initialPoint()); } - //append the inside outline of the path (against direction) - throwaway_path = Outline::PathOutsideOutline(pathv_out[1].reverse(), - -fabs(line_width), static_cast(join_type.get_value()), miter_limit); - - real_path.append(throwaway_path, Geom::Path::STITCH_DISCONTINUOUS); - real_path.appendNew(real_path.initialPoint()); - real_path.close(); real_pathv.push_back(real_path); diff --git a/src/live_effects/pathoutlineprovider.cpp b/src/live_effects/pathoutlineprovider.cpp index b5a3258fa..9ff896f84 100644 --- a/src/live_effects/pathoutlineprovider.cpp +++ b/src/live_effects/pathoutlineprovider.cpp @@ -162,8 +162,7 @@ bool outside_angle (const Geom::Curve& cbc1, const Geom::Curve& cbc2) //assert(cbc1.finalPoint() == cbc2.initialPoint()); //short circuiting? if (cbc1.finalPoint() != cbc2.initialPoint()) { - printf("There was an issue when asserting that one curve's end is the start of the other. Line %d, File %s\n" - "By default we are going to say that this is an inside join, so we cannot make a line join for it.\n", __LINE__, __FILE__); + printf("erk! Line %d, File %s\n", __LINE__, __FILE__); return false; } @@ -261,7 +260,10 @@ void extrapolate_curves(Geom::Path& path_builder, Geom::Curve* cbc1, Geom::Curve } path_builder.appendNew (endPt); } - path_builder.append(*cbc2, Geom::Path::STITCH_DISCONTINUOUS); + if (cbc1->finalPoint() != cbc2->initialPoint()) { + path_builder.appendNew(cbc2->initialPoint()); + } + path_builder.append(*cbc2); } if ( outside && lineProblem ) { Geom::Path pth; @@ -283,7 +285,10 @@ void extrapolate_curves(Geom::Path& path_builder, Geom::Curve* cbc1, Geom::Curve } } path_builder.appendNew (endPt); - path_builder.append(*cbc2, Geom::Path::STITCH_DISCONTINUOUS); + if (cbc1->finalPoint() != cbc2->initialPoint()) { + path_builder.appendNew(cbc2->initialPoint()); + } + path_builder.append(*cbc2); } if ( !outside ) { /*path_builder.appendNew (endPt);*/ @@ -297,7 +302,12 @@ void extrapolate_curves(Geom::Path& path_builder, Geom::Curve* cbc1, Geom::Curve cubic = cubic.subdivide(cross[0].tb).second; path_builder.append(cubic, Geom::Path::STITCH_DISCONTINUOUS); } else { - path_builder.append(*cbc2, Geom::Path::STITCH_DISCONTINUOUS); + if (Geom::distance(path_builder.finalPoint(), cbc2->initialPoint()) > 0.0000001) { + path_builder.appendNew(cbc2->initialPoint()); + } else { + path_builder.setFinal(cbc2->initialPoint()); + } + path_builder.append(*cbc2); } } } @@ -360,6 +370,9 @@ void reflect_curves(Geom::Path& path_builder, Geom::Curve* cbc1, Geom::Curve* cb path_builder.appendNew (sub1.first[1], sub1.first[2], /*sub1.first[3]*/ sub2.second[0] ); path_builder.appendNew (sub2.second[1], sub2.second[2], /*sub2.second[3]*/ endPt ); } + if (cbc1->finalPoint() != cbc2->initialPoint()) { + path_builder.appendNew(cbc2->initialPoint()); + } path_builder.append(*cbc2); } else { //probably on the inside of the corner @@ -374,7 +387,12 @@ void reflect_curves(Geom::Path& path_builder, Geom::Curve* cbc1, Geom::Curve* cb cubic = cubic.subdivide(cross[0].tb).second; path_builder.append(cubic, Geom::Path::STITCH_DISCONTINUOUS); } else { - path_builder.append(*cbc2, Geom::Path::STITCH_DISCONTINUOUS); + if (Geom::distance(path_builder.finalPoint(), cbc2->initialPoint()) > 0.0000001) { + path_builder.appendNew(cbc2->initialPoint()); + } else { + path_builder.setFinal(cbc2->initialPoint()); + } + path_builder.append(*cbc2); } } } @@ -431,6 +449,7 @@ Geom::Path doAdvHalfOutline(const Geom::Path& path_in, double line_width, double } //store it Geom::Path temp_path = (*path_vec)[0]; + //erase the first segment since the join code already appended it temp_path.erase(temp_path.begin()); path_builder.append( temp_path ); @@ -477,7 +496,7 @@ Geom::Path doAdvHalfOutline(const Geom::Path& path_in, double line_width, double Geom::Curve * cbc1; Geom::Curve * cbc2; - if ( path_in[path_in.size() - 1].length() != Geom::distance(path_in[path_in.size() - 1].finalPoint(), path_in.initialPoint())) { + if ( path_in[path_in.size()].isDegenerate() ) { //handle case for last segment curved outlined_result = Path(); to_outline = Path(); @@ -512,10 +531,10 @@ Geom::Path doAdvHalfOutline(const Geom::Path& path_in, double line_width, double if (extrapolate) { extrapolate_curves(path_builder, cbc1, cbc2, cbc2->initialPoint(), miter_limit, line_width, - outside_angle ( path_in[path_in.size() - 1], path_in [0] )); + outside_angle ( path_in[path_in.size() - 1], oneCurve [0] )); } else { reflect_curves (path_builder, cbc1, cbc2, cbc2->initialPoint(), miter_limit, line_width, - outside_angle ( path_in[path_in.size() - 1], path_in [0] )); + outside_angle ( path_in[path_in.size() - 1], oneCurve [0] )); } delete cbc1; cbc1 = cbc2->duplicate(); @@ -534,22 +553,29 @@ Geom::Path doAdvHalfOutline(const Geom::Path& path_in, double line_width, double Geom::Path temporary; //just an accessory path, we won't need it for long temporary.append(*cbc1); + const Geom::Curve& prev_curve = path_in[path_in.size()].isDegenerate() ? path_in[path_in.size() - 1] : + path_in[path_in.size()]; + if (extrapolate) { extrapolate_curves(temporary, cbc1, cbc2, cbc2->initialPoint(), miter_limit, line_width, - outside_angle ( path_in[path_in.size() - 1], path_in [0] )); + outside_angle ( prev_curve, path_in [0] )); } else { reflect_curves (temporary, cbc1, cbc2, cbc2->initialPoint(), miter_limit, line_width, - outside_angle ( path_in[path_in.size() - 1], path_in [0] )); + outside_angle ( prev_curve, path_in [0] )); } //extract the appended curves - if (temporary[0].finalPoint() != path_builder[path_builder.size() - 1].finalPoint()) { + //if (temporary[temporary.size()].initialPoint() != path_builder[0].initialPoint()) { path_builder.erase(path_builder.begin()); - } else { + /*} else { temporary.erase_last(); - } + }*/ path_builder.erase_last(); - - path_builder.append(temporary, Geom::Path::STITCH_DISCONTINUOUS); + if (Geom::distance(path_builder.finalPoint(), temporary.initialPoint()) > 0.0000001) { + path_builder.appendNew(temporary.initialPoint()); + } else { + path_builder.setFinal(temporary.initialPoint()); + } + path_builder.append(temporary); path_builder.close(); if (cbc1) delete cbc1; -- cgit v1.2.3