* Intersect two clips. `undefined` on an axis means unbounded; the other * clip's bound wins. If both are bounded, take the tighter constraint * (max of mins, min of maxes). If the resulting region is empty * (x1 >= x2 or y1 >= y2), writes clipped by it will be dropped.
(parent: Clip | undefined, child: Clip)
| 102 | * (x1 >= x2 or y1 >= y2), writes clipped by it will be dropped. |
| 103 | */ |
| 104 | function intersectClip(parent: Clip | undefined, child: Clip): Clip { |
| 105 | if (!parent) return child |
| 106 | return { |
| 107 | x1: maxDefined(parent.x1, child.x1), |
| 108 | x2: minDefined(parent.x2, child.x2), |
| 109 | y1: maxDefined(parent.y1, child.y1), |
| 110 | y2: minDefined(parent.y2, child.y2), |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | function maxDefined( |
| 115 | a: number | undefined, |
no test coverage detected