Code

simplify sketch result to fix crash
authorjohanengelen <johanengelen@users.sourceforge.net>
Tue, 27 Jan 2009 17:12:48 +0000 (17:12 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Tue, 27 Jan 2009 17:12:48 +0000 (17:12 +0000)
src/pencil-context.cpp

index a29e13e22d5ac94a5f3f3350644d37a8c8e497e7..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);
@@ -824,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;
         }