Cull draw command if shape does not intersect viewport.

This commit is contained in:
meehl committed 2026-08-24 11:41:57 +02:00
1 parent 2bbfd14c1b
commit 8ba72fd7df
2 files changed
+46 -4

No files matched your search

+23
View File
@@ -1,5 +1,6 @@
use crate::math::{Corners, Point, Rect, Size, Vector};
use bytemuck::{Pod, Zeroable};
use euclid::approxord::{max, min};
use euclid::num::Zero;
use std::fmt;
use std::hash::Hash;
@@ -135,3 +136,25 @@ where
)
}
}
impl<T, U> Quad<T, U>
where
T: Copy + PartialOrd,
{
/// Returns the axis-aligned bounding box containing this quad.
#[inline]
pub fn aabb(&self) -> Rect<T, U> {
let min_x = min(min(min(self.p0.x, self.p1.x), self.p2.x), self.p3.x);
let max_x = max(max(max(self.p0.x, self.p1.x), self.p2.x), self.p3.x);
let min_y = min(min(min(self.p0.y, self.p1.y), self.p2.y), self.p3.y);
let max_y = max(max(max(self.p0.y, self.p1.y), self.p2.y), self.p3.y);
Rect::new(Point::new(min_x, min_y), Point::new(max_x, max_y))
}
/// Tests intersection between this quad's AABB and a rectangle.
#[inline]
pub fn aabb_intersects_rect(&self, rect: &Rect<T, U>) -> bool {
self.aabb().intersects(rect)
}
}