Code

c744f126856d0484293974e721cddb37ec8c799c
[inkscape.git] / src / live_effects / lpe-perp_bisector.cpp
1 #define INKSCAPE_LPE_PERP_BISECTOR_CPP
2 /** \file
3  * LPE <perp_bisector> implementation.
4  */
5 /*
6  * Authors:
7  *   Maximilian Albert
8  *   Johan Engelen
9  *
10  * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
11  * Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com>
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #include "live_effects/lpe-perp_bisector.h"
17 #include "display/curve.h"
18 #include <libnr/n-art-bpath.h>
20 #include <2geom/path.h>
22 namespace Inkscape {
23 namespace LivePathEffect {
25 LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) :
26     Effect(lpeobject),
27     length_left(_("Length left"), _(""), "length-left", &wr, this, 200),
28     length_right(_("Length right"), _(""), "length-right", &wr, this, 200)
29 {
30     registerParameter( dynamic_cast<Parameter *>(&length_left) );
31     registerParameter( dynamic_cast<Parameter *>(&length_right) );
32 }
34 LPEPerpBisector::~LPEPerpBisector()
35 {
37 }
39 Geom::Point LPEPerpBisector::left_end(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) {
40     Geom::Point A(pwd2_in.firstValue());
41     Geom::Point B(pwd2_in.lastValue());
42     Geom::Point M((A + B)/2);
44     Geom::Point dir1((B - M).ccw());
46     if (dir1.length() > Geom::EPSILON)
47         dir1 = Geom::unit_vector(dir1) * length_left;
49     return M + dir1;
50 }
52 Geom::Piecewise<Geom::D2<Geom::SBasis> >
53 LPEPerpBisector::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
54 {
55     using namespace Geom;
57     Piecewise<D2<SBasis> > output;
59     Point A(pwd2_in.firstValue());
60     Point B(pwd2_in.lastValue());
61     Point M((A + B)/2);
63     Point dir1((B - M).ccw());
64     Point dir2((A - M).ccw());
66     if (dir1.length() > EPSILON)
67         dir1 = unit_vector(dir1) * length_left;
69     if (dir2.length() > EPSILON)
70         dir2 = unit_vector(dir2) * length_right;
72     Point C(M + dir1);
73     Point D(M + dir2);
75     output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
77     return output;
78 }
80 /* ######################## */
82 } //namespace LivePathEffect
83 } /* namespace Inkscape */
85 /*
86   Local Variables:
87   mode:c++
88   c-file-style:"stroustrup"
89   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
90   indent-tabs-mode:nil
91   fill-column:99
92   End:
93 */
94 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :