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