feat: Bbox drawing
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user