Code

New LPE: Ruler
[inkscape.git] / src / live_effects / lpe-ruler.cpp
1 #define INKSCAPE_LPE_RULER_CPP
3 /** \file
4  * LPE <ruler> implementation, see lpe-ruler.cpp.
5  */
7 /*
8  * Authors:
9  *   Maximilian Albert
10  *   Johan Engelen
11  *
12  * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include "live_effects/lpe-ruler.h"
18 #include <2geom/piecewise.h>
20 namespace Inkscape {
21 namespace LivePathEffect {
23 LPERuler::LPERuler(LivePathEffectObject *lpeobject) :
24     Effect(lpeobject),
25     mark_distance(_("Mark distance"), _("Distance between ruler marks"), "mark_distance", &wr, this, 50),
26     mark_length(_("Mark length"), _("Length of ruler marks"), "mark_length", &wr, this, 10)
27 {
28     registerParameter(dynamic_cast<Parameter *>(&mark_distance));
29     registerParameter(dynamic_cast<Parameter *>(&mark_length));
31     mark_distance.param_make_integer();
32     mark_length.param_make_integer();
33 }
35 LPERuler::~LPERuler()
36 {
38 }
40 Geom::Piecewise<Geom::D2<Geom::SBasis> >
41 LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
42 {
43     using namespace Geom;
45     Point A(pwd2_in.firstValue());
46     Point B(pwd2_in.lastValue());
48     Piecewise<D2<SBasis> >output(D2<SBasis>(Linear(A[X], B[X]), Linear(A[Y], B[Y])));
50     Point dir(unit_vector(B - A));
51     Point n(-rot90(dir) * mark_length);
52     double length = L2(B - A);
54     Point C, D;
55     for (int i = 0; i < length; i+=mark_distance) {
56         C = A + dir * i;
57         D = C + n;
58         Piecewise<D2<SBasis> > seg(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
59         output.concat(seg);
60     }
62     return output;
63 }
65 /* ######################## */
67 } //namespace LivePathEffect
68 } /* namespace Inkscape */
70 /*
71   Local Variables:
72   mode:c++
73   c-file-style:"stroustrup"
74   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
75   indent-tabs-mode:nil
76   fill-column:99
77   End:
78 */
79 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :