1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** \file
3 * LPE Curve Stitching implementation, used as an example for a base starting class
4 * when implementing new LivePathEffects.
5 *
6 */
7 /*
8 * Authors:
9 * JF Barraud.
10 *
11 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16 #include "ui/widget/scalar.h"
17 #include "live_effects/lpe-rough-hatches.h"
18
19 #include "object/sp-item.h"
20
21 #include "xml/repr.h"
22
23 #include <2geom/sbasis-math.h>
24 #include <2geom/bezier-to-sbasis.h>
25
26 // TODO due to internal breakage in glibmm headers, this must be last:
27 #include <glibmm/i18n.h>
28
29 namespace Inkscape {
30 namespace LivePathEffect {
31
32 using namespace Geom;
33
34 //------------------------------------------------
35 // Some goodies to navigate through curve's levels.
36 //------------------------------------------------
37 struct LevelCrossing{
38 Point pt;
39 double t;
40 bool sign;
41 bool used;
42 std::pair<unsigned,unsigned> next_on_curve;
43 std::pair<unsigned,unsigned> prev_on_curve;
44 };
45 struct LevelCrossingOrder {
operator ()Inkscape::LivePathEffect::LevelCrossingOrder46 bool operator()(LevelCrossing a, LevelCrossing b) {
47 return ( a.pt[Y] < b.pt[Y] );// a.pt[X] == b.pt[X] since we are supposed to be on the same level...
48 //return ( a.pt[X] < b.pt[X] || ( a.pt[X] == b.pt[X] && a.pt[Y] < b.pt[Y] ) );
49 }
50 };
51 struct LevelCrossingInfo{
52 double t;
53 unsigned level;
54 unsigned idx;
55 };
56 struct LevelCrossingInfoOrder {
operator ()Inkscape::LivePathEffect::LevelCrossingInfoOrder57 bool operator()(LevelCrossingInfo a, LevelCrossingInfo b) {
58 return a.t < b.t;
59 }
60 };
61
62 typedef std::vector<LevelCrossing> LevelCrossings;
63
64 static std::vector<double>
discontinuities(Piecewise<D2<SBasis>> const & f)65 discontinuities(Piecewise<D2<SBasis> > const &f){
66 std::vector<double> result;
67 if (f.size()==0) return result;
68 result.push_back(f.cuts[0]);
69 Point prev_pt = f.segs[0].at1();
70 //double old_t = f.cuts[0];
71 for(unsigned i=1; i<f.size(); i++){
72 if ( f.segs[i].at0()!=prev_pt){
73 result.push_back(f.cuts[i]);
74 //old_t = f.cuts[i];
75 //assert(f.segs[i-1].at1()==f.valueAt(old_t));
76 }
77 prev_pt = f.segs[i].at1();
78 }
79 result.push_back(f.cuts.back());
80 //assert(f.segs.back().at1()==f.valueAt(old_t));
81 return result;
82 }
83
84 class LevelsCrossings: public std::vector<LevelCrossings>{
85 public:
LevelsCrossings()86 LevelsCrossings():std::vector<LevelCrossings>(){};
LevelsCrossings(std::vector<std::vector<double>> const & times,Piecewise<D2<SBasis>> const & f,Piecewise<SBasis> const & dx)87 LevelsCrossings(std::vector<std::vector<double> > const ×,
88 Piecewise<D2<SBasis> > const &f,
89 Piecewise<SBasis> const &dx){
90
91 for (const auto & time : times){
92 LevelCrossings lcs;
93 for (double j : time){
94 LevelCrossing lc;
95 lc.pt = f.valueAt(j);
96 lc.t = j;
97 lc.sign = ( dx.valueAt(j)>0 );
98 lc.used = false;
99 lcs.push_back(lc);
100 }
101 std::sort(lcs.begin(), lcs.end(), LevelCrossingOrder());
102 push_back(lcs);
103 }
104 //Now create time ordering.
105 std::vector<LevelCrossingInfo>temp;
106 for (unsigned i=0; i<size(); i++){
107 for (unsigned j=0; j<(*this)[i].size(); j++){
108 LevelCrossingInfo elem;
109 elem.t = (*this)[i][j].t;
110 elem.level = i;
111 elem.idx = j;
112 temp.push_back(elem);
113 }
114 }
115 std::sort(temp.begin(),temp.end(),LevelCrossingInfoOrder());
116 std::vector<double> jumps = discontinuities(f);
117 unsigned jump_idx = 0;
118 unsigned first_in_comp = 0;
119 for (unsigned i=0; i<temp.size(); i++){
120 unsigned lvl = temp[i].level, idx = temp[i].idx;
121 if ( i == temp.size()-1 || temp[i+1].t > jumps[jump_idx+1]){
122 std::pair<unsigned,unsigned>next_data(temp[first_in_comp].level,temp[first_in_comp].idx);
123 (*this)[lvl][idx].next_on_curve = next_data;
124 first_in_comp = i+1;
125 jump_idx += 1;
126 }else{
127 std::pair<unsigned,unsigned> next_data(temp[i+1].level,temp[i+1].idx);
128 (*this)[lvl][idx].next_on_curve = next_data;
129 }
130 }
131
132 for (unsigned i=0; i<size(); i++){
133 for (unsigned j=0; j<(*this)[i].size(); j++){
134 std::pair<unsigned,unsigned> next = (*this)[i][j].next_on_curve;
135 (*this)[next.first][next.second].prev_on_curve = std::pair<unsigned,unsigned>(i,j);
136 }
137 }
138 }
139
findFirstUnused(unsigned & level,unsigned & idx)140 void findFirstUnused(unsigned &level, unsigned &idx){
141 level = size();
142 idx = 0;
143 for (unsigned i=0; i<size(); i++){
144 for (unsigned j=0; j<(*this)[i].size(); j++){
145 if (!(*this)[i][j].used){
146 level = i;
147 idx = j;
148 return;
149 }
150 }
151 }
152 }
153 //set indexes to point to the next point in the "snake walk"
154 //follow_level's meaning:
155 // 0=yes upward
156 // 1=no, last move was upward,
157 // 2=yes downward
158 // 3=no, last move was downward.
step(unsigned & level,unsigned & idx,int & direction)159 void step(unsigned &level, unsigned &idx, int &direction){
160 if ( direction % 2 == 0 ){
161 if (direction == 0) {
162 if ( idx >= (*this)[level].size()-1 || (*this)[level][idx+1].used ) {
163 level = size();
164 return;
165 }
166 idx += 1;
167 }else{
168 if ( idx <= 0 || (*this)[level][idx-1].used ) {
169 level = size();
170 return;
171 }
172 idx -= 1;
173 }
174 direction += 1;
175 return;
176 }
177 //double t = (*this)[level][idx].t;
178 double sign = ((*this)[level][idx].sign ? 1 : -1);
179 //---double next_t = t;
180 //level += 1;
181 direction = (direction + 1)%4;
182 if (level == size()){
183 return;
184 }
185
186 std::pair<unsigned,unsigned> next;
187 if ( sign > 0 ){
188 next = (*this)[level][idx].next_on_curve;
189 }else{
190 next = (*this)[level][idx].prev_on_curve;
191 }
192
193 if ( level+1 != next.first || (*this)[next.first][next.second].used ) {
194 level = size();
195 return;
196 }
197 level = next.first;
198 idx = next.second;
199 return;
200 }
201 };
202
203 //-------------------------------------------------------
204 // Bend a path...
205 //-------------------------------------------------------
206
bend(Piecewise<D2<SBasis>> const & f,Piecewise<SBasis> bending)207 static Piecewise<D2<SBasis> > bend(Piecewise<D2<SBasis> > const &f, Piecewise<SBasis> bending){
208 D2<Piecewise<SBasis> > ff = make_cuts_independent(f);
209 ff[X] += compose(bending, ff[Y]);
210 return sectionize(ff);
211 }
212
213 //--------------------------------------------------------
214 // The RoughHatches lpe.
215 //--------------------------------------------------------
LPERoughHatches(LivePathEffectObject * lpeobject)216 LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) :
217 Effect(lpeobject),
218 hatch_dist(0),
219 dist_rdm(_("Frequency randomness:"), _("Variation of distance between hatches, in %."), "dist_rdm", &wr, this, 75),
220 growth(_("Growth:"), _("Growth of distance between hatches."), "growth", &wr, this, 0.),
221 //FIXME: top/bottom names are inverted in the UI/svg and in the code!!
222 scale_tf(_("Half-turns smoothness: 1st side, in:"), _("Set smoothness/sharpness of path when reaching a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bf", &wr, this, 1.),
223 scale_tb(_("1st side, out:"), _("Set smoothness/sharpness of path when leaving a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bb", &wr, this, 1.),
224 scale_bf(_("2nd side, in:"), _("Set smoothness/sharpness of path when reaching a 'top' half-turn. 0=sharp, 1=default"), "scale_tf", &wr, this, 1.),
225 scale_bb(_("2nd side, out:"), _("Set smoothness/sharpness of path when leaving a 'top' half-turn. 0=sharp, 1=default"), "scale_tb", &wr, this, 1.),
226 top_edge_variation(_("Magnitude jitter: 1st side:"), _("Randomly moves 'bottom' half-turns to produce magnitude variations."), "bottom_edge_variation", &wr, this, 0),
227 bot_edge_variation(_("2nd side:"), _("Randomly moves 'top' half-turns to produce magnitude variations."), "top_edge_variation", &wr, this, 0),
228 top_tgt_variation(_("Parallelism jitter: 1st side:"), _("Add direction randomness by moving 'bottom' half-turns tangentially to the boundary."), "bottom_tgt_variation", &wr, this, 0),
229 bot_tgt_variation(_("2nd side:"), _("Add direction randomness by randomly moving 'top' half-turns tangentially to the boundary."), "top_tgt_variation", &wr, this, 0),
230 top_smth_variation(_("Variance: 1st side:"), _("Randomness of 'bottom' half-turns smoothness"), "top_smth_variation", &wr, this, 0),
231 bot_smth_variation(_("2nd side:"), _("Randomness of 'top' half-turns smoothness"), "bottom_smth_variation", &wr, this, 0),
232 //
233 fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varying width"), "fat_output", &wr, this, true),
234 do_bend(_("Bend hatches"), _("Add a global bend to the hatches (slower)"), "do_bend", &wr, this, true),
235 stroke_width_top(_("Thickness: at 1st side:"), _("Width at 'bottom' half-turns"), "stroke_width_top", &wr, this, 1.),
236 stroke_width_bot(_("At 2nd side:"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.),
237 //
238 front_thickness(_("From 2nd to 1st side:"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.),
239 back_thickness(_("From 1st to 2nd side:"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25),
240
241 direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0)),
242 //
243 bender(_("Global bending"), _("Relative position to a reference point defines global bending direction and amount"), "bender", &wr, this, Geom::Point(-5,0))
244 {
245 registerParameter(&direction);
246 registerParameter(&dist_rdm);
247 registerParameter(&growth);
248 registerParameter(&do_bend);
249 registerParameter(&bender);
250 registerParameter(&top_edge_variation);
251 registerParameter(&bot_edge_variation);
252 registerParameter(&top_tgt_variation);
253 registerParameter(&bot_tgt_variation);
254 registerParameter(&scale_tf);
255 registerParameter(&scale_tb);
256 registerParameter(&scale_bf);
257 registerParameter(&scale_bb);
258 registerParameter(&top_smth_variation);
259 registerParameter(&bot_smth_variation);
260 registerParameter(&fat_output);
261 registerParameter(&stroke_width_top);
262 registerParameter(&stroke_width_bot);
263 registerParameter(&front_thickness);
264 registerParameter(&back_thickness);
265
266 //hatch_dist.param_set_range(0.1, Geom::infinity());
267 growth.param_set_range(0, std::numeric_limits<double>::max());
268 dist_rdm.param_set_range(0, 99.);
269 stroke_width_top.param_set_range(0, std::numeric_limits<double>::max());
270 stroke_width_bot.param_set_range(0, std::numeric_limits<double>::max());
271 front_thickness.param_set_range(0, std::numeric_limits<double>::max());
272 back_thickness.param_set_range(0, std::numeric_limits<double>::max());
273
274 // hide the widgets for direction and bender vectorparams
275 direction.widget_is_visible = false;
276 bender.widget_is_visible = false;
277 // give distinguishing colors to direction and bender on-canvas params
278 direction.set_oncanvas_color(0x00ff7d00);
279 bender.set_oncanvas_color(0xffffb500);
280
281 concatenate_before_pwd2 = false;
282 show_orig_path = true;
283 }
284
285 LPERoughHatches::~LPERoughHatches()
286 = default;
287
288 Geom::Piecewise<Geom::D2<Geom::SBasis> >
doEffect_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis>> const & pwd2_in)289 LPERoughHatches::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in){
290
291 //std::cout<<"doEffect_pwd2:\n";
292
293 Piecewise<D2<SBasis> > result;
294
295 Piecewise<D2<SBasis> > transformed_pwd2_in = pwd2_in;
296 Point start = pwd2_in.segs.front().at0();
297 Point end = pwd2_in.segs.back().at1();
298 if (end != start ){
299 transformed_pwd2_in.push_cut( transformed_pwd2_in.cuts.back() + 1 );
300 D2<SBasis> stitch( SBasis( 1, Linear(end[X],start[X]) ), SBasis( 1, Linear(end[Y],start[Y]) ) );
301 transformed_pwd2_in.push_seg( stitch );
302 }
303 Point transformed_org = direction.getOrigin();
304 Piecewise<SBasis> tilter;//used to bend the hatches
305 Affine bend_mat;//used to bend the hatches
306
307 if (do_bend.get_value()){
308 Point bend_dir = -rot90(unit_vector(bender.getVector()));
309 double bend_amount = L2(bender.getVector());
310 bend_mat = Affine(-bend_dir[Y], bend_dir[X], bend_dir[X], bend_dir[Y],0,0);
311 transformed_pwd2_in = transformed_pwd2_in * bend_mat;
312 tilter = Piecewise<SBasis>(shift(Linear(-bend_amount),1));
313 OptRect bbox = bounds_exact( transformed_pwd2_in );
314 if (!(bbox)) return pwd2_in;
315 tilter.setDomain((*bbox)[Y]);
316 transformed_pwd2_in = bend(transformed_pwd2_in, tilter);
317 transformed_pwd2_in = transformed_pwd2_in * bend_mat.inverse();
318 }
319 hatch_dist = Geom::L2(direction.getVector())/5;
320 Point hatches_dir = rot90(unit_vector(direction.getVector()));
321 Affine mat(-hatches_dir[Y], hatches_dir[X], hatches_dir[X], hatches_dir[Y],0,0);
322 transformed_pwd2_in = transformed_pwd2_in * mat;
323 transformed_org *= mat;
324
325 std::vector<std::vector<Point> > snakePoints;
326 snakePoints = linearSnake(transformed_pwd2_in, transformed_org);
327 if (!snakePoints.empty()){
328 Piecewise<D2<SBasis> >smthSnake = smoothSnake(snakePoints);
329 smthSnake = smthSnake*mat.inverse();
330 if (do_bend.get_value()){
331 smthSnake = smthSnake*bend_mat;
332 smthSnake = bend(smthSnake, -tilter);
333 smthSnake = smthSnake*bend_mat.inverse();
334 }
335 return (smthSnake);
336 }
337 return pwd2_in;
338 }
339
340 //------------------------------------------------
341 // Generate the levels with random, growth...
342 //------------------------------------------------
343 std::vector<double>
generateLevels(Interval const & domain,double x_org)344 LPERoughHatches::generateLevels(Interval const &domain, double x_org){
345 std::vector<double> result;
346 int n = int((domain.min()-x_org)/hatch_dist);
347 double x = x_org + n * hatch_dist;
348 //double x = domain.min() + double(hatch_dist)/2.;
349 double step = double(hatch_dist);
350 double scale = 1+(hatch_dist*growth/domain.extent());
351 while (x < domain.max()){
352 result.push_back(x);
353 double rdm = 1;
354 if (dist_rdm.get_value() != 0)
355 rdm = 1.+ double((2*dist_rdm - dist_rdm.get_value()))/100.;
356 x+= step*rdm;
357 step*=scale;//(1.+double(growth));
358 }
359 return result;
360 }
361
362
363 //-------------------------------------------------------
364 // Walk through the intersections to create linear hatches
365 //-------------------------------------------------------
366 std::vector<std::vector<Point> >
linearSnake(Piecewise<D2<SBasis>> const & f,Point const & org)367 LPERoughHatches::linearSnake(Piecewise<D2<SBasis> > const &f, Point const &org){
368
369 //std::cout<<"linearSnake:\n";
370 std::vector<std::vector<Point> > result;
371 Piecewise<SBasis> x = make_cuts_independent(f)[X];
372 //Remark: derivative is computed twice in the 2 lines below!!
373 Piecewise<SBasis> dx = derivative(x);
374 OptInterval range = bounds_exact(x);
375
376 if (!range) return result;
377 std::vector<double> levels = generateLevels(*range, org[X]);
378 std::vector<std::vector<double> > times;
379 times = multi_roots(x,levels);
380 //TODO: fix multi_roots!!!*****************************************
381 //remove doubles :-(
382 std::vector<std::vector<double> > cleaned_times(levels.size(),std::vector<double>());
383 for (unsigned i=0; i<times.size(); i++){
384 if ( times[i].size()>0 ){
385 double last_t = times[i][0]-1;//ugly hack!!
386 for (unsigned j=0; j<times[i].size(); j++){
387 if (times[i][j]-last_t >0.000001){
388 last_t = times[i][j];
389 cleaned_times[i].push_back(last_t);
390 }
391 }
392 }
393 }
394 times = cleaned_times;
395 //*******************************************************************
396
397 LevelsCrossings lscs(times,f,dx);
398
399 unsigned i,j;
400 lscs.findFirstUnused(i,j);
401
402 std::vector<Point> result_component;
403 int n = int((range->min()-org[X])/hatch_dist);
404
405 while ( i < lscs.size() ){
406 int dir = 0;
407 //switch orientation of first segment according to starting point.
408 if ((static_cast<long long>(i) % 2 == n % 2) && ((j + 1) < lscs[i].size()) && !lscs[i][j].used){
409 j += 1;
410 dir = 2;
411 }
412
413 while ( i < lscs.size() ){
414 result_component.push_back(lscs[i][j].pt);
415 lscs[i][j].used = true;
416 lscs.step(i,j, dir);
417 }
418 result.push_back(result_component);
419 result_component = std::vector<Point>();
420 lscs.findFirstUnused(i,j);
421 }
422 return result;
423 }
424
425 //-------------------------------------------------------
426 // Smooth the linear hatches according to params...
427 //-------------------------------------------------------
428 Piecewise<D2<SBasis> >
smoothSnake(std::vector<std::vector<Point>> const & linearSnake)429 LPERoughHatches::smoothSnake(std::vector<std::vector<Point> > const &linearSnake){
430
431 Piecewise<D2<SBasis> > result;
432 for (const auto & comp : linearSnake){
433 if (comp.size()>=2){
434 Point last_pt = comp[0];
435 //Point last_top = linearSnake[comp][0];
436 //Point last_bot = linearSnake[comp][0];
437 Point last_hdle = comp[0];
438 Point last_top_hdle = comp[0];
439 Point last_bot_hdle = comp[0];
440 Geom::Path res_comp(last_pt);
441 Geom::Path res_comp_top(last_pt);
442 Geom::Path res_comp_bot(last_pt);
443 unsigned i=1;
444 //bool is_top = true;//Inversion here; due to downward y?
445 bool is_top = ( comp[0][Y] < comp[1][Y] );
446
447 while( i+1<comp.size() ){
448 Point pt0 = comp[i];
449 Point pt1 = comp[i+1];
450 Point new_pt = (pt0+pt1)/2;
451 double scale_in = (is_top ? scale_tf : scale_bf );
452 double scale_out = (is_top ? scale_tb : scale_bb );
453 if (is_top){
454 if (top_edge_variation.get_value() != 0)
455 new_pt[Y] += double(top_edge_variation)-top_edge_variation.get_value()/2.;
456 if (top_tgt_variation.get_value() != 0)
457 new_pt[X] += double(top_tgt_variation)-top_tgt_variation.get_value()/2.;
458 if (top_smth_variation.get_value() != 0) {
459 scale_in*=(100.-double(top_smth_variation))/100.;
460 scale_out*=(100.-double(top_smth_variation))/100.;
461 }
462 }else{
463 if (bot_edge_variation.get_value() != 0)
464 new_pt[Y] += double(bot_edge_variation)-bot_edge_variation.get_value()/2.;
465 if (bot_tgt_variation.get_value() != 0)
466 new_pt[X] += double(bot_tgt_variation)-bot_tgt_variation.get_value()/2.;
467 if (bot_smth_variation.get_value() != 0) {
468 scale_in*=(100.-double(bot_smth_variation))/100.;
469 scale_out*=(100.-double(bot_smth_variation))/100.;
470 }
471 }
472 Point new_hdle_in = new_pt + (pt0-pt1) * (scale_in /2.);
473 Point new_hdle_out = new_pt - (pt0-pt1) * (scale_out/2.);
474
475 if ( fat_output.get_value() ){
476 //double scaled_width = double((is_top ? stroke_width_top : stroke_width_bot))/(pt1[X]-pt0[X]);
477 //double scaled_width = 1./(pt1[X]-pt0[X]);
478 //Point hdle_offset = (pt1-pt0)*scaled_width;
479 Point inside = new_pt;
480 Point inside_hdle_in;
481 Point inside_hdle_out;
482 inside[Y]+= double((is_top ? -stroke_width_top : stroke_width_bot));
483 inside_hdle_in = inside + (new_hdle_in -new_pt);// + hdle_offset * double((is_top ? front_thickness : back_thickness));
484 inside_hdle_out = inside + (new_hdle_out-new_pt);// - hdle_offset * double((is_top ? back_thickness : front_thickness));
485
486 inside_hdle_in += (pt1-pt0)/2*( double((is_top ? front_thickness : back_thickness)) / (pt1[X]-pt0[X]) );
487 inside_hdle_out -= (pt1-pt0)/2*( double((is_top ? back_thickness : front_thickness)) / (pt1[X]-pt0[X]) );
488
489 new_hdle_in -= (pt1-pt0)/2*( double((is_top ? front_thickness : back_thickness)) / (pt1[X]-pt0[X]) );
490 new_hdle_out += (pt1-pt0)/2*( double((is_top ? back_thickness : front_thickness)) / (pt1[X]-pt0[X]) );
491 //TODO: find a good way to handle limit cases (small smoothness, large stroke).
492 //if (inside_hdle_in[X] > inside[X]) inside_hdle_in = inside;
493 //if (inside_hdle_out[X] < inside[X]) inside_hdle_out = inside;
494
495 if (is_top){
496 res_comp_top.appendNew<CubicBezier>(last_top_hdle,new_hdle_in,new_pt);
497 res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,inside_hdle_in,inside);
498 last_top_hdle = new_hdle_out;
499 last_bot_hdle = inside_hdle_out;
500 }else{
501 res_comp_top.appendNew<CubicBezier>(last_top_hdle,inside_hdle_in,inside);
502 res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,new_hdle_in,new_pt);
503 last_top_hdle = inside_hdle_out;
504 last_bot_hdle = new_hdle_out;
505 }
506 }else{
507 res_comp.appendNew<CubicBezier>(last_hdle,new_hdle_in,new_pt);
508 }
509
510 last_hdle = new_hdle_out;
511 i+=2;
512 is_top = !is_top;
513 }
514 if ( i<comp.size() ){
515 if ( fat_output.get_value() ){
516 res_comp_top.appendNew<CubicBezier>(last_top_hdle,comp[i],comp[i]);
517 res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,comp[i],comp[i]);
518 }else{
519 res_comp.appendNew<CubicBezier>(last_hdle,comp[i],comp[i]);
520 }
521 }
522 if ( fat_output.get_value() ){
523 res_comp = res_comp_bot;
524 res_comp.setStitching(true);
525 res_comp.append(res_comp_top.reversed());
526 }
527 result.concat(res_comp.toPwSb());
528 }
529 }
530 return result;
531 }
532
533 void
doBeforeEffect(SPLPEItem const *)534 LPERoughHatches::doBeforeEffect (SPLPEItem const*/*lpeitem*/)
535 {
536 using namespace Geom;
537 top_edge_variation.resetRandomizer();
538 bot_edge_variation.resetRandomizer();
539 top_tgt_variation.resetRandomizer();
540 bot_tgt_variation.resetRandomizer();
541 top_smth_variation.resetRandomizer();
542 bot_smth_variation.resetRandomizer();
543 dist_rdm.resetRandomizer();
544
545 //original_bbox(lpeitem);
546 }
547
548
549 void
resetDefaults(SPItem const * item)550 LPERoughHatches::resetDefaults(SPItem const* item)
551 {
552 Effect::resetDefaults(item);
553
554 Geom::OptRect bbox = item->geometricBounds();
555 Geom::Point origin(0.,0.);
556 Geom::Point vector(50.,0.);
557 if (bbox) {
558 origin = bbox->midpoint();
559 vector = Geom::Point((*bbox)[X].extent()/4, 0.);
560 top_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 );
561 bot_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 );
562 top_edge_variation.write_to_SVG();
563 bot_edge_variation.write_to_SVG();
564 }
565 //direction.set_and_write_new_values(origin, vector);
566 //bender.param_set_and_write_new_value( origin + Geom::Point(5,0) );
567 direction.set_and_write_new_values(origin + Geom::Point(0,-5), vector);
568 bender.set_and_write_new_values( origin, Geom::Point(5,0) );
569 hatch_dist = Geom::L2(vector)/2;
570 }
571
572
573 } //namespace LivePathEffect
574 } /* namespace Inkscape */
575
576 /*
577 Local Variables:
578 mode:c++
579 c-file-style:"stroustrup"
580 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
581 indent-tabs-mode:nil
582 fill-column:99
583 End:
584 */
585 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
586