Code

update to latest 2geom (r1195)
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 23 Mar 2008 19:59:42 +0000 (19:59 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 23 Mar 2008 19:59:42 +0000 (19:59 +0000)
src/2geom/piecewise.h
src/2geom/sbasis.h

index 1715997684cec7c7ccff95f8e893c0cd5fe9cdbf..1d0fd93baf17a9576f9b3b8b4481e974f2e44cba 100644 (file)
@@ -73,12 +73,26 @@ class Piecewise {
         unsigned n = segN(t);
         return segs[n](segT(t, n));
     }
+    std::vector<output_type> valueAndDerivatives(double t, unsigned cnt) const {
+        unsigned n = segN(t);
+        std::vector<output_type> ret, val = segs[n].valueAndDerivatives(segT(t, n), cnt);
+        double mult = 1;
+        for(unsigned i = 0; i < val.size(); i++) {
+            ret.push_back(val[i] * mult);
+            mult /= cuts[n+1] - cuts[n];
+        }
+        return ret;
+    }
     //TODO: maybe it is not a good idea to have this?
     Piecewise<T> operator()(SBasis f);
     Piecewise<T> operator()(Piecewise<SBasis>f);
 
     inline unsigned size() const { return segs.size(); }
     inline bool empty() const { return segs.empty(); }
+    inline void clear() {
+        segs.clear();
+        cuts.clear();
+    }
 
     /**Convenience/implementation hiding function to add segment/cut pairs.
      * Asserts that basic size and order invariants are correct
index c7489e27dcd9115ad621c76fcb9666b41d5cf0cb..82ff989e7b3d01e9b4501926bd02841dcf53bbc9 100644 (file)
@@ -113,7 +113,18 @@ public:
         return valueAt(t);
     }
 
-    std::vector<double> valueAndDerivatives(double /*t*/, unsigned /*n*/) const {
+    std::vector<double> valueAndDerivatives(double t, unsigned n) const {
+        std::vector<double> ret;
+        if(n==1) {
+            ret.push_back(valueAt(t));
+            return ret;
+        }
+        if(n==2) {
+            double der;
+            ret.push_back(valueAndDerivative(t, der));
+            ret.push_back(der);
+            return ret;
+        }
         //TODO
         throwNotImplemented();
     }