feat: Draw bounding boxes correctly
This commit is contained in:
@@ -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