From: Johan Engelen Date: Fri, 30 Jul 2010 22:52:27 +0000 (+0200) Subject: powerstroke: redefine meaning of offset point parameter values. now knots move with... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b7975890f78e083b615e80a9a9432ec8f79baf17;p=inkscape.git powerstroke: redefine meaning of offset point parameter values. now knots move with path --- diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index addddd06f..68cdac115 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -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(&offset_points) ); registerParameter( dynamic_cast(&sort_points) ); } @@ -147,10 +149,10 @@ void LPEPowerStroke::doOnApply(SPLPEItem *lpeitem) { std::vector 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 > const & { using namespace Geom; + offset_points.set_pwd2(pwd2_in); + // perhaps use std::list instead of std::vector? std::vector 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 > const & Piecewise y = Piecewise(patternd2[1]); Piecewise > der = unitVector(derivative(pwd2_in)); - Piecewise > n = rot90(der); + Piecewise > n = rot90(der); + offset_points.set_pwd2_normal(n); // output = pwd2_in + n * offset; // append_half_circle(output, pwd2_in.lastValue(), n.lastValue() * offset); diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp index 99c327207..c20980193 100644 --- a/src/live_effects/parameter/powerstrokepointarray.cpp +++ b/src/live_effects/parameter/powerstrokepointarray.cpp @@ -11,13 +11,11 @@ #include "live_effects/effect.h" #include "svg/svg.h" #include "svg/stringstream.h" -#include -#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 > const & pwd2 = _pparam->get_pwd2(); + Piecewise > 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 > const & pwd2 = _pparam->get_pwd2(); + Piecewise > 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; } diff --git a/src/live_effects/parameter/powerstrokepointarray.h b/src/live_effects/parameter/powerstrokepointarray.h index 66eb3c987..06d406dfe 100644 --- a/src/live_effects/parameter/powerstrokepointarray.h +++ b/src/live_effects/parameter/powerstrokepointarray.h @@ -43,6 +43,11 @@ public: virtual bool providesKnotHolderEntities() { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void set_pwd2(Geom::Piecewise > const & pwd2_in) { last_pwd2 = pwd2_in; } + Geom::Piecewise > const & get_pwd2() { return last_pwd2; } + void set_pwd2_normal(Geom::Piecewise > const & pwd2_in) { last_pwd2_normal = pwd2_in; } + Geom::Piecewise > 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 > last_pwd2; + Geom::Piecewise > last_pwd2_normal; };