use crate::renderer::render_tree::BoundingBox;
pub(crate) fn rectangle(clip: BoundingBox, [a, b, c, d, e, f]: [f64; 6]) -> Option<BoundingBox> {
if ![clip.x, clip.y, clip.width, clip.height, a, b, c, d, e, f]
.into_iter()
.all(f64::is_finite)
|| clip.width <= 0.0
|| clip.height <= 0.0
|| a <= 0.0
|| d <= 0.0
|| b != 0.0
|| c != 0.0
{
return None;
}
let left = (a * clip.x + e).floor();
let top = (d * clip.y + f).floor();
let right = (a * (clip.x + clip.width) + e).ceil();
let bottom = (d * (clip.y + clip.height) + f).ceil();
let mapped = BoundingBox::new(
(left - e) / a,
(top - f) / d,
(right - left) / a,
(bottom - top) / d,
);
[mapped.x, mapped.y, mapped.width, mapped.height]
.into_iter()
.all(f64::is_finite)
.then_some(mapped)
}