Code

Added freedom of strokepath for the Curve Stitching LPE
authorjohanengelen <johanengelen@users.sourceforge.net>
Thu, 30 Aug 2007 20:31:27 +0000 (20:31 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Thu, 30 Aug 2007 20:31:27 +0000 (20:31 +0000)
src/live_effects/lpe-curvestitch.cpp

index 1769a40a1e74841b2d8effb6a0a43f14cd33ac75..b0e8dc8f7106cc0333159a46e3f9339ea7a58120 100644 (file)
@@ -24,6 +24,8 @@
 #include <2geom/bezier-to-sbasis.h>\r
 #include <2geom/sbasis-to-bezier.h>\r
 #include <2geom/d2.h>\r
+#include <2geom/matrix.h>\r
+\r
 \r
 #include "ui/widget/scalar.h"\r
 #include "libnr/nr-values.h"\r
@@ -35,14 +37,15 @@ using namespace Geom;
 \r
 LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) :\r
     Effect(lpeobject),\r
-    strokepath(_("Stroke path"), _("The path that will be stroked, whatever, think of good text here."), "strokepath", &wr, this, "M0,0 L1,1"),\r
+    strokepath(_("Stroke path"), _("The path that will be stroked, whatever, think of good text here."), "strokepath", &wr, this, "M0,0 L1,0"),\r
     nrofpaths(_("Nr of paths"), _("The number of paths that will be generated."), "count", &wr, this, 5),\r
     startpoint_variation(_("Startpoint variation"), _("..."), "startpoint_variation", &wr, this, 0),\r
     endpoint_variation(_("Endpoint variation"), _("..."), "endpoint_variation", &wr, this, 0)\r
 {\r
     registerParameter( dynamic_cast<Parameter *>(&nrofpaths) );\r
-//    registerParameter( dynamic_cast<Parameter *>(&startpoint_variation) );\r
-//    registerParameter( dynamic_cast<Parameter *>(&endpoint_variation) );\r
+    registerParameter( dynamic_cast<Parameter *>(&startpoint_variation) );\r
+    registerParameter( dynamic_cast<Parameter *>(&endpoint_variation) );\r
+    registerParameter( dynamic_cast<Parameter *>(&strokepath) );\r
 \r
     nrofpaths.param_make_integer();\r
     nrofpaths.param_set_range(2, NR_HUGE);\r
@@ -60,6 +63,12 @@ std::vector<Geom::Path>
 LPECurveStitch::doEffect (std::vector<Geom::Path> & path_in)\r
 {\r
     if (path_in.size() >= 2) {\r
+        D2<Piecewise<SBasis> > stroke = make_cuts_independant(strokepath);\r
+        Interval bndsStroke = bounds_exact(stroke[0]);\r
+        gdouble scaling = bndsStroke.max() - bndsStroke.min();\r
+        Interval bndsStrokeY = bounds_exact(stroke[1]);\r
+        Point stroke_origin(bndsStroke.min(), (bndsStrokeY.max()+bndsStrokeY.min())/2);\r
+\r
         std::vector<Geom::Path> path_out (nrofpaths);\r
 \r
         // do this for all permutations if there are more than 2 paths? realllly cool!\r
@@ -78,9 +87,14 @@ LPECurveStitch::doEffect (std::vector<Geom::Path> & path_in)
                 start = start + g_random_double_range(0, startpoint_variation) * (end - start);\r
             if (endpoint_variation != 0)\r
                 end = end + g_random_double_range(0, endpoint_variation) * (end - start);\r
-\r
-            path_out[i].start( start );\r
-            path_out[i].appendNew<LineSegment>( end );\r
+    \r
+            Matrix transform;\r
+            transform.setXAxis( (end-start) / scaling );\r
+            transform.setYAxis( rot90(unit_vector(end-start)));\r
+            transform.setTranslation( start );\r
+            Piecewise<D2<SBasis> > pwd2_out = (strokepath-stroke_origin) * transform;\r
+            std::vector<Path> result = Geom::path_from_piecewise(pwd2_out, LPE_CONVERSION_TOLERANCE);\r
+            path_out[i] = result[0];\r
             tA += incrementA;\r
             tB += incrementB;\r
         }\r