Code

lpe-vonkoch: updated to handle groups + changed parameter interpretation to allow...
authorjfbarraud <jfbarraud@users.sourceforge.net>
Wed, 17 Sep 2008 00:26:46 +0000 (00:26 +0000)
committerjfbarraud <jfbarraud@users.sourceforge.net>
Wed, 17 Sep 2008 00:26:46 +0000 (00:26 +0000)
src/live_effects/lpe-vonkoch.cpp
src/live_effects/lpe-vonkoch.h

index 8937f7cec5e4f4a4778f57d96d5c9e25874149ce..bc86e4daae42dd5df00594cd906c4bc7fc4cd216 100644 (file)
@@ -80,31 +80,39 @@ LPEVonKoch::doEffect_path (std::vector<Geom::Path> const & path_in)
     Matrix m0;
     VonKochRefType type = reftype.get_value();
     if (type==VKREF_BBOX){
-        Rect bbox = path_in[0].boundsExact();
-        for(unsigned i=1; i < path_in.size(); i++){
-            bbox.unionWith(path_in[i].boundsExact());
-        }
-        m0 = Matrix(bbox[X].extent(),0,0,bbox[X].extent(), bbox.min()[X], (bbox.min()[Y]+bbox.max()[Y])/2);
+        Rect bbox = Rect(boundingbox_X,boundingbox_Y);
+        m0 = Matrix(boundingbox_X.extent(),0,0,boundingbox_X.extent(), boundingbox_X.min(), boundingbox_Y.middle());
+
     }else{
         if (generating_path.size()==0) return path_in;
         Point p = generating_path.back().back().pointAt(0);
-        Point u = generating_path.back().back().pointAt(0.999)-p;
+        Point u = generating_path.back().back().pointAt(1)-p;
         m0 = Matrix(u[X], u[Y],-u[Y], u[X], p[X], p[Y]);
     }
     m0 = m0.inverse();
 
+
     std::vector<Matrix> transforms;
+    unsigned end = generating_path.size(); 
+    if (type==VKREF_SEG) end-=1;
     for (unsigned i=0; i<generating_path.size(); i++){
-        unsigned end = generating_path[i].size(); 
-        if(type==VKREF_SEG && i==generating_path.size()-1) end-=1;
-        for (unsigned j=0; j<end; j++){   
-            Point p = generating_path[i].pointAt(j);
-            Point u = generating_path[i].pointAt(j+0.999)-generating_path[i].pointAt(j+0.001);
-            Matrix m = Matrix(u[X], u[Y],-u[Y], u[X], p[X], p[Y]);
+        Matrix m;
+        if(generating_path[i].size()==1){
+            Point p = generating_path[i].pointAt(0);
+            Point u = generating_path[i].pointAt(1)-p;
+            m = Matrix(u[X], u[Y],-u[Y], u[X], p[X], p[Y]);
+            m = m0*m;
+            transforms.push_back(m);
+        }else if(generating_path[i].size()>=2){
+            Point p = generating_path[i].pointAt(1);
+            Point u = generating_path[i].pointAt(2)-p;
+            Point v = p-generating_path[i].pointAt(0);
+            m = Matrix(u[X], u[Y],v[X], v[Y], p[X], p[Y]);
             m = m0*m;
             transforms.push_back(m);
         }
     }
+
     if (transforms.size()==0) return path_in;
 
     //Do nothing if the output is too complex... 
@@ -151,43 +159,28 @@ LPEVonKoch::doEffect_path (std::vector<Geom::Path> const & path_in)
 }
 
 void
-LPEVonKoch::resetDefaults(SPItem * item)
+LPEVonKoch::doBeforeEffect (SPLPEItem *lpeitem)
 {
-    if (!SP_IS_PATH(item)) return;
+    original_bbox(lpeitem);
+}
 
-    using namespace Geom;
 
-    // set the bend path to run horizontally in the middle of the bounding box of the original path
-    Piecewise<D2<SBasis> > pwd2;
-    std::vector<Geom::Path> temppath = sp_svg_read_pathv( SP_OBJECT_REPR(item)->attribute("inkscape:original-d"));
-    for (unsigned int i=0; i < temppath.size(); i++) {
-        pwd2.concat( temppath[i].toPwSb() );
-    }
-
-    D2<Piecewise<SBasis> > d2pw = make_cuts_independent(pwd2);
-    Interval bndsX = bounds_exact(d2pw[0]);
-    Interval bndsY = bounds_exact(d2pw[1]);
-    Point start(bndsX.min(), (bndsY.max()+bndsY.min())/2);
-    Point end(bndsX.max(), (bndsY.max()+bndsY.min())/2);
+void
+LPEVonKoch::resetDefaults(SPItem * item)
+{
+    using namespace Geom;
+    original_bbox(SP_LPE_ITEM(item));
+    Point start(boundingbox_X.min(), boundingbox_Y.middle());
+    Point end(boundingbox_X.max(), boundingbox_Y.middle());
 
     std::vector<Geom::Path> paths;
-    Geom::Path path;
-    path = Geom::Path();
-    path.start( start );
+    Geom::Path path = Geom::Path(start);
     path.appendNew<Geom::LineSegment>( end );
-    paths.push_back(path * Matrix(1./3,0,0,1./3,start[X]*2./3,start[Y]*2./3 + bndsY.extent()/2));
-    paths.push_back(path * Matrix(1./3,0,0,1./3,  end[X]*2./3,  end[Y]*2./3 + bndsY.extent()/2));
+    paths.push_back(path * Matrix(1./3,0,0,1./3,start[X]*2./3,start[Y]*2./3 + boundingbox_Y.extent()/2));
+    paths.push_back(path * Matrix(1./3,0,0,1./3,  end[X]*2./3,  end[Y]*2./3 + boundingbox_Y.extent()/2));
     paths.push_back(path);
 
     generator.set_new_value(paths, true);
-
-    
-
-
-//     Piecewise<D2<SBasis> > default_gen;
-//     default_gen.concat(Piecewise<D2<SBasis> >(D2<SBasis>(Linear(bndsX.min(),bndsX.max()),Linear((bndsY.min()+bndsY.max())/2))));
-//     default_gen.concat(Piecewise<D2<SBasis> >(D2<SBasis>(Linear(bndsX.max(),bndsX.max()+bndsX.extent()/2),Linear((bndsY.min()+bndsY.max())/2))));
-//     generator.set_new_value(default_gen, true);
 }
 
 void
index a825d658a820707f247335ebce97714647da16a2..4909b87303af62f944d22ae1c52eccd014b1c299 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include "live_effects/effect.h"
+#include "live_effects/lpegroupbbox.h"
 #include "live_effects/parameter/path.h"
 #include "live_effects/parameter/enum.h"
 #include "live_effects/parameter/bool.h"
@@ -35,7 +36,7 @@ public:
     virtual void param_setup_nodepath(Inkscape::NodePath::Path *np);  
   };
 
-class LPEVonKoch : public Effect {
+class LPEVonKoch : public Effect, GroupBBoxEffect {
 public:
     LPEVonKoch(LivePathEffectObject *lpeobject);
     virtual ~LPEVonKoch();
@@ -44,6 +45,8 @@ public:
 
     virtual void resetDefaults(SPItem * item);
 
+    virtual void doBeforeEffect(SPLPEItem * item);
+
     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
 
 private: