Code

warning cleanup
[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     g_print ("Distance: %8.2f\n", length);
56     Point C, D;
57     for (int i = 0; i < length; i += static_cast<int>(mark_distance)) {
58         C = A + dir * i;
59         D = C + n;
60         Piecewise<D2<SBasis> > seg(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
61         output.concat(seg);
62     }
64     return output;
65 }
67 /* ######################## */
69 } //namespace LivePathEffect
70 } /* namespace Inkscape */
72 /*
73   Local Variables:
74   mode:c++
75   c-file-style:"stroustrup"
76   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
77   indent-tabs-mode:nil
78   fill-column:99
79   End:
80 */
81 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :