pub struct PixelSpace;
pub type PixelPoint = euclid::Point2D<i32, PixelSpace>;
pub type PixelVector = euclid::Vector2D<i32, PixelSpace>;
pub type PixelSize = euclid::Size2D<i32, PixelSpace>;
pub type PixelRect = euclid::Rect<i32, PixelSpace>;
pub type PixelBox = euclid::Box2D<i32, PixelSpace>;
pub type PixelSideOffsets = euclid::SideOffsets2D<i32, PixelSpace>;
pub fn clip_to(
img1_clip_box: PixelBox,
img2_clip_box: PixelBox,
img1_victim_box: PixelBox,
img2_victim_box: PixelBox,
) -> Option<(PixelBox, PixelBox)> {
if img1_victim_box.size() != img2_victim_box.size() || img1_victim_box.is_empty() {
return None;
}
let adj = PixelSideOffsets {
left: (img1_clip_box.min.x - img1_victim_box.min.x)
.max(img2_clip_box.min.x - img2_victim_box.min.x)
.max(0),
top: (img1_clip_box.min.y - img1_victim_box.min.y)
.max(img2_clip_box.min.y - img2_victim_box.min.y)
.max(0),
right: (img1_victim_box.max.x - img1_clip_box.max.x)
.max(img2_victim_box.max.x - img2_clip_box.max.x)
.max(0),
bottom: (img1_victim_box.max.y - img1_clip_box.max.y)
.max(img2_victim_box.max.y - img2_clip_box.max.y)
.max(0),
..Default::default()
};
Some((
img1_victim_box.inner_box(adj),
img2_victim_box.inner_box(adj),
))
}