Code

New LPE: Circle (with center at the first point and passing through the last point...
[inkscape.git] / src / live_effects / lpe-circle_with_radius.cpp
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"
24 #include <libnr/n-art-bpath.h>
26 // You might need to include other 2geom files. You can add them here:
27 #include <2geom/path.h>
28 #include <2geom/sbasis.h>
29 #include <2geom/bezier-to-sbasis.h>
30 #include <2geom/d2.h>
32 using namespace Geom;
34 namespace Inkscape {
35 namespace LivePathEffect {
37 LPECircleWithRadius::LPECircleWithRadius(LivePathEffectObject *lpeobject) :
38     Effect(lpeobject)//,
39     // initialise your parameters here:
40     //radius(_("Float parameter"), _("just a real number like 1.4!"), "svgname", &wr, this, 50)
41 {
42     // register all your parameters here, so Inkscape knows which parameters this effect has:
43     //registerParameter( dynamic_cast<Parameter *>(&radius) );
44 }
46 LPECircleWithRadius::~LPECircleWithRadius()
47 {
49 }
52 /* ########################
53  *  Choose to implement one of the doEffect functions. You can delete or comment out the others.
54 */
56 D2<SBasis> _circle(Geom::Point center, double radius) {
57     D2<SBasis> B;
58     Linear bo = Linear(0, 2 * M_PI);
60     B[0] = cos(bo,2);
61     B[1] = sin(bo,2);
63     B = B*radius + center;
64     return B;
65 }
67 std::vector<Geom::Path>
68 LPECircleWithRadius::doEffect_path (std::vector<Geom::Path> & path_in)
69 {
70     std::vector<Geom::Path> path_out = std::vector<Geom::Path>();
71     Geom::Path pb;
73     Geom::Point center = path_in[0].initialPoint();
74     Geom::Point pt = path_in[0].finalPoint();
76     double radius = Geom::L2(pt - center);
78     pb.append(SBasisCurve(_circle(center, radius)));
80     path_out.push_back(pb);
82     return path_out;
83 }
85 /*
87 Geom::Piecewise<Geom::D2<Geom::SBasis> >
88 LPECircleWithRadius::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
89 {
90     Geom::Piecewise<Geom::D2<Geom::SBasis> > output;
92     output = pwd2_in;   // spice this up to make the effect actually *do* something!
94     return output;
95 }
97 */
99 /* ######################## */
101 } //namespace LivePathEffect
102 } /* namespace Inkscape */
104 /*
105   Local Variables:
106   mode:c++
107   c-file-style:"stroustrup"
108   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
109   indent-tabs-mode:nil
110   fill-column:99
111   End:
112 */
113 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :