sightloom_core/
overlap.rs1use crate::Rect;
4
5#[must_use]
7pub fn intersection_area(a: Rect, b: Rect) -> f32 {
8 a.intersection(b).area()
9}
10
11#[must_use]
15pub fn iou(a: Rect, b: Rect) -> f32 {
16 let intersection = intersection_area(a, b);
17 let union = a.area() + b.area() - intersection;
18
19 if union > 0.0 {
20 intersection / union
21 } else {
22 0.0
23 }
24}
25
26#[must_use]
30pub fn ios(a: Rect, b: Rect) -> f32 {
31 let smaller = a.area().min(b.area());
32
33 if smaller > 0.0 {
34 intersection_area(a, b) / smaller
35 } else {
36 0.0
37 }
38}