Code

powerstroke: sort point option
authorJohan Engelen <goejendaagh@zonnet.nl>
Tue, 27 Jul 2010 20:30:10 +0000 (22:30 +0200)
committerJohan Engelen <goejendaagh@zonnet.nl>
Tue, 27 Jul 2010 20:30:10 +0000 (22:30 +0200)
src/live_effects/lpe-powerstroke.cpp
src/live_effects/lpe-powerstroke.h

index da2b9d6a92c96a1b74fbbad1d7b68270e25243f1..cb45e0518faba0f4d4052534c44fc070ce680444 100644 (file)
@@ -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<Parameter *>(&offset_points) );
+    registerParameter( dynamic_cast<Parameter *>(&sort_points) );
 }
 
 LPEPowerStroke::~LPEPowerStroke()
@@ -60,11 +62,18 @@ static void append_half_circle(Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
     pwd2.continuousConcat(cap_pwd2);
 }
 
+static bool compare_offsets (Geom::Point first, Geom::Point second)
+{
+    return first[Geom::X] <= second[Geom::X];
+}
+
+
 Geom::Piecewise<Geom::D2<Geom::SBasis> >
 LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
 {
     using namespace Geom;
 
+    // perhaps use std::list instead of std::vector?
     std::vector<Geom::Point> ts(offset_points.data().size());
 
     for (unsigned int i; i < ts.size(); ++i) {
@@ -72,6 +81,9 @@ LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > 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;
index 66b2ab89fcf351adde321603afa31318ab0f7b41..6c208fda45a18c86d53058c9f8eced067b850227 100644 (file)
@@ -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&);