From 2ab94d47c09e4afe46209e87e8251e197c1f5b93 Mon Sep 17 00:00:00 2001 From: dooglus Date: Wed, 12 Sep 2007 01:38:05 +0000 Subject: [PATCH] Fix 1792063: problem with curve gradients when a vertex has split tangents which are almost parallel to each other. git-svn-id: http://svn.voria.com/code@656 1f10aa63-cdf2-0310-b900-c93c546f37ac --- .../src/modules/mod_gradient/curvegradient.cpp | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/synfig-core/trunk/src/modules/mod_gradient/curvegradient.cpp b/synfig-core/trunk/src/modules/mod_gradient/curvegradient.cpp index d76d76d..508a464 100644 --- a/synfig-core/trunk/src/modules/mod_gradient/curvegradient.cpp +++ b/synfig-core/trunk/src/modules/mod_gradient/curvegradient.cpp @@ -237,6 +237,7 @@ CurveGradient::color_func(const Point &point_, int quality, float supersample)co Real dist; float perp_dist; + bool edge_case = false; if(bline.size()==0) return Color::alpha(); @@ -306,6 +307,31 @@ CurveGradient::color_func(const Point &point_, int quality, float supersample)co p1=curve(t); // the closest point on the curve tangent=deriv(t).norm(); // the unit tangent at that point + // if the point we're nearest to is at either end of the + // bline, our distance from the curve is the distance from the + // point on the curve. we need to know which side of the + // curve we're on, so find the average of the two tangents at + // this point + if (t<0.00001 || t>0.99999) + { + if (t<0.5) + { + if (iter->get_split_tangent_flag()) + { + tangent=(iter->get_tangent1().norm()+tangent).norm(); + edge_case=true; + } + } + else + { + if (next->get_split_tangent_flag()) + { + tangent=(next->get_tangent2().norm()+tangent).norm(); + edge_case=true; + } + } + } + if(perpendicular) { tangent*=curve_length_; @@ -340,7 +366,15 @@ CurveGradient::color_func(const Point &point_, int quality, float supersample)co } else // not perpendicular { - diff=tangent.perp()*thickness*width; + if (edge_case) + { + diff=(p1-(point_-offset)); + if(diff*tangent.perp()<0) diff=-diff; + diff=diff.norm()*thickness*width; + } + else + diff=tangent.perp()*thickness*width; + p1-=diff*0.5; const Real mag(diff.inv_mag()); supersample=supersample*mag; -- 2.7.4