def reduce.cell
gralha-svg-render@0.1.0.1 · svg.bend:4282
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
import gralha-image@0.1.0.1/image.bend as Img
4282
4283def reduce.cell(+pixels: Img.Pixels, +side: U32, +x: U32, +y: U32, +w: U32, +h: U32, +fx: F32, +fy: F32) -> Img.Color:
4284 +x0 = (U32.to_f32(x) * fx : F32)
4285 +y0 = (U32.to_f32(y) * fy : F32)
4286 +x1 = U.min((x0 + fx : F32), U32.to_f32(w))
4287 +y1 = U.min((y0 + fy : F32), U32.to_f32(h))
4288 +ix = F32.to_u32(F32.floor(x0))
4289 +iy = F32.to_u32(F32.floor(y0))
4290 +area = ((x1 - x0) * (y1 - y0) : F32)
4291 U.branch(Img.Color, F32.is_le(area, 0.0), _ => Img.clear(),
4292 _ => color.fade(reduce.rows(pixels, side, ix, iy, x0, x1, y0, y1, U32.to_nat((F32.to_u32(F32.ceil(x1)) - ix : U32)), U32.to_nat((F32.to_u32(F32.ceil(y1)) - iy : U32)), Img.clear()), (1.0 / area : F32)))
4293
4294@unsafe