Code

lpe-skeletal-stroke: make spacing and normal_offset parameters do something...
authorjfbarraud <jfbarraud@users.sourceforge.net>
Tue, 5 Feb 2008 00:51:50 +0000 (00:51 +0000)
committerjfbarraud <jfbarraud@users.sourceforge.net>
Tue, 5 Feb 2008 00:51:50 +0000 (00:51 +0000)
src/live_effects/lpe-skeletalstrokes.cpp

index 6ba9ac65c9cb69e3b5b65598a224f111ef00dd1e..ea16105467fc61c4b295dce79031407d09f048f7 100644 (file)
@@ -72,13 +72,14 @@ LPESkeletalStrokes::LPESkeletalStrokes(LivePathEffectObject *lpeobject) :
     registerParameter( dynamic_cast<Parameter *>(&copytype) );
     registerParameter( dynamic_cast<Parameter *>(&prop_scale) );
     registerParameter( dynamic_cast<Parameter *>(&scale_y_rel) );
-//    registerParameter( dynamic_cast<Parameter *>(&spacing) );
-//    registerParameter( dynamic_cast<Parameter *>(&normal_offset) );
-//    registerParameter( dynamic_cast<Parameter *>(&tang_offset) );
+    registerParameter( dynamic_cast<Parameter *>(&spacing) );
+    registerParameter( dynamic_cast<Parameter *>(&normal_offset) );
+    registerParameter( dynamic_cast<Parameter *>(&tang_offset) );
     registerParameter( dynamic_cast<Parameter *>(&vertical_pattern) );
 
     prop_scale.param_set_digits(3);
     prop_scale.param_set_increments(0.01, 0.10);
+    tang_offset.param_set_range(0, NR_HUGE);
 }
 
 LPESkeletalStrokes::~LPESkeletalStrokes()
@@ -105,28 +106,37 @@ LPESkeletalStrokes::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pw
     Piecewise<SBasis> x = vertical_pattern.get_value() ? Piecewise<SBasis>(patternd2[1]) : Piecewise<SBasis>(patternd2[0]);
     Piecewise<SBasis> y = vertical_pattern.get_value() ? Piecewise<SBasis>(patternd2[0]) : Piecewise<SBasis>(patternd2[1]);
     Interval pattBnds = bounds_exact(x);
-    x -= pattBnds.min();
+    x -=  pattBnds.min();
     Interval pattBndsY = bounds_exact(y);
-    y -= pattBndsY.middle();
+    y -= pattBndsY.middle()+normal_offset;
 
-    int nbCopies = int(uskeleton.cuts.back()/pattBnds.extent());
+    //Prevent more than 90% overlap...
+    if (spacing < -pattBnds.extent()*.9) {
+        spacing.param_set_value(-pattBnds.extent()*.9);
+    }
+
+    int nbCopies = 0;
     double scaling = 1;
 
     switch(type) {
         case SSCT_REPEATED:
+            nbCopies = floor((uskeleton.domain().extent() - tang_offset + spacing)/(pattBnds.extent()+spacing));
+            pattBnds = Interval(pattBnds.min(),pattBnds.max()+spacing);
             break;
 
         case SSCT_SINGLE:
-            nbCopies = (nbCopies > 0) ? 1 : 0;
+            nbCopies = (tang_offset + pattBnds.extent() < uskeleton.domain().extent()) ? 1 : 0;
             break;
 
         case SSCT_SINGLE_STRETCHED:
             nbCopies = 1;
-            scaling = uskeleton.cuts.back()/pattBnds.extent();
+            scaling = (uskeleton.domain().extent() - tang_offset)/pattBnds.extent();
             break;
 
         case SSCT_REPEATED_STRETCHED:
-             scaling = uskeleton.cuts.back()/(((double)nbCopies)*pattBnds.extent());
+            nbCopies = std::floor((uskeleton.domain().extent() - tang_offset + spacing)/(pattBnds.extent()+spacing));
+            pattBnds = Interval(pattBnds.min(),pattBnds.max()+spacing);
+            scaling = (uskeleton.domain().extent() - tang_offset)/(((double)nbCopies)*pattBnds.extent() - spacing);
             break;
 
         default:
@@ -143,6 +153,7 @@ LPESkeletalStrokes::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pw
     } else {
         if (prop_scale != 1.0) y *= prop_scale;
     }
+    x += tang_offset;
 
     double offs = 0;
     Piecewise<D2<SBasis> > output;