import type { CurvePiece } from '../mat/curve-piece.js'; import type { FootAndEndpointInfo } from './foot-and-endpoint-info.js'; import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js'; import { getPotentialClosestPointsOnCurveCertified } from './get-potential-closest-points-on-curve-certified.js'; import { cullCurvePieces } from './cull-curve-pieces.js'; import { getBestDistanceSquared } from './get-best-distance-squared.js'; import { toP } from '../point-on-shape/to-p.js'; /** * Returns the closest boundary point to the given point, limited to the given * bezier pieces, including the beziers actually checked after culling. * * @param maxCoordPowerOf2 * @param curvePieces * @param x * * @internal */ function getCloseBoundaryPointsCertified( curvePieces: CurvePiece[], x: number[]): PrePointOnShape[] { // cull the pieces that cannot contain the closest point (the best // squared distance already includes a floating point tolerance) curvePieces = cullCurvePieces(curvePieces, x, getBestDistanceSquared(curvePieces, x)); const pInfos: FootAndEndpointInfo[] = []; for (let i=0; i { const { curve, t } = info; const { ps } = curve; const pDd = toP(ps, t); const p = pDd.map(c => c[0] + c[1]) return { curve, t, isSource: false, p, pDd }; }); } export { getCloseBoundaryPointsCertified };