def first_half

bend-visgraph@2.0.0.0 · visgraph.bend:760

import bend-visgraph@2.0.0.0/visgraph.bend as Visgraph
import Base

760# How many of the first `count` of `len` points do half the sweeps' work. A
761# natural sweep walks every point right of its start, so the first c starts
762# walk c (2 len - 1 - c) / 2 points; a horizontal sweep stops early, so
763# halving the starts is close enough.
764def first_half(g: Visibility, +len: U32, +count: U32) -> U32:
765  match g:
766    case Natural{}:
767      +b = F32.sub(F32.mul(2.0, U32.to_f32(len)), 1.0)
768      +c = U32.to_f32(count)
769      U32.min(count, F32.to_u32(F32.div(F32.sub(b, F32.sqrt(F32.sub(F32.mul(b, b), F32.mul(2.0, F32.mul(c, F32.sub(b, c)))))), 2.0)))
770    case Horizontal{}:
771      U32.div(count, 2)

Uses (10)

Used by (1)