diff --git a/bounding-box/src/draw.rs b/bounding-box/src/draw.rs index 7a80864..1fa0b0e 100644 --- a/bounding-box/src/draw.rs +++ b/bounding-box/src/draw.rs @@ -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> for Aabb2 { 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> for Aabb2 { 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); + }); } } diff --git a/bounding-box/src/lib.rs b/bounding-box/src/lib.rs index 26e5b30..ffa0bf2 100644 --- a/bounding-box/src/lib.rs +++ b/bounding-box/src/lib.rs @@ -108,7 +108,8 @@ impl AxisAlignedBoundingBox { 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) -> Self @@ -140,6 +141,18 @@ impl AxisAlignedBoundingBox { 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, diff --git a/src/main.rs b/src/main.rs index 10d59e4..0d165b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; }