def bitmap.nearest

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

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

2304# Inverse F32 transforms can place an exact texel boundary a few ulps above
2305# its integer value. Snap only that rounding neighborhood before tie-breaking.
2306def bitmap.nearest(+q: F32) -> F32:
2307  +integer = F32.floor((q + 0.5 : F32))
2308  +close = F32.is_le(F32.abs((q - integer : F32)), (U.max(1.0, F32.abs(q)) * 0.000000476837158203125 : F32))
2309  F32.ceil((U.choose(F32, close, integer, q) - 1.0 : F32))

Uses (10)

Used by (1)