def edge.distance

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

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

543def edge.distance(+e: Edge, +p: Point) -> F32:
544  Edge{ax, ay, bx, by, stroked, closed} = e
545  +a = {Point{ax, ay} : Point}
546  +ab = point.sub(Point{bx, by}, a)
547  +den = point.dot(ab, ab)
548  +t = U.clamp((point.dot(point.sub(p, a), ab) / U.max(0.000000000001, den) : F32), 0.0, 1.0)
549  U.choose(F32, stroked, point.distance(p, point.add(a, point.scale(ab, t))), 100000000000000000000.0)

Uses (12)

Used by (1)