feat: Bbox drawing

This commit is contained in:
uttarayan21
2025-08-05 00:28:13 +05:30
parent df5584d797
commit 9fd0993cc3
3 changed files with 27 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
use crate::*;
use crate::{roi::RoiMut, *};
pub use color::Rgba8;
use ndarray::{Array1, Array3, ArrayViewMut3};
@@ -27,6 +27,8 @@ impl Drawable<ArrayViewMut3<'_, u8>> for Aabb2<usize> {
self.corners()
.iter()
.zip(self.padding(thickness).corners())
.cycle()
.take(5)
.tuple_windows()
.for_each(|((a, b), (c, d))| {
let bbox = Aabb2::from_vertices([*a, b, *c, d]).expect("Invalid bounding box");
@@ -49,5 +51,15 @@ impl Drawable<Array3<u8>> for Aabb2<usize> {
let pixel_size = canvas.dim().2;
let color = color.slice(ndarray::s![..pixel_size]);
let [x1y1, x2y1, x1y2, x2y2] = self.corners();
let right = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x2y1.x, x2y1.y + thickness);
dbg!(right);
canvas
.roi_mut(right)
.expect("Failed to get ROI")
.lanes_mut(ndarray::Axis(2))
.into_iter()
.for_each(|mut pixel| {
pixel.assign(&color);
});
}
}

View File

@@ -108,7 +108,8 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
let min = self.min_vertex();
let max = self.max_vertex();
*point > min && *point < max
// *point > min && *point < max
true
}
pub fn scale(self, vector: SVector<T, D>) -> Self
@@ -140,6 +141,18 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
other_min >= self_min && other_max <= self_max
}
pub fn clamp(&self, other: &Self) -> Self
where
T: core::ops::AddAssign,
T: core::ops::SubAssign,
T: PartialOrd,
{
if self.contains_bbox(other) {
return *other;
}
todo!()
}
pub fn union(&self, other: &Self) -> Self
where
T: core::ops::AddAssign,

View File

@@ -43,7 +43,6 @@ pub fn main() -> Result<()> {
.cast()
.ok_or(errors::Error)
.attach_printable("Failed to cast f32 to usize")?;
dbg!(bbox);
array.draw(bbox, color::palette::css::GREEN_YELLOW.to_rgba8(), 20);
break;
}