-/*! ========================================================================
-** Synfig
-** Template File
-** $Id: curvegradient.cpp,v 1.2 2005/01/13 06:48:39 darco Exp $
+/* === S Y N F I G ========================================================= */
+/*! \file curvegradient.cpp
+** \brief Template Header
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
** This package is free software; you can redistribute it and/or
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
** This package is free software; you can redistribute it and/or
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
SYNFIG_LAYER_SET_LOCAL_NAME(CurveGradient,_("Curve Gradient"));
SYNFIG_LAYER_SET_CATEGORY(CurveGradient,_("Gradients"));
SYNFIG_LAYER_SET_VERSION(CurveGradient,"0.0");
SYNFIG_LAYER_SET_LOCAL_NAME(CurveGradient,_("Curve Gradient"));
SYNFIG_LAYER_SET_CATEGORY(CurveGradient,_("Gradients"));
SYNFIG_LAYER_SET_VERSION(CurveGradient,"0.0");
/*
const float t(curve.find_closest(p,6,0.01,0.99));
/*
const float t(curve.find_closest(p,6,0.01,0.99));
- // Setup the derivative function
- etl::derivative<etl::hermite<Vector> > deriv(curve);
-
- int search_iterations(7);
-
- /*if(quality==0)search_iterations=8;
- else if(quality<=2)search_iterations=10;
- else if(quality<=4)search_iterations=8;
- */
- if(!perpendicular)
- {
- if(quality<=6)search_iterations=7;
- else if(quality<=7)search_iterations=6;
- else if(quality<=8)search_iterations=5;
- else search_iterations=4;
- }
- else
- {
- if(quality>7)
- search_iterations=4;
- }
-
- // Figure out the closest point on the curve
- const float t(curve.find_closest(point,search_iterations));
-
-
- // Calculate our values
- p1=curve(t);
- tangent=deriv(t).norm();
-
- if(perpendicular)
- {
- tangent*=curve_length_;
- p1-=tangent*perp_dist;
- tangent=-tangent.perp();
- }
- else
- {
- thickness=(next->get_width()-iter->get_width())*t+iter->get_width();
- }
+ // Setup the derivative function
+ etl::derivative<etl::hermite<Vector> > deriv(curve);
+
+ int search_iterations(7);
+
+ /*if(quality==0)search_iterations=8;
+ else if(quality<=2)search_iterations=10;
+ else if(quality<=4)search_iterations=8;
+ */
+ if(!perpendicular)
+ {
+ if(quality<=6)search_iterations=7;
+ else if(quality<=7)search_iterations=6;
+ else if(quality<=8)search_iterations=5;
+ else search_iterations=4;
+ }
+ else
+ {
+ if(quality>7)
+ search_iterations=4;
+ }
+
+ // Figure out the closest point on the curve
+ const float t(curve.find_closest(point,search_iterations));
+
+
+ // Calculate our values
+ p1=curve(t);
+ tangent=deriv(t).norm();
+
+ if(perpendicular)
+ {
+ tangent*=curve_length_;
+ p1-=tangent*perp_dist;
+ tangent=-tangent.perp();
+ }
+ else
+ {
+ thickness=(next->get_width()-iter->get_width())*t+iter->get_width();
+ }
- diff=tangent.perp()*thickness*width;
- p1-=diff*0.5;
- const Real mag(diff.inv_mag());
- supersample=supersample*mag;
- diff*=mag*mag;
- dist=((point_-offset)*diff-p1*diff);
+ diff=tangent.perp()*thickness*width;
+ p1-=diff*0.5;
+ const Real mag(diff.inv_mag());
+ supersample=supersample*mag;
+ diff*=mag*mag;
+ dist=((point_-offset)*diff-p1*diff);
- diff=tangent.perp();
- //p1-=diff*0.5;
- const Real mag(diff.inv_mag());
- supersample=supersample*mag;
- diff*=mag*mag;
- dist=((point_-offset)*diff-p1*diff);
+ diff=tangent.perp();
+ //p1-=diff*0.5;
+ const Real mag(diff.inv_mag());
+ supersample=supersample*mag;
+ diff*=mag*mag;
+ dist=((point_-offset)*diff-p1*diff);
- Color pool(gradient(dist,supersample*0.5).premult_alpha()*(1.0-(dist-supersample*0.5)));
- pool+=gradient((dist+supersample*0.5)-1.0,supersample*0.5).premult_alpha()*((dist+supersample*0.5)-1.0);
+ float left(supersample*0.5-(dist-1.0));
+ float right(supersample*0.5+(dist-1.0));
+ Color pool(gradient(1.0-(left*0.5),left).premult_alpha()*left/supersample);
+ if (zigzag) pool+=gradient(1.0-right*0.5,right).premult_alpha()*right/supersample;
+ else pool+=gradient(right*0.5,right).premult_alpha()*right/supersample;
- Color pool(gradient(dist,supersample*0.5).premult_alpha()*(dist+supersample*0.5));
- pool+=gradient(1.0-(dist-supersample*0.5),supersample*0.5).premult_alpha()*(-(dist-supersample*0.5));
+ float left(supersample*0.5-dist);
+ float right(supersample*0.5+dist);
+ Color pool(gradient(right*0.5,right).premult_alpha()*right/supersample);
+ if (zigzag) pool+=gradient(left*0.5,left).premult_alpha()*left/supersample;
+ else pool+=gradient(1.0-left*0.5,left).premult_alpha()*left/supersample;