CurveUtil.js revision cec703a844d9691646231634fe709f4ea41d278a
/**
* Utility class used for calculating curve points.
*
* @class CurveUtil
* @constructor
*/
function CurveUtil()
{
}
/**
* Creates an array of start, end and control points for splines.
*
* @method getCurveControlPoints
* @param {Array} xcoords Collection of x-coordinates used for calculate the curves
* @param {Array} ycoords Collection of y-coordinates used for calculate the curves
* @return Object
* @protected
*/
{
var outpoints = [],
i = 1,
xvals = [],
yvals = [];
// Too few points, need at least two
if (l < 1)
{
return null;
}
outpoints[0] = {
};
// Special case, the Bezier should be a straight line
if (l === 1)
{
return outpoints;
}
for (; i < l; ++i)
{
outpoints.push({startx: Math.round(xcoords[i]), starty: Math.round(ycoords[i]), endx: Math.round(xcoords[i+1]), endy: Math.round(ycoords[i+1])});
}
for (i = 0; i < l; ++i)
{
if (i < l-1)
{
}
else
{
}
}
return outpoints;
},
/**
* Gets the control points for the curve.
*
* @method getControlPoints
* @param {Array} vals Collection of values coords used to generate control points.
* @return Array
* @private
*/
getControlPoints: function(vals)
{
x = [],
tmp = [],
b = 2.0,
i = 1;
for (; i < l; ++i)
{
tmp[i] = 1/b;
x[i] = (vals[i] - x[i-1]) / b;
}
for (i = 1; i < l; ++i)
{
x[l-i-1] -= tmp[l-i] * x[l-i];
}
return x;
}
};