def cubic.count

gralha-svg-render@0.1.0.1 · svg.bend:187

import gralha-svg-render@0.1.0.1/svg.bend as Svg
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U

187# Wang's bound: a cubic cut into n equal parameter steps stays within e of
188# its chords when n >= sqrt(3/4 * L / e), L the larger second difference of
189# the control points. The bound assumes the curvature all sits in one place,
190# so the tolerance is doubled to land near the adaptive count; the count is
191# fixed up front and each point costs one evaluation and no flatness test.
192def cubic.count(+p: Point, +a: Point, +b: Point, +q: Point, +tol: F32) -> U32:
193  +l = U.max(point.distance(point.add(p, b), point.scale(a, 2.0)), point.distance(point.add(a, q), point.scale(b, 2.0)))
194  F32.to_u32(U.clamp(F32.ceil(F32.sqrt((0.375 * l / U.max(tol, 0.000001) : F32))), 1.0, 1024.0))

Uses (13)

Used by (1)