1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /**
3 * @file
4 * Inspired by Hofstadter's 'Goedel Escher Bach', chapter V.
5 */
6 /* Authors:
7 * Johan Engelen <j.b.c.engelen@utwente.nl>
8 *
9 * Copyright (C) 2007-2009 Authors
10 *
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14 #include "live_effects/lpe-recursiveskeleton.h"
15
16 #include <2geom/bezier-to-sbasis.h>
17
18 // TODO due to internal breakage in glibmm headers, this must be last:
19 #include <glibmm/i18n.h>
20
21 namespace Inkscape {
22 namespace LivePathEffect {
23
LPERecursiveSkeleton(LivePathEffectObject * lpeobject)24 LPERecursiveSkeleton::LPERecursiveSkeleton(LivePathEffectObject *lpeobject) :
25 Effect(lpeobject),
26 iterations(_("Iterations:"), _("recursivity"), "iterations", &wr, this, 2)
27 {
28 show_orig_path = true;
29 concatenate_before_pwd2 = true;
30 iterations.param_make_integer(true);
31 iterations.param_set_range(1, 15);
32 registerParameter(&iterations);
33
34 }
35
36 LPERecursiveSkeleton::~LPERecursiveSkeleton()
37 = default;
38
39
40 Geom::Piecewise<Geom::D2<Geom::SBasis> >
doEffect_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis>> const & pwd2_in)41 LPERecursiveSkeleton::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
42 {
43 using namespace Geom;
44
45 Piecewise<D2<SBasis> > output;
46 double prop_scale = 1.0;
47
48 D2<Piecewise<SBasis> > patternd2 = make_cuts_independent(pwd2_in);
49 Piecewise<SBasis> x0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[1]) : Piecewise<SBasis>(patternd2[0]);
50 Piecewise<SBasis> y0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[0]) : Piecewise<SBasis>(patternd2[1]);
51 OptInterval pattBndsX = bounds_exact(x0);
52 OptInterval pattBndsY = bounds_exact(y0);
53
54 if ( !pattBndsX || !pattBndsY) {
55 return pwd2_in;
56 }
57
58 x0 -= pattBndsX->min();
59 y0 -= pattBndsY->middle();
60
61 double noffset = 0;//normal_offset;
62 double toffset = 0;//tang_offset;
63 if (false /*prop_units.get_value()*/){
64 noffset *= pattBndsY->extent();
65 toffset *= pattBndsX->extent();
66 }
67
68 y0+=noffset;
69
70 output = pwd2_in;
71
72 for (int i = 0; i < iterations; ++i) {
73 std::vector<Piecewise<D2<SBasis> > > skeleton = split_at_discontinuities(output);
74
75 output.clear();
76 for (auto path_i : skeleton){
77 Piecewise<SBasis> x = x0;
78 Piecewise<SBasis> y = y0;
79 Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2,.1);
80 uskeleton = remove_short_cuts(uskeleton,.01);
81 Piecewise<D2<SBasis> > n = rot90(derivative(uskeleton));
82 n = force_continuity(remove_short_cuts(n,.1));
83
84 double scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent();
85
86 // TODO investigate why pattWidth is not being used:
87 // - Doesn't appear to have been used anywhere in bzr history (Alex V: 2013-03-16)
88 // double pattWidth = pattBndsX->extent() * scaling;
89
90 if (scaling != 1.0) {
91 x*=scaling;
92 }
93
94 if ( true /*scale_y_rel.get_value()*/ ) {
95 y*=(scaling*prop_scale);
96 } else {
97 if (prop_scale != 1.0) y *= prop_scale;
98 }
99 x += toffset;
100
101 output.concat(compose(uskeleton,x)+y*compose(n,x));
102 }
103 }
104
105 return output;
106 }
107
108
109 } //namespace LivePathEffect
110 } /* namespace Inkscape */
111
112 /*
113 Local Variables:
114 mode:c++
115 c-file-style:"stroustrup"
116 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
117 indent-tabs-mode:nil
118 fill-column:99
119 End:
120 */
121 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
122