def filter.region
gralha-svg-render@0.1.0.1 · svg.bend:2599
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-xml-doc@0.1.0.1/xml.bend as XML
2599def filter.region(+as: List<&2, XML.Attr>, box: Bounds, +w: F32, +h: F32, +primitiveBox: Bool) -> Bounds:
2600 Bounds{x0, y0, x1, y1} = box
2601 +bx = x0
2602 +by = y0
2603 +bw = (x1 - bx : F32)
2604 +bh = (y1 - by : F32)
2605 +user = U.string.equal(XML.attr.get(as, "filterUnits", "objectBoundingBox"), "userSpaceOnUse")
2606 +fw = U.choose(F32, user, w, bw)
2607 +fh = U.choose(F32, user, h, bh)
2608 +x = (U.choose(F32, user, 0.0, bx) + filter.dimension(as, "x", fw, "-10%", user) : F32)
2609 +y = (U.choose(F32, user, 0.0, by) + filter.dimension(as, "y", fh, "-10%", user) : F32)
2610 +width = filter.dimension(as, "width", fw, "120%", user)
2611 +height = filter.dimension(as, "height", fh, "120%", user)
2612 U.branch(Bounds, (user || (F32.is_gt(bw, 0.0) && F32.is_gt(bh, 0.0))) && (Bool.not(primitiveBox) || (F32.is_gt(bw, 0.0) && F32.is_gt(bh, 0.0))),
2613 _ => U.branch(Bounds, primitiveBox, _ => Bounds{((x - bx) / bw : F32), ((y - by) / bh : F32), ((x + width - bx) / bw : F32), ((y + height - by) / bh : F32)},
2614 _ => Bounds{x, y, (x + width : F32), (y + height : F32)}), _ => bounds.empty())