Code

Translations. POTFILES.in, inkcape.pot and fr.po updated.
[inkscape.git] / src / live_effects / lpe-offset.cpp
1 #define INKSCAPE_LPE_OFFSET_CPP
2 /** \file
3  * LPE <offset> implementation
4  */
5 /*
6  * Authors:
7  *   Maximilian Albert
8  *
9  * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
10  * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "live_effects/lpe-offset.h"
16 #include "sp-shape.h"
17 #include "display/curve.h"
19 #include <2geom/path.h>
20 #include <2geom/piecewise.h>
21 #include <2geom/sbasis-geometric.h>
22 #include <2geom/svg-elliptical-arc.h>
23 #include <2geom/transforms.h>
25 namespace Inkscape {
26 namespace LivePathEffect {
28 LPEOffset::LPEOffset(LivePathEffectObject *lpeobject) :
29     Effect(lpeobject),
30     offset_pt(_("Offset"), _("Handle to control the distance of the offset from the curve"), "offset_pt", &wr, this)
31 {
32     show_orig_path = true;
34     registerParameter(dynamic_cast<Parameter *>(&offset_pt));
35 }
37 LPEOffset::~LPEOffset()
38 {
39 }
41 void
42 LPEOffset::doOnApply(SPLPEItem *lpeitem)
43 {
44     offset_pt.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->curve->first_point()));
45 }
47 static void append_half_circle(Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
48                                Geom::Point const center, Geom::Point const &dir) {
49     using namespace Geom;
51     double r = L2(dir);
52     SVGEllipticalArc cap(center + dir, r, r, angle_between(Point(1,0), dir), false, false, center - dir);
53     Piecewise<D2<SBasis> > cap_pwd2(cap.toSBasis());
54     pwd2.continuousConcat(cap_pwd2);
55 }
57 Geom::Piecewise<Geom::D2<Geom::SBasis> >
58 LPEOffset::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
59 {
60     using namespace Geom;
62     Piecewise<D2<SBasis> > output;
64     double t = nearest_point(offset_pt, pwd2_in);
65     Point A = pwd2_in.valueAt(t);
66     double offset = L2(A - offset_pt);
68     Piecewise<D2<SBasis> > der = unitVector(derivative(pwd2_in));
69     Piecewise<D2<SBasis> > n   = rot90(der);
71     output  = pwd2_in + n * offset;
72     append_half_circle(output, pwd2_in.lastValue(), n.lastValue() * offset);
73     output.continuousConcat(reverse(pwd2_in - n * offset));
74     append_half_circle(output, pwd2_in.firstValue(), -n.firstValue() * offset);
76     // TODO: here we should remove self-overlaps by applying the "union" boolop
77     //       but we'd need to convert the path to a Shape, which is currently
78     //       broken in 2geom, so we return the unaltered path
80     return output;
81 }
83 } //namespace LivePathEffect
84 } /* namespace Inkscape */
86 /*
87   Local Variables:
88   mode:c++
89   c-file-style:"stroustrup"
90   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
91   indent-tabs-mode:nil
92   fill-column:99
93   End:
94 */
95 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :