// based on https://en.wikipedia.org/wiki/De_Boor%27s_algorithm /// <summary>Returns the point at the given De-Boor recursion depth, knot interval and parameter space u-value</summary> /// <param name="k">The index of the knot interval our u-value is inside</param> /// <param name="u">A value in parameter space. Note: this value has to be within the internal knot interval</param> public Vector2 Eval(int k, float u) { // make sure our buffer is ready if (evalBuffer == null || evalBuffer.Length != degree + 1) { evalBuffer = new Vector2[degree + 1]; } // populate points in the buffer for (int i = 0; i < degree + 1; i++) { evalBuffer[i] = points[i + k - degree]; } // calculate each layer until we've got only one point left for (int r = 1; r < degree + 1; r++) { for (int j = degree; j > r - 1; j--) { float alpha = Mathfs.InverseLerpSafe(knots[j + k - degree], knots[j + 1 + k - r], u); evalBuffer[j] = Vector2.LerpUnclamped(evalBuffer[j - 1], evalBuffer[j], alpha); } } return(evalBuffer[degree]); }