Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / pencil-context.cpp
index a8c3112acd0617ce65e091d5c2d5bdf29f5bb088..de286ea5afba91416a7e11843e6ce30fe629633f 100644 (file)
@@ -42,6 +42,7 @@
 #include "desktop-style.h"
 #include "macros.h"
 #include "display/curve.h"
+#include "livarot/Path.h"
 
 static void sp_pencil_context_class_init(SPPencilContextClass *klass);
 static void sp_pencil_context_init(SPPencilContext *pc);
@@ -710,9 +711,8 @@ square(double const x)
 static void
 interpolate(SPPencilContext *pc)
 {
-
     if ( pc->ps.size() <= 1 ) {
-       return;
+        return;
     }
 
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -775,7 +775,9 @@ interpolate(SPPencilContext *pc)
 static void
 sketch_interpolate(SPPencilContext *pc)
 {
-    g_assert( pc->ps.size() > 1 );
+    if ( pc->ps.size() <= 1 ) {
+        return;
+    }
 
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4;
@@ -823,6 +825,14 @@ sketch_interpolate(SPPencilContext *pc)
                 t = 0.5;
             }
             pc->sketch_interpolation = Geom::lerp(t, fit_pwd2, pc->sketch_interpolation);
+            // simplify path, to eliminate small segments
+            Path *path = new Path;
+            path->LoadPathVector(Geom::path_from_piecewise(pc->sketch_interpolation, 0.01));
+            path->Simplify(0.5);
+            Geom::PathVector *pathv = path->MakePathVector();
+            pc->sketch_interpolation = (*pathv)[0].toPwSb();
+            delete path;
+            delete pathv;
         } else {
             pc->sketch_interpolation = fit_pwd2;
         }