Code

sync with current 2geom, split_at_discontinuities method and SVGEllipticalArc
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 13 Apr 2008 19:27:01 +0000 (19:27 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 13 Apr 2008 19:27:01 +0000 (19:27 +0000)
src/2geom/d2-sbasis.cpp
src/2geom/d2-sbasis.h

index a646e2cf4782148bdc3c13b2136c540b28dab404..dbf4da10e5effe08e320704e10aedb96bd41509e 100644 (file)
@@ -97,9 +97,8 @@ Piecewise<D2<SBasis> > operator*(Piecewise<D2<SBasis> > const &a, Matrix const &
 }
 
 //if tol>0, only force continuity where the jump is smaller than tol.
-Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f, 
-                                        double tol,
-                                        bool closed){
+Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f, double tol, bool closed)
+{
     if (f.size()==0) return f;
     Piecewise<D2<SBasis> > result=f;
     unsigned cur   = (closed)? 0:1;
@@ -129,4 +128,26 @@ Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f,
     }
     return result;
 }
+
+std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > 
+split_at_discontinuities (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwsbin, double tol)
+{
+    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;
 }
+
+}  // namespace Geom
index 95f1ca0dd3562f58150d3da9731ed91c35198695..c1f0faf4daea0e23485f68af3d24e1a912cfc0b1 100644 (file)
@@ -39,9 +39,9 @@ Piecewise<SBasis> cross(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> >
 
 Piecewise<D2<SBasis> > operator*(Piecewise<D2<SBasis> > const &a, Matrix const &m);
 
-Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f, 
-                                        double tol=0,
-                                        bool closed=false);
+Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f, double tol=0, bool closed=false);
+
+std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > split_at_discontinuities (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwsbin, double tol = .0001);
 
 class CoordIterator
 : public std::iterator<std::input_iterator_tag, SBasis const>