From: johanengelen Date: Sun, 27 Jul 2008 21:15:05 +0000 (+0000) Subject: lpe interpolate: fix traversal of trajectory_path. add option for equidistant_spacing X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b632ab726ddcf5acea122f867fef25decfb6dbe9;p=inkscape.git lpe interpolate: fix traversal of trajectory_path. add option for equidistant_spacing --- diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index f2ac17ef8..a4c722acc 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -1,6 +1,6 @@ #define INKSCAPE_LPE_INTERPOLATE_CPP /** \file - * LPE boolops implementation + * LPE interpolate implementation */ /* * Authors: @@ -17,6 +17,7 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/d2-sbasis.h> #include <2geom/piecewise.h> +#include <2geom/sbasis-geometric.h> #include "sp-path.h" #include "display/curve.h" @@ -26,13 +27,14 @@ namespace LivePathEffect { LPEInterpolate::LPEInterpolate(LivePathEffectObject *lpeobject) : Effect(lpeobject), - interpolate_path(_("Interpolate trajectory"), _("Path along which intermediate steps are created."), "trajectory", &wr, this, "M0,0 L0,0"), + trajectory_path(_("Trajectory"), _("Path along which intermediate steps are created."), "trajectory", &wr, this, "M0,0 L0,0"), number_of_steps(_("Steps"), _("Determines the number of steps from start to end path."), "steps", &wr, this, 5), - spacing(_("Spacing"), _("Determines the spacing between intermediate steps."), "spacing", &wr, this, 1) + equidistant_spacing(_("Equidistant spacing"), _("If true, the spacing between intermediates is constant along the length of the path. If false, the distance depends on the location of the nodes of the trajectory path."), "equidistant_spacing", &wr, this, true) { show_orig_path = true; - registerParameter( dynamic_cast(&interpolate_path) ); + registerParameter( dynamic_cast(&trajectory_path) ); + registerParameter( dynamic_cast(&equidistant_spacing) ); registerParameter( dynamic_cast(&number_of_steps) ); number_of_steps.param_make_integer(); @@ -67,14 +69,17 @@ LPEInterpolate::doEffect_path (Geom::PathVector const & path_in) Geom::Piecewise > pA = Geom::partition(pwd2_A, pwd2_B.cuts); Geom::Piecewise > pB = Geom::partition(pwd2_B, pwd2_A.cuts); - Geom::Path const &trajectory = interpolate_path.get_pathvector()[0]; - double trajectory_length = trajectory.size(); + Geom::Piecewise > trajectory = trajectory_path.get_pathvector()[0].toPwSb(); + if (equidistant_spacing) + trajectory = Geom::arc_length_parametrization(trajectory); + + Geom::Interval trajectory_domain = trajectory.domain(); for (int i = 0; i < number_of_steps; ++i) { double fraction = i / (number_of_steps-1); - Geom::Piecewise > pResult = pA*fraction + pB*(1-fraction); - pResult += trajectory.pointAt((1.-fraction)*trajectory_length); + Geom::Piecewise > pResult = pA*(1-fraction) + pB*fraction; + pResult += trajectory.valueAt(trajectory_domain.min() + fraction*trajectory_domain.extent()); Geom::PathVector pathv = Geom::path_from_piecewise(pResult, LPE_CONVERSION_TOLERANCE); path_out.push_back( pathv[0] ); @@ -101,7 +106,7 @@ LPEInterpolate::resetDefaults(SPItem * item) traj_pathv.push_back( Geom::Path() ); traj_pathv[0].start( bounds_A.midpoint() ); traj_pathv[0].appendNew( bounds_B.midpoint() ); - interpolate_path.set_new_value( traj_pathv, true ); + trajectory_path.set_new_value( traj_pathv, true ); } } //namespace LivePathEffect diff --git a/src/live_effects/lpe-interpolate.h b/src/live_effects/lpe-interpolate.h index 10d21e309..3091537f3 100644 --- a/src/live_effects/lpe-interpolate.h +++ b/src/live_effects/lpe-interpolate.h @@ -17,6 +17,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/path.h" +#include "live_effects/parameter/bool.h" namespace Inkscape { namespace LivePathEffect { @@ -30,9 +31,9 @@ public: virtual void resetDefaults(SPItem * item); private: - PathParam interpolate_path; + PathParam trajectory_path; ScalarParam number_of_steps; - ScalarParam spacing; + BoolParam equidistant_spacing; LPEInterpolate(const LPEInterpolate&); LPEInterpolate& operator=(const LPEInterpolate&);