def target.within

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

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

5135# The target's rectangle intersected with a device box, as a target.
5136def target.within(+t: Target, +box: Bounds) -> Target:
5137  Target{x, y, w, h} = t
5138  Bounds{bx0, by0, bx1, by1} = box
5139  +x0 = F32.to_u32(U.clamp(F32.floor(bx0), U32.to_f32(x), U32.to_f32((x + w : U32))))
5140  +y0 = F32.to_u32(U.clamp(F32.floor(by0), U32.to_f32(y), U32.to_f32((y + h : U32))))
5141  +x1 = F32.to_u32(U.clamp(F32.ceil(bx1), U32.to_f32(x), U32.to_f32((x + w : U32))))
5142  +y1 = F32.to_u32(U.clamp(F32.ceil(by1), U32.to_f32(y), U32.to_f32((y + h : U32))))
5143  Target{x0, y0, U.choose(U32, U32.is_gt(x1, x0), (x1 - x0 : U32), 0), U.choose(U32, U32.is_gt(y1, y0), (y1 - y0 : U32), 0)}

Uses (12)

Used by (1)