From 3c1610c55889e3169142d2af1eece43c63022672 Mon Sep 17 00:00:00 2001 From: dooglus Date: Tue, 4 Mar 2008 22:02:22 +0000 Subject: [PATCH] Improve the derivative class for hermites. Compare http://synfig.org/images/a/a8/Bline-tangent-inaccuracy-before.png and http://synfig.org/images/a/a7/Bline-tangent-inaccuracy-after.png, the results of rendering http://synfig.org/images/b/bd/Bline-tangent-inaccuracy.sifz . git-svn-id: http://svn.voria.com/code@1857 1f10aa63-cdf2-0310-b900-c93c546f37ac --- ETL/trunk/ETL/_calculus.h | 18 ++++++++++++++++++ .../trunk/src/synfig/valuenode_blinecalctangent.cpp | 2 +- .../trunk/src/synfig/valuenode_segcalctangent.cpp | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ETL/trunk/ETL/_calculus.h b/ETL/trunk/ETL/_calculus.h index 279ed91..9fbea85 100644 --- a/ETL/trunk/ETL/_calculus.h +++ b/ETL/trunk/ETL/_calculus.h @@ -28,6 +28,8 @@ #include +#include "hermite" + /* === M A C R O S ========================================================= */ //#ifndef _EPSILON @@ -56,6 +58,22 @@ public: }; template +class derivative > : public std::unary_function::argument_type,typename hermite::result_type> +{ + hermite func; +public: + explicit derivative(const hermite &x):func(x) { } + + typename hermite::result_type + operator()(const typename hermite::argument_type &x)const + { + T a = func[0], b = func[1], c = func[2], d = func[3]; + typename hermite::argument_type y(1-x); + return ((b-a)*y*y + (c-b)*x*y*2 + (d-c)*x*x) * 3; + } +}; + +template class integral : public std::binary_function { T func; diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp index 50c3afc..0d27157 100644 --- a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp @@ -125,7 +125,7 @@ ValueNode_BLineCalcTangent::operator()(Time t)const etl::hermite curve(blinepoint0.get_vertex(), blinepoint1.get_vertex(), blinepoint0.get_tangent2(), blinepoint1.get_tangent1()); - etl::derivative< etl::hermite > deriv(curve, 0.0001); + etl::derivative< etl::hermite > deriv(curve); switch (get_type()) { diff --git a/synfig-core/trunk/src/synfig/valuenode_segcalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_segcalctangent.cpp index e27d950..a4b735c 100644 --- a/synfig-core/trunk/src/synfig/valuenode_segcalctangent.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_segcalctangent.cpp @@ -82,7 +82,7 @@ ValueNode_SegCalcTangent::operator()(Time t)const Segment segment((*segment_)(t).get(Segment())); etl::hermite curve(segment.p1,segment.p2,segment.t1,segment.t2); - etl::derivative< etl::hermite > deriv(curve, 0.0001); + etl::derivative< etl::hermite > deriv(curve); return deriv((*amount_)(t).get(Real())); } -- 2.7.4