1
#define INKSCAPE_LPE_ANGLE_BISECTOR_CPP
3
* LPE <angle_bisector> implementation, used as an example for a base starting class
4
* when implementing new LivePathEffects.
6
* In vi, three global search-and-replaces will let you rename everything
7
* in this and the .h file:
9
* :%s/ANGLE_BISECTOR/YOURNAME/g
10
* :%s/AngleBisector/Yourname/g
11
* :%s/angle_bisector/yourname/g
17
* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
19
* Released under GNU GPL, read the file 'COPYING' for more information
22
#include "live_effects/lpe-angle_bisector.h"
24
// You might need to include other 2geom files. You can add them here:
25
#include <2geom/path.h>
26
#include <2geom/sbasis-to-bezier.h>
29
namespace LivePathEffect {
33
class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity
36
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
37
virtual Geom::Point knot_get();
40
class KnotHolderEntityRightEnd : public LPEKnotHolderEntity
43
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
44
virtual Geom::Point knot_get();
49
LPEAngleBisector::LPEAngleBisector(LivePathEffectObject *lpeobject) :
51
length_left(_("Length left"), _("Specifies the left end of the bisector"), "length-left", &wr, this, 0),
52
length_right(_("Length right"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 250)
54
show_orig_path = true;
56
registerParameter( dynamic_cast<Parameter *>(&length_left) );
57
registerParameter( dynamic_cast<Parameter *>(&length_right) );
59
registerKnotHolderHandle(new AB::KnotHolderEntityLeftEnd(), _("Adjust the \"left\" end of the bisector"));
60
registerKnotHolderHandle(new AB::KnotHolderEntityRightEnd(), _("Adjust the \"right\" of the bisector"));
63
LPEAngleBisector::~LPEAngleBisector()
67
std::vector<Geom::Path>
68
LPEAngleBisector::doEffect_path (std::vector<Geom::Path> const & path_in)
72
std::vector<Geom::Path> path_out;
74
// we assume that the path has >= 3 nodes
75
ptA = path_in[0].pointAt(1);
76
Point B = path_in[0].initialPoint();
77
Point C = path_in[0].pointAt(2);
79
double angle = angle_between(B - ptA, C - ptA);
81
dir = unit_vector(B - ptA) * Rotate(angle/2);
83
Geom::Point D = ptA - dir * length_left;
84
Geom::Point E = ptA + dir * length_right;
86
Piecewise<D2<SBasis> > output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(D[X], E[X]), Linear(D[Y], E[Y])));
88
return path_from_piecewise(output, LPE_CONVERSION_TOLERANCE);
92
// TODO: make this more generic
93
static LPEAngleBisector *
94
get_effect(SPItem *item)
96
Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
97
if (effect->effectType() != ANGLE_BISECTOR) {
98
g_print ("Warning: Effect is not of type LPEAngleBisector!\n");
101
return static_cast<LPEAngleBisector *>(effect);
105
KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
107
LPEAngleBisector *lpe = get_effect(item);
109
Geom::Point const s = snap_knot_position(p);
111
double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir);
112
lpe->length_left.param_set_value(-lambda);
114
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
118
KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
120
LPEAngleBisector *lpe = get_effect(item);
122
Geom::Point const s = snap_knot_position(p);
124
double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir);
125
lpe->length_right.param_set_value(lambda);
127
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
131
KnotHolderEntityLeftEnd::knot_get()
133
LPEAngleBisector *lpe = get_effect(item);
134
return lpe->ptA - lpe->dir * lpe->length_left;
138
KnotHolderEntityRightEnd::knot_get()
140
LPEAngleBisector *lpe = get_effect(item);
141
return lpe->ptA + lpe->dir * lpe->length_right;
146
/* ######################## */
148
} //namespace LivePathEffect
149
} /* namespace Inkscape */
154
c-file-style:"stroustrup"
155
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
160
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :