feat: Draw bounding boxes correctly
This commit is contained in:
@@ -48,15 +48,13 @@ impl Drawable<Array3<u8>> for Aabb2<usize> {
|
||||
let color = Array1::from_vec(vec![color.r, color.g, color.b, color.a]);
|
||||
let pixel_size = canvas.dim().2;
|
||||
let color = color.slice(ndarray::s![..pixel_size]);
|
||||
let [x1y1, x2y1, x1y2, x2y2] = self.corners();
|
||||
dbg!(self.corners());
|
||||
let [x1y1, x2y1, x2y2, x1y2] = self.corners();
|
||||
let top = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x2y1.x, x2y1.y + thickness);
|
||||
let bottom = Aabb2::from_x1y1x2y2(x2y2.x, x2y2.y, x1y2.x, x1y2.y + thickness);
|
||||
let bottom = Aabb2::from_x1y1x2y2(x1y2.x, x1y2.y, x2y2.x, x2y2.y + thickness);
|
||||
let left = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x1y2.x + thickness, x1y2.y);
|
||||
// let right = Aabb2::from_x1y1x2y2(x2y2.x, x2y2.y, x2y1.x + thickness, x2y1.y);
|
||||
let lines = [top, bottom, left /* right */];
|
||||
let right = Aabb2::from_x1y1x2y2(x2y1.x, x2y1.y, x2y2.x + thickness, x2y2.y + thickness);
|
||||
let lines = [top, bottom, left, right];
|
||||
lines.into_iter().for_each(|line| {
|
||||
dbg!(line);
|
||||
canvas
|
||||
.roi_mut(line)
|
||||
.expect("Failed to get Roi")
|
||||
|
||||
@@ -2,6 +2,7 @@ pub mod draw;
|
||||
pub mod nms;
|
||||
pub mod roi;
|
||||
|
||||
use itertools::Itertools;
|
||||
use nalgebra::{Point, Point2, Point3, SVector};
|
||||
pub trait Num: num::Num + Copy + core::fmt::Debug + 'static {}
|
||||
impl<T: num::Num + Copy + core::fmt::Debug + 'static> Num for T {}
|
||||
@@ -108,8 +109,7 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
|
||||
let min = self.min_vertex();
|
||||
let max = self.max_vertex();
|
||||
|
||||
// *point > min && *point < max
|
||||
true
|
||||
*point >= min && *point <= max
|
||||
}
|
||||
|
||||
pub fn scale(self, vector: SVector<T, D>) -> Self
|
||||
@@ -241,7 +241,6 @@ impl<T: Num> Aabb2<T> {
|
||||
{
|
||||
let point1 = Point2::new(x1, y1);
|
||||
let point2 = Point2::new(x2, y2);
|
||||
dbg!(point1, point2);
|
||||
Self::from_min_max_vertices(point1, point2)
|
||||
}
|
||||
pub fn new_2d(point1: Point2<T>, point2: Point2<T>) -> Self
|
||||
@@ -451,3 +450,29 @@ fn test_bounding_box_intersection_2d() {
|
||||
assert_eq!(intersection_bbox.min_vertex(), Point2::new(3.0, 5.0));
|
||||
assert_eq!(intersection_bbox.size(), Vector2::new(1.0, 1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bounding_box_contains_point() {
|
||||
use nalgebra::Point2;
|
||||
|
||||
let point1 = Point2::new(2, 3);
|
||||
let point2 = Point2::new(5, 4);
|
||||
let bbox = AxisAlignedBoundingBox::new_2d(point1, point2);
|
||||
for (i, j) in (0..=10).cartesian_product(0..=10) {
|
||||
if bbox.contains_point(&Point2::new(i, j)) {
|
||||
if !(2..=5).contains(&i) && !(3..=4).contains(&j) {
|
||||
panic!(
|
||||
"Point ({}, {}) should not be contained in the bounding box",
|
||||
i, j
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (2..=5).contains(&i) && (3..=4).contains(&j) {
|
||||
panic!(
|
||||
"Point ({}, {}) should be contained in the bounding box",
|
||||
i, j
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user