Files
face-detector/test_bbox_replacement.rs
uttarayan21 dab7719206
Some checks failed
build / checks-matrix (push) Has been cancelled
build / checks-build (push) Has been cancelled
build / codecov (push) Has been cancelled
docs / docs (push) Has been cancelled
refactor: replace bbox::BBox with bounding_box::Aabb2 across codebase
2025-08-22 18:14:58 +05:30

66 lines
1.8 KiB
Rust

//! Simple test to verify that the bbox replacement from bbox::BBox to bounding_box::Aabb2 works correctly
use bounding_box::Aabb2;
#[test]
fn test_bbox_replacement() {
// Test basic construction
let bbox1 = Aabb2::from_xywh(10.0, 20.0, 100.0, 200.0);
assert_eq!(bbox1.x1(), 10.0);
assert_eq!(bbox1.y1(), 20.0);
assert_eq!(bbox1.x2(), 110.0);
assert_eq!(bbox1.y2(), 220.0);
// Test from coordinates
let bbox2 = Aabb2::from_x1y1x2y2(10.0, 20.0, 110.0, 220.0);
assert_eq!(bbox2.x1(), 10.0);
assert_eq!(bbox2.y1(), 20.0);
assert_eq!(bbox2.x2(), 110.0);
assert_eq!(bbox2.y2(), 220.0);
// Test equality
assert_eq!(bbox1.x1(), bbox2.x1());
assert_eq!(bbox1.y1(), bbox2.y1());
assert_eq!(bbox1.x2(), bbox2.x2());
assert_eq!(bbox1.y2(), bbox2.y2());
// Test contains
let smaller = Aabb2::from_xywh(20.0, 30.0, 50.0, 100.0);
assert!(bbox1.contains_bbox(&smaller));
// Test padding
let padded = bbox1.padding(10.0);
assert_eq!(padded.x1(), 5.0);
assert_eq!(padded.y1(), 15.0);
assert_eq!(padded.x2(), 115.0);
assert_eq!(padded.y2(), 225.0);
// Test scale
let scaled = bbox1.scale(nalgebra::Vector2::new(2.0, 2.0));
assert_eq!(scaled.x1(), -40.0);
assert_eq!(scaled.y1(), -80.0);
assert_eq!(scaled.x2(), 160.0);
assert_eq!(scaled.y2(), 320.0);
println!("All bbox replacement tests passed!");
}
#[test]
fn test_integer_bbox() {
// Test with integer types
let bbox = Aabb2::from_xywh(1, 2, 10, 20);
assert_eq!(bbox.x1(), 1);
assert_eq!(bbox.y1(), 2);
assert_eq!(bbox.x2(), 11);
assert_eq!(bbox.y2(), 22);
let area = bbox.area();
assert_eq!(area, 200);
}
fn main() {
test_bbox_replacement();
test_integer_bbox();
println!("Test completed successfully!");
}