Code

Merging from trunk
[inkscape.git] / src / live_effects / lpe-sketch.cpp
index fcdbfefc0a4afe370949f860fa149e5996491a45..a95d89398c7cf318d0a1c10fef925c88e7b83740 100644 (file)
@@ -12,8 +12,6 @@
  */
 
 #include "live_effects/lpe-sketch.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
 
 // You might need to include other 2geom files. You can add them here:
 #include <2geom/path.h>
@@ -34,29 +32,29 @@ LPESketch::LPESketch(LivePathEffectObject *lpeobject) :
     Effect(lpeobject),
     // initialise your parameters here:
     //testpointA(_("Test Point A"), _("Test A"), "ptA", &wr, this, Geom::Point(100,100)),
-    nbiter_approxstrokes(_("Nb of iterations"), _("Draw that many approximating strokes sequences."), "nbiter_approxstrokes", &wr, this, 5),
+    nbiter_approxstrokes(_("Strokes"), _("Draw that many approximating strokes"), "nbiter_approxstrokes", &wr, this, 5),
     strokelength(_("Max stroke length"), 
-                 _("Maximal length of approximated strokes."), "strokelength", &wr, this, 100.),
+                 _("Maximum length of approximating strokes"), "strokelength", &wr, this, 100.),
     strokelength_rdm(_("Stroke length variation"), 
-                     _("Random variation of stroke length (relative to max. length)."), "strokelength_rdm", &wr, this, .3),
+                     _("Random variation of stroke length (relative to maximum length)"), "strokelength_rdm", &wr, this, .3),
     strokeoverlap(_("Max. overlap"), 
-                  _("How much successive strokes should overlap (relative to max. length)."), "strokeoverlap", &wr, this, .3),
+                  _("How much successive strokes should overlap (relative to maximum length)"), "strokeoverlap", &wr, this, .3),
     strokeoverlap_rdm(_("Overlap variation"), 
-                      _("Random variation of overlap (relative to max. overlap)"), "strokeoverlap_rdm", &wr, this, .3),
-    ends_tolerance(_("Max. ends tolerance"), 
-                   _("Max. distance between original and approximated paths ends (relative to max. length)."), "ends_tolerance", &wr, this, .1),
+                      _("Random variation of overlap (relative to maximum overlap)"), "strokeoverlap_rdm", &wr, this, .3),
+    ends_tolerance(_("Max. end tolerance"), 
+                   _("Maximum distance between ends of original and approximating paths (relative to maximum length)"), "ends_tolerance", &wr, this, .1),
     parallel_offset(_("Parallel offset"), 
-                    _("Average distance to original stroke(try 0.)."), "parallel_offset", &wr, this, 5.),
+                    _("Average distance from approximating path to original path"), "parallel_offset", &wr, this, 5.),
     tremble_size(_("Max. tremble"), 
-                 _("Maximal tremble magnitude."), "tremble_size", &wr, this, 5.),
+                 _("Maximum tremble magnitude"), "tremble_size", &wr, this, 5.),
     tremble_frequency(_("Tremble frequency"), 
-                      _("Typical nb of tremble 'period' in a stroke."), "tremble_frequency", &wr, this, 1.),
-    nbtangents(_("Nb of construction Lines"), 
-               _("How many construction lines (tangents) to draw?"), "nbtangents", &wr, this, 5),
+                      _("Average number of tremble periods in an approximating stroke"), "tremble_frequency", &wr, this, 1.),
+    nbtangents(_("Construction lines"), 
+               _("How many construction lines (tangents) to draw"), "nbtangents", &wr, this, 5),
     tgtscale(_("Scale"), 
-             _("Scale factor relating curvature and length of construction lines(try 5*avarage offset) )"), "tgtscale", &wr, this, 10.0),
-    tgtlength(_("Max. length"), _("Max. length of construction lines."), "tgtlength", &wr, this, 100.0),
-    tgtlength_rdm(_("Length variation"), _("Random variation of construction lines length."), "tgtlength_rdm", &wr, this, .3)
+             _("Scale factor relating curvature and length of construction lines (try 5*offset)"), "tgtscale", &wr, this, 10.0),
+    tgtlength(_("Max. length"), _("Maximum length of construction lines"), "tgtlength", &wr, this, 100.0),
+    tgtlength_rdm(_("Length variation"), _("Random variation of the length of construction lines"), "tgtlength_rdm", &wr, this, .3)
 {
     // register all your parameters here, so Inkscape knows which parameters this effect has:
     //Add some comment in the UI:  *warning* the precise output of this effect might change in future releases!
@@ -134,27 +132,7 @@ addLinearEnds (Geom::Piecewise<Geom::D2<Geom::SBasis> > & m){
 }
 */
 
-//TODO: does this already exist in 2Geom? if not, move this there...
-std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > 
-split_at_discontinuities (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwsbin, double tol = .0001)
-{
-    using namespace Geom;
-    std::vector<Piecewise<D2<SBasis> > > ret;
-    unsigned piece_start = 0;
-    for (unsigned i=0; i<pwsbin.segs.size(); i++){
-        if (i==(pwsbin.segs.size()-1) || L2(pwsbin.segs[i].at1()- pwsbin.segs[i+1].at0()) > tol){
-            Piecewise<D2<SBasis> > piece;
-            piece.cuts.push_back(pwsbin.cuts[piece_start]);
-            for (unsigned j = piece_start; j<i+1; j++){
-                piece.segs.push_back(pwsbin.segs[j]);
-                piece.cuts.push_back(pwsbin.cuts[j+1]);                
-            }
-            ret.push_back(piece);
-            piece_start = i+1;
-        }
-    }
-    return ret;
-}
+
 
 //This returns a random perturbation. Notice the domain is [s0,s0+first multiple of period>s1]...
 Geom::Piecewise<Geom::D2<Geom::SBasis> > 
@@ -193,9 +171,13 @@ LPESketch::computePerturbation (double s0, double s1){
 
 // Main effect body...
 Geom::Piecewise<Geom::D2<Geom::SBasis> >
-LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
+LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
 {
     using namespace Geom;
+    //If the input path is empty, do nothing.
+    //Note: this happens when duplicating a 3d box... dunno why.
+    if (pwd2_in.size()==0) return pwd2_in;
+
     Piecewise<D2<SBasis> > output;
 
 
@@ -203,8 +185,12 @@ LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
     parallel_offset.resetRandomizer();
     strokelength_rdm.resetRandomizer();
     strokeoverlap_rdm.resetRandomizer();
+    ends_tolerance.resetRandomizer();
+    tremble_size.resetRandomizer();
     tgtlength_rdm.resetRandomizer();
 
+
+
     // some variables for futur use (for construction lines; compute arclength only once...)
     // notations will be : t = path time, s = distance from start along the path.
     Piecewise<SBasis> pathlength;
@@ -245,14 +231,12 @@ LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
 
             while (!done){
                 // if the start point is already too far... do nothing. (this should not happen!)
-                assert (s0>=0);//this should not happen!!
                 if (!closed && s1>piece_total_length - ends_tolerance.get_value()*strokelength) break;
                 if ( closed && s0>piece_total_length + s0_initial) break;
 
                 std::vector<double> times;  
                 times = roots(piecelength-s0);  
-                if (times.size()==0) break;//we should not be there.
-                t0 = times[0];
+                t0 = times.at(0);//there should be one and only one solution!!
                 
                 // pick a new end point (s1 = s0 + strokelength).
                 s1 = s0 + strokelength*(1-strokelength_rdm);
@@ -300,8 +284,7 @@ LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
         double s = total_length * ( i + tgtlength_rdm ) / (nbtangents+1.);
         std::vector<double> times;  
         times = roots(pathlength-s);
-        assert(times.size()>0);//there should be one and only one solution!
-        double t = times[0];
+        double t = times.at(0);//there should be one and only one solution!
         Point m_t = m(t), v_t = v(t), a_t = a(t);
         //Compute tgt length according to curvature (not exceeding tgtlength) so that  
         //  dist to origninal curve ~ 4 * (parallel_offset+tremble_size).