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