X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flive_effects%2Flpe-tangent_to_curve.cpp;h=65948837fc3fb745f3738c5e0af9689e6cd6208f;hb=71146abe8aba032d73788a625fee5769a581bd3c;hp=e7344c9dcb33b1048cc2a127e6943f7e5e172021;hpb=bce2f84f17e5ee51d8222dc076ad013a68e58a7a;p=inkscape.git diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index e7344c9dc..65948837f 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -22,6 +22,7 @@ #include "libnr/n-art-bpath-2geom.h" #include <2geom/path.h> +#include <2geom/transforms.h> namespace Inkscape { namespace LivePathEffect { @@ -57,12 +58,54 @@ void attach_pt_set(SPItem *item, NR::Point const &p, NR::Point const &origin, gu sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), true); } +NR::Point left_end_get(SPItem *item) { + Inkscape::LivePathEffect::LPETangentToCurve *lpe = + (Inkscape::LivePathEffect::LPETangentToCurve *) sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item)); + + return lpe->C; +} + +NR::Point right_end_get(SPItem *item) { + Inkscape::LivePathEffect::LPETangentToCurve *lpe = + (Inkscape::LivePathEffect::LPETangentToCurve *) sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item)); + + return lpe->D; +} + +void left_end_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state) { + Inkscape::LivePathEffect::LPETangentToCurve *lpe = + (Inkscape::LivePathEffect::LPETangentToCurve *) sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item)); + + double lambda = Geom::nearest_point(p.to_2geom(), lpe->ptA, lpe->derivA); + lpe->length_left.param_set_value(-lambda); + + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), true); +} + +void right_end_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state) { + Inkscape::LivePathEffect::LPETangentToCurve *lpe = + (Inkscape::LivePathEffect::LPETangentToCurve *) sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item)); + + double lambda = Geom::nearest_point(p.to_2geom(), lpe->ptA, lpe->derivA); + lpe->length_right.param_set_value(lambda); + + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), true); +} + LPETangentToCurve::LPETangentToCurve(LivePathEffectObject *lpeobject) : Effect(lpeobject), - t_attach(_("Location along curve"), _("Location of the point of attachment along the curve (between 0.0 and number-of-segments)"), "t_attach", &wr, this, 0.5) + t_attach(_("Location along curve"), _("Location of the point of attachment along the curve (between 0.0 and number-of-segments)"), "t_attach", &wr, this, 0.5), + length_left(_("Length left"), _("Specifies the left end of the tangent"), "length-left", &wr, this, 150), + length_right(_("Length right"), _("Specifies the right end of the tangent"), "length-right", &wr, this, 150), + angle(_("Angle"), _("Additional angle between tangent and curve"), "angle", &wr, this, 0.0) { registerParameter( dynamic_cast(&t_attach) ); + registerParameter( dynamic_cast(&length_left) ); + registerParameter( dynamic_cast(&length_right) ); + registerParameter( dynamic_cast(&angle) ); registerKnotHolderHandle(attach_pt_set, attach_pt_get); + registerKnotHolderHandle(left_end_set, left_end_get); + registerKnotHolderHandle(right_end_set, right_end_get); } LPETangentToCurve::~LPETangentToCurve() @@ -78,10 +121,14 @@ LPETangentToCurve::doEffect_pwd2 (Geom::Piecewise > const ptA = pwd2_in.valueAt(t_attach); derivA = unit_vector(derivative(pwd2_in).valueAt(t_attach)); - Point A = ptA - derivA * 100; - Point B = ptA + derivA * 100; + // TODO: Why are positive angles measured clockwise, not counterclockwise? + Geom::Rotate rot(Geom::Rotate::from_degrees(-angle)); + derivA = derivA * rot; + + C = ptA - derivA * length_left; + D = ptA + derivA * length_right; - output = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); + output = Piecewise >(D2(Linear(C[X], D[X]), Linear(C[Y], D[Y]))); return output; }