Code

powerstroke: redefine meaning of offset point parameter values. now knots move with...
authorJohan Engelen <goejendaagh@zonnet.nl>
Fri, 30 Jul 2010 22:52:27 +0000 (00:52 +0200)
committerJohan Engelen <goejendaagh@zonnet.nl>
Fri, 30 Jul 2010 22:52:27 +0000 (00:52 +0200)
src/live_effects/lpe-powerstroke.cpp
src/live_effects/parameter/powerstrokepointarray.cpp
src/live_effects/parameter/powerstrokepointarray.h

index addddd06f25a369d01bdf37911c628a3479e8ede..68cdac115d13c9830f3edec399a9f5a8b50c37e8 100644 (file)
@@ -133,6 +133,8 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
 {
     show_orig_path = true;
 
+    /// @todo offset_points are initialized with empty path, is that bug-save?
+
     registerParameter( dynamic_cast<Parameter *>(&offset_points) );
     registerParameter( dynamic_cast<Parameter *>(&sort_points) );
 }
@@ -147,10 +149,10 @@ void
 LPEPowerStroke::doOnApply(SPLPEItem *lpeitem)
 {
     std::vector<Geom::Point> points;
-    points.push_back( *(SP_SHAPE(lpeitem)->curve->first_point()) );
-    Geom::Path const *path = SP_SHAPE(lpeitem)->curve->first_path();
-    points.push_back( path->pointAt(path->size()/2) );
-    points.push_back( *(SP_SHAPE(lpeitem)->curve->last_point()) );
+    Geom::Path::size_type size = SP_SHAPE(lpeitem)->curve->get_pathvector().front().size_open();
+    points.push_back( Geom::Point(0,0) );
+    points.push_back( Geom::Point(0.5*size,0) );
+    points.push_back( Geom::Point(size,0) );
     offset_points.param_set_and_write_new_value(points);
 }
 
@@ -165,15 +167,15 @@ LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
 {
     using namespace Geom;
 
+    offset_points.set_pwd2(pwd2_in);
+
     // perhaps use std::list instead of std::vector?
     std::vector<Geom::Point> ts(offset_points.data().size() + 2);
     // first and last point coincide with input path (for now at least)
     ts.front() = Point(pwd2_in.domain().min(),0);
     ts.back()  = Point(pwd2_in.domain().max(),0);
     for (unsigned int i = 0; i < offset_points.data().size(); ++i) {
-        double t = nearest_point(offset_points.data().at(i), pwd2_in);
-        double offset = L2(pwd2_in.valueAt(t) - offset_points.data().at(i));
-        ts.at(i+1) = Geom::Point(t, offset);
+        ts.at(i+1) = offset_points.data().at(i);
     }
 
     if (sort_points) {
@@ -192,7 +194,8 @@ LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
     Piecewise<SBasis> y = Piecewise<SBasis>(patternd2[1]);
 
     Piecewise<D2<SBasis> > der = unitVector(derivative(pwd2_in));
-    Piecewise<D2<SBasis> > n   = rot90(der);
+    Piecewise<D2<SBasis> > n = rot90(der);
+    offset_points.set_pwd2_normal(n);
 
 //    output  = pwd2_in + n * offset;
 //    append_half_circle(output, pwd2_in.lastValue(), n.lastValue() * offset);
index 99c32720729876935d9b32a38665720188287b57..c209801933242dc540c545fb3cf016fae3421293 100644 (file)
 #include "live_effects/effect.h"
 #include "svg/svg.h"
 #include "svg/stringstream.h"
-#include <gtkmm.h>
-#include "ui/widget/point.h"
-#include "widgets/icon.h"
-#include "ui/widget/registered-widget.h"
-#include "inkscape.h"
-#include "verbs.h"
 #include "knotholder.h"
+#include "sp-lpe-item.h"
+
+#include <2geom/piecewise.h>
+#include <2geom/sbasis-geometric.h>
 
 // needed for on-canvas editting:
 #include "desktop.h"
@@ -110,16 +108,28 @@ PowerStrokePointArrayParamKnotHolderEntity::PowerStrokePointArrayParamKnotHolder
 void
 PowerStrokePointArrayParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
 {
+/// @todo how about item transforms???
+    using namespace Geom;
+    Piecewise<D2<SBasis> > const & pwd2 = _pparam->get_pwd2();
+    Piecewise<D2<SBasis> > const & n = _pparam->get_pwd2_normal();
+
     Geom::Point const s = snap_knot_position(p);
-    _pparam->_vector.at(_index) = s;
-//    _pparam->param_set_and_write_new_value(_pparam->_vector);
+    double t = nearest_point(s, pwd2);
+    double offset = dot(s - pwd2.valueAt(t), n.valueAt(t));
+    _pparam->_vector.at(_index) = Geom::Point(t, offset);
     sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
 }
 
 Geom::Point
 PowerStrokePointArrayParamKnotHolderEntity::knot_get()
 {
-    Geom::Point canvas_point = _pparam->_vector.at(_index);
+    using namespace Geom;
+    Piecewise<D2<SBasis> > const & pwd2 = _pparam->get_pwd2();
+    Piecewise<D2<SBasis> > const & n = _pparam->get_pwd2_normal();
+
+    Point offset_point = _pparam->_vector.at(_index);
+
+    Point canvas_point = pwd2.valueAt(offset_point[X]) + offset_point[Y] * n.valueAt(offset_point[X]);
     return canvas_point;
 }
 
index 66eb3c9877fa78053e9e8e37c736fff0cdddde87..06d406dfe9d337afa7b1762a889cbbbe344bf43f 100644 (file)
@@ -43,6 +43,11 @@ public:
     virtual bool providesKnotHolderEntities() { return true; }
     virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
 
+    void set_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) { last_pwd2 = pwd2_in; }
+    Geom::Piecewise<Geom::D2<Geom::SBasis> > const & get_pwd2() { return last_pwd2; }
+    void set_pwd2_normal(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) { last_pwd2_normal = pwd2_in; }
+    Geom::Piecewise<Geom::D2<Geom::SBasis> > const & get_pwd2_normal() { return last_pwd2_normal; }
+
     friend class PowerStrokePointArrayParamKnotHolderEntity;
 
 private:
@@ -53,6 +58,9 @@ private:
     SPKnotModeType knot_mode;
     guint32 knot_color;
     gchar *handle_tip;
+
+    Geom::Piecewise<Geom::D2<Geom::SBasis> > last_pwd2;
+    Geom::Piecewise<Geom::D2<Geom::SBasis> > last_pwd2_normal;
 };