def mask.rect
gralha-coverage@0.1.0.1 · cover.bend:1228
import gralha-coverage@0.1.0.1/cover.bend as Cover
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
1228def mask.rect(+width: U32, +height: U32, +box: CovBox, +trees: Bool) -> CovMask:
1229 CovBox{x0, y0, x1, y1} = box
1230 +gx = F32.to_u32(U.clamp(x0, 0.0, U32.to_f32(width)))
1231 +gy = F32.to_u32(U.clamp(y0, 0.0, U32.to_f32(height)))
1232 +ex = F32.to_u32(U.clamp(x1, 0.0, U32.to_f32(width)))
1233 +ey = F32.to_u32(U.clamp(y1, 0.0, U32.to_f32(height)))
1234 +w = (ex - gx : U32)
1235 +h = (ey - gy : U32)
1236 +depth = depth.for(U.choose(U32, U32.is_gt(w, h), w, h), 1, 0n)
1237 U.branch(CovMask, U32.is_ge(gx, ex) || U32.is_ge(gy, ey), _ => CovMask{0, 0, 0, 0, 0, 0n, CovTreed{CovFlat{0.0}}, True{}},
1238 _ => CovMask{gx, gy, w, h, U32.shln(1, depth), depth, rect.data(trees, depth, w, h), True{}})