/// <summary> /// Computes the maximum squared distance from a point to the curve using the current parameterization. /// </summary> protected FLOAT FindMaxSquaredError(int first, int last, CubicBezier curve, out int split) { #if OPTIMIZED_FINDMAXSQUAREDERROR using var _ = FindMaxSquaredErrorMarker.Auto(); unsafe { using (_pts.ViewAsNativeArray(out var pts)) using (_u.ViewAsNativeArray(out var u)) { OptimizedHelpers.FindMaxSquaredError(first, last, curve, out split, (VECTOR *)pts.GetUnsafePtr(), (FLOAT *)u.GetUnsafePtr(), out var max); return(max); } } #else using var _ = FindMaxSquaredErrorMarker.Auto(); List <VECTOR> pts = _pts; List <FLOAT> u = _u; int s = (last - first + 1) / 2; int nPts = last - first + 1; FLOAT max = 0; for (int i = 1; i < nPts; i++) { VECTOR v0 = pts[first + i]; VECTOR v1 = curve.Sample(u[i]); FLOAT d = VectorHelper.DistanceSquared(v0, v1); if (d > max) { max = d; s = i; } } // split at point of maximum error split = s + first; if (split <= first) { split = first + 1; } if (split >= last) { split = last - 1; } return(max); #endif }