From 0bc4d63d9f8840bb1db75f1a23db3b159f6612a2 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Tue, 27 Jul 2010 22:30:10 +0200 Subject: [PATCH] powerstroke: sort point option --- src/live_effects/lpe-powerstroke.cpp | 14 +++++++++++++- src/live_effects/lpe-powerstroke.h | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index da2b9d6a9..cb45e0518 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -26,11 +26,13 @@ namespace LivePathEffect { LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) : Effect(lpeobject), - offset_points(_("Offset points"), _("Offset points"), "offset_points", &wr, this) + offset_points(_("Offset points"), _("Offset points"), "offset_points", &wr, this), + sort_points(_("Sort points"), _("Sort offset points according to their time value along the curve."), "sort_points", &wr, this, true) { show_orig_path = true; registerParameter( dynamic_cast(&offset_points) ); + registerParameter( dynamic_cast(&sort_points) ); } LPEPowerStroke::~LPEPowerStroke() @@ -60,11 +62,18 @@ static void append_half_circle(Geom::Piecewise > &pwd2, pwd2.continuousConcat(cap_pwd2); } +static bool compare_offsets (Geom::Point first, Geom::Point second) +{ + return first[Geom::X] <= second[Geom::X]; +} + + Geom::Piecewise > LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { using namespace Geom; + // perhaps use std::list instead of std::vector? std::vector ts(offset_points.data().size()); for (unsigned int i; i < ts.size(); ++i) { @@ -72,6 +81,9 @@ LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise > const & double offset = L2(pwd2_in.valueAt(t) - offset_points.data().at(i)); ts.at(i) = Geom::Point(t, offset); } + if (sort_points) { + sort(ts.begin(), ts.end(), compare_offsets); + } // create stroke path where points (x,y) = (t, offset) Path strokepath; diff --git a/src/live_effects/lpe-powerstroke.h b/src/live_effects/lpe-powerstroke.h index 66b2ab89f..6c208fda4 100644 --- a/src/live_effects/lpe-powerstroke.h +++ b/src/live_effects/lpe-powerstroke.h @@ -13,7 +13,7 @@ #define INKSCAPE_LPE_POWERSTROKE_H #include "live_effects/effect.h" -#include "live_effects/parameter/point.h" +#include "live_effects/parameter/bool.h" #include "live_effects/parameter/powerstrokepointarray.h" namespace Inkscape { @@ -30,6 +30,7 @@ public: private: PowerStrokePointArrayParam offset_points; + BoolParam sort_points; LPEPowerStroke(const LPEPowerStroke&); LPEPowerStroke& operator=(const LPEPowerStroke&); -- 2.30.2