/** * Exact bounding box calculation for paths with bezier curves * * Bezier curves can extend beyond their control points, so we need to find * the actual extrema by solving for where the derivative equals zero. */ import type { GlyphPath } from "../render/path.ts"; /** * Bounding box in 2D space */ export interface BBox { xMin: number; yMin: number; xMax: number; yMax: number; } /** * Calculate exact bounding box for a path * * For line segments: min/max of endpoints * For quadratic bezier: find t where derivative = 0, evaluate curve at those t values * For cubic bezier: solve quadratic for extrema, evaluate curve at those t values * * @param path - Path to calculate bounds for * @returns Bounding box or null for empty path */ export declare function getExactBounds(path: GlyphPath): BBox | null; /** * Find t values where a quadratic bezier has extrema * * For quadratic bezier B(t) = (1-t)²p0 + 2(1-t)t*p1 + t²p2 * Derivative: B'(t) = 2(1-t)(p1-p0) + 2t(p2-p1) * = 2(p1-p0) + 2t(p0-2p1+p2) * = 2[(p1-p0) + t(p0-2p1+p2)] * * Set B'(t) = 0: * (p1-p0) + t(p0-2p1+p2) = 0 * t = -(p1-p0)/(p0-2p1+p2) * = (p0-p1)/(p0-2p1+p2) * * @param p0 - Start point * @param p1 - Control point * @param p2 - End point * @returns Array of t values in [0,1] where extrema occur */ export declare function getQuadraticExtrema(p0: number, p1: number, p2: number): number[]; /** * Find t values where a cubic bezier has extrema * * For cubic bezier B(t) = (1-t)³p0 + 3(1-t)²t*p1 + 3(1-t)t²p2 + t³p3 * Derivative: B'(t) = 3(1-t)²(p1-p0) + 6(1-t)t(p2-p1) + 3t²(p3-p2) * * Simplified: B'(t) = at² + bt + c where: * a = 3(p3 - 3p2 + 3p1 - p0) * b = 6(p2 - 2p1 + p0) * c = 3(p1 - p0) * * Solve using quadratic formula: t = (-b ± √(b²-4ac)) / 2a * * @param p0 - Start point * @param p1 - First control point * @param p2 - Second control point * @param p3 - End point * @returns Array of t values in [0,1] where extrema occur */ export declare function getCubicExtrema(p0: number, p1: number, p2: number, p3: number): number[]; /** * Evaluate quadratic bezier at parameter t * * B(t) = (1-t)²p0 + 2(1-t)t*p1 + t²p2 * * @param p0 - Start point * @param p1 - Control point * @param p2 - End point * @param t - Parameter in [0,1] * @returns Value at t */ export declare function evaluateQuadratic(p0: number, p1: number, p2: number, t: number): number; /** * Evaluate cubic bezier at parameter t * * B(t) = (1-t)³p0 + 3(1-t)²t*p1 + 3(1-t)t²p2 + t³p3 * * @param p0 - Start point * @param p1 - First control point * @param p2 - Second control point * @param p3 - End point * @param t - Parameter in [0,1] * @returns Value at t */ export declare function evaluateCubic(p0: number, p1: number, p2: number, p3: number, t: number): number;