private static float GetT(this SplineBase spline, float tStart, float tEnd, Vector3 testPoint, ref int iter, float eps = 0.01f) { iter++; float sqrEps = eps * eps; Vector3 start = spline.GetPoint(tStart); Vector3 end = spline.GetPoint(tEnd); Vector3 toStart = start - testPoint; Vector3 toEnd = end - testPoint; if (toStart.sqrMagnitude < toEnd.sqrMagnitude) { if ((end - start).sqrMagnitude <= sqrEps) { return(tStart); } return(spline.GetT(tStart, (tStart + tEnd) / 2.0f, testPoint, ref iter, eps)); } if ((end - start).sqrMagnitude <= sqrEps) { return(tEnd); } return(spline.GetT((tStart + tEnd) / 2.0f, tEnd, testPoint, ref iter, eps)); }