1 /**
2 * \file lpe-test.cpp
3 * \brief Example file showing how to write an Inkscape Live Path Effect toy.
4 */
5 /*
6 * Copyright 2009 Johan Engelen <goejendaagh@zonnet.nl>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it either under the terms of the GNU Lesser General Public
10 * License version 2.1 as published by the Free Software Foundation
11 * (the "LGPL") or, at your option, under the terms of the Mozilla
12 * Public License Version 1.1 (the "MPL"). If you do not alter this
13 * notice, a recipient may use your version of this file under either
14 * the MPL or the LGPL.
15 *
16 * You should have received a copy of the LGPL along with this library
17 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * You should have received a copy of the MPL along with this library
20 * in the file COPYING-MPL-1.1
21 *
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License at
25 * http://www.mozilla.org/MPL/
26 *
27 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
28 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
29 * the specific language governing rights and limitations.
30 *
31 */
32
33 #include <toys/lpe-framework.h>
34
35 // This is usually very bad practice: don't do it in your LPE
36 using std::vector;
37 using namespace Geom;
38 using namespace std;
39
40 class LPETest: public LPEToy {
41 public:
LPETest()42 LPETest() {
43 concatenate_before_pwd2 = false;
44 }
45
46 Geom::Piecewise<Geom::D2<Geom::SBasis> >
doEffect_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis>> const & pwd2_in)47 doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) override
48 {
49 using namespace Geom;
50
51 Piecewise<D2<SBasis> > pwd2_out = pwd2_in;
52
53 Point vector(50,100);
54 // generate extrusion bottom: (just a copy of original path, displaced a bit)
55 pwd2_out.concat( pwd2_in + vector );
56
57 // generate connecting lines (the 'sides' of the extrusion)
58 Path path(Point(0.,0.));
59 path.appendNew<Geom::LineSegment>( vector );
60 Piecewise<D2<SBasis> > connector = path.toPwSb();
61 // connecting lines should be put at cusps
62 Piecewise<D2<SBasis> > deriv = derivative(pwd2_in);
63 std::vector<double> cusps; // = roots(deriv);
64 for (double cusp : cusps) {
65 pwd2_out.concat( connector + pwd2_in.valueAt(cusp) );
66 }
67 // connecting lines should be put where the tangent of the path equals the extrude_vector in direction
68 std::vector<double> rts = roots(dot(deriv, rot90(vector)));
69 for (double rt : rts) {
70 pwd2_out.concat( connector + pwd2_in.valueAt(rt) );
71 }
72
73 return pwd2_out;
74 }
75 };
76
main(int argc,char ** argv)77 int main(int argc, char **argv) {
78 init(argc, argv, new LPETest);
79 return 0;
80 }
81
82 /*
83 Local Variables:
84 mode:c++
85 c-file-style:"stroustrup"
86 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
87 indent-tabs-mode:nil
88 fill-column:99
89 End:
90 */
91 //vim:expandtab:shiftwidth = 4:tabstop = 8:softtabstop = 4:encoding = utf-8:textwidth = 99 :
92
93
94