Improve the derivative class for hermites. Compare http://synfig.org/images/a/a8...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 4 Mar 2008 22:02:22 +0000 (22:02 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 4 Mar 2008 22:02:22 +0000 (22:02 +0000)
git-svn-id: http://svn.voria.com/code@1857 1f10aa63-cdf2-0310-b900-c93c546f37ac

ETL/trunk/ETL/_calculus.h
synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp
synfig-core/trunk/src/synfig/valuenode_segcalctangent.cpp

index 279ed91..9fbea85 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <functional>
 
+#include "hermite"
+
 /* === M A C R O S ========================================================= */
 
 //#ifndef _EPSILON
@@ -56,6 +58,22 @@ public:
 };
 
 template <typename T>
+class derivative<hermite<T> > : public std::unary_function<typename hermite<T>::argument_type,typename hermite<T>::result_type>
+{
+       hermite<T> func;
+public:
+       explicit derivative(const hermite<T> &x):func(x) { }
+
+       typename hermite<T>::result_type
+       operator()(const typename hermite<T>::argument_type &x)const
+       {
+               T a = func[0], b = func[1], c = func[2], d = func[3];
+               typename hermite<T>::argument_type y(1-x);
+               return ((b-a)*y*y + (c-b)*x*y*2 + (d-c)*x*x) * 3;
+       }
+};
+
+template <typename T>
 class integral : public std::binary_function<typename T::argument_type,typename T::argument_type,typename T::result_type>
 {
        T func;
index 50c3afc..0d27157 100644 (file)
@@ -125,7 +125,7 @@ ValueNode_BLineCalcTangent::operator()(Time t)const
 
        etl::hermite<Vector> curve(blinepoint0.get_vertex(),   blinepoint1.get_vertex(),
                                                           blinepoint0.get_tangent2(), blinepoint1.get_tangent1());
-       etl::derivative< etl::hermite<Vector> > deriv(curve, 0.0001);
+       etl::derivative< etl::hermite<Vector> > deriv(curve);
 
        switch (get_type())
        {
index e27d950..a4b735c 100644 (file)
@@ -82,7 +82,7 @@ ValueNode_SegCalcTangent::operator()(Time t)const
        Segment segment((*segment_)(t).get(Segment()));
 
        etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
-       etl::derivative< etl::hermite<Vector> > deriv(curve, 0.0001);
+       etl::derivative< etl::hermite<Vector> > deriv(curve);
 
        return deriv((*amount_)(t).get(Real()));
 }