public double Sample(double x) { if (CubicBezier.AlmostEq(x, 0.0)) { return(this._y0); } if (CubicBezier.AlmostEq(x, 1.0)) { return(this._y3); } double num = this._y3 - this._y0; return(CubicBezier.AlmostEq(this._x1 * num, this._y1 - this._y0) && CubicBezier.AlmostEq((1.0 - this._x2) * num, this._y3 - this._y2) ? this._y0 + x * num : CubicBezier.CalcBezierY(this.GetTForX(x), this._y0, this._y1, this._y2, this._y3)); }
private double GetTForX(double aX) { double aA = 0.0; int index1 = 1; for (int index2 = 10; index1 != index2 && this._sampleValues[index1] <= aX; ++index1) { aA += 0.1; } int index3 = index1 - 1; double num1 = (aX - this._sampleValues[index3]) / (this._sampleValues[index3 + 1] - this._sampleValues[index3]); double num2 = aA + num1 * 0.1; double slopeX = CubicBezier.GetSlopeX(num2, this._x1, this._x2); return(slopeX < 0.001 ? (!CubicBezier.AlmostEq(slopeX, 0.0) ? CubicBezier.BinarySubdivide(aX, aA, aA + 0.1, this._x1, this._x2) : num2) : this.NewtonRaphsonIterate(aX, num2, this._x1, this._x2)); }