8b169af3c496360f6ef678b3090d4dfb23d0c561
1 #define INKSCAPE_LPE_CIRCLE_WITH_RADIUS_CPP
2 /** \file
3 * LPE <circle_with_radius> implementation, used as an example for a base starting class
4 * when implementing new LivePathEffects.
5 *
6 * In vi, three global search-and-replaces will let you rename everything
7 * in this and the .h file:
8 *
9 * :%s/CIRCLE_WITH_RADIUS/YOURNAME/g
10 * :%s/CircleWithRadius/Yourname/g
11 * :%s/circle_with_radius/yourname/g
12 */
13 /*
14 * Authors:
15 * Johan Engelen
16 *
17 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
18 *
19 * Released under GNU GPL, read the file 'COPYING' for more information
20 */
22 #include "live_effects/lpe-circle_with_radius.h"
23 #include "display/curve.h"
25 // You might need to include other 2geom files. You can add them here:
26 #include <2geom/path.h>
27 #include <2geom/sbasis.h>
28 #include <2geom/bezier-to-sbasis.h>
29 #include <2geom/d2.h>
31 using namespace Geom;
33 namespace Inkscape {
34 namespace LivePathEffect {
36 LPECircleWithRadius::LPECircleWithRadius(LivePathEffectObject *lpeobject) :
37 Effect(lpeobject)//,
38 // initialise your parameters here:
39 //radius(_("Float parameter"), _("just a real number like 1.4!"), "svgname", &wr, this, 50)
40 {
41 // register all your parameters here, so Inkscape knows which parameters this effect has:
42 //registerParameter( dynamic_cast<Parameter *>(&radius) );
43 }
45 LPECircleWithRadius::~LPECircleWithRadius()
46 {
48 }
50 void _circle(Geom::Point center, double radius, std::vector<Geom::Path> &path_out) {
51 Geom::Path pb;
53 D2<SBasis> B;
54 Linear bo = Linear(0, 2 * M_PI);
56 B[0] = cos(bo,4);
57 B[1] = sin(bo,4);
59 B = B * radius + center;
61 pb.append(SBasisCurve(B));
63 path_out.push_back(pb);
64 }
66 std::vector<Geom::Path>
67 LPECircleWithRadius::doEffect_path (std::vector<Geom::Path> const & path_in)
68 {
69 std::vector<Geom::Path> path_out = std::vector<Geom::Path>();
71 Geom::Point center = path_in[0].initialPoint();
72 Geom::Point pt = path_in[0].finalPoint();
74 double radius = Geom::L2(pt - center);
76 _circle(center, radius, path_out);
78 return path_out;
79 }
81 /*
83 Geom::Piecewise<Geom::D2<Geom::SBasis> >
84 LPECircleWithRadius::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
85 {
86 Geom::Piecewise<Geom::D2<Geom::SBasis> > output;
88 output = pwd2_in; // spice this up to make the effect actually *do* something!
90 return output;
91 }
93 */
95 /* ######################## */
97 } //namespace LivePathEffect
98 } /* namespace Inkscape */
100 /*
101 Local Variables:
102 mode:c++
103 c-file-style:"stroustrup"
104 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
105 indent-tabs-mode:nil
106 fill-column:99
107 End:
108 */
109 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :