import { gaussQuadrature } from "flo-gauss-quadrature"; import { ds } from "../../local-properties-at-t/ds.js"; import { fromTo2InclErrorBound } from "../../transformation/split/from-to/from-to-2-incl-error-bound.js"; import { splitByCurvature } from "../../transformation/split/split-by-curvature.js"; /** * Returns the curve length of the given quadratic bezier curve within the * specified parameter interval. * * @param interval the paramter interval over which the length is * to be calculated (often `[0,1]`) * @param ps a quadratic bezier curve given by an ordered array of its control * points, e.g. `[[0,0],[1,1],[2,1]]` * @param maxCurviness optional maximum 'curviness' (defined as the total angle * change between consecutive line segments between the curve control points) * before subdivision occurs; defaults to 0.4 radians * @param gaussOrder the optional order of the Gaussian Quadrature performed * between curve segments; defaults to 16; can be 4,16 or 64 * * @internal */ function lengthBez2( interval: number[], ps: number[][], maxCurviness = 0.4, gaussOrder: 4|16|64 = 16): number { const tS = interval[0]; const tE = interval[1]; if (tS === tE) { return 0; } const [[x0, y0], [x1, y1], [x2, y2]] = ps; // Ensure zero length curve returns zero! if (x0 === x1 && x1 === x2 && y0 === y1 && y1 === y2) { return 0; } const ps_ = fromTo2InclErrorBound(ps,tS,tE).ps; const ts = splitByCurvature(ps_, maxCurviness); let total = 0; for (let i=0; i