diff --git a/powerboxesrs/src/tiou.rs b/powerboxesrs/src/tiou.rs index 5505ba0..f9ca6ce 100644 --- a/powerboxesrs/src/tiou.rs +++ b/powerboxesrs/src/tiou.rs @@ -1,3 +1,5 @@ +use std::vec; + use ndarray::Array2; use num_traits::{Num, ToPrimitive}; @@ -41,26 +43,29 @@ where let mut tiou_matrix = Array2::::zeros((num_boxes1, num_boxes2)); let areas_boxes1 = boxes::box_areas(&boxes1); let areas_boxes2 = boxes::box_areas(&boxes2); - for (i, a1) in boxes1.outer_iter().enumerate() { - let a1_x1 = a1[0]; - let a1_y1 = a1[1]; - let a1_x2 = a1[2]; - let a1_y2 = a1[3]; + let boxes1_vecs: Vec<(N, N, N, N)> = boxes1 + .rows() + .into_iter() + .map(|r| (r[0], r[1], r[2], r[3])) + .collect(); + let boxes2_vecs: Vec<(N, N, N, N)> = boxes2 + .rows() + .into_iter() + .map(|r| (r[0], r[1], r[2], r[3])) + .collect(); + for (i, a1) in boxes1_vecs.iter().enumerate() { + let (a1_x1, a1_y1, a1_x2, a1_y2) = a1; let area1 = areas_boxes1[i]; - for (j, a2) in boxes2.outer_iter().enumerate() { - let a2_x1 = a2[0]; - let a2_y1 = a2[1]; - let a2_x2 = a2[2]; - let a2_y2 = a2[3]; + for (j, a2) in boxes2_vecs.iter().enumerate() { + let (a2_x1, a2_y1, a2_x2, a2_y2) = a2; let area2 = areas_boxes2[j]; - // Calculate the enclosing box (C) coordinates - let c_x1 = utils::min(a1_x1, a2_x1); - let c_y1 = utils::min(a1_y1, a2_y1); - let c_x2 = utils::max(a1_x2, a2_x2); - let c_y2 = utils::max(a1_y2, a2_y2); + let c_x1 = utils::min(*a1_x1, *a2_x1); + let c_y1 = utils::min(*a1_y1, *a2_y1); + let c_x2 = utils::max(*a1_x2, *a2_x2); + let c_y2 = utils::max(*a1_y2, *a2_y2); // Calculate the area of the enclosing box (C) let c_area = (c_x2 - c_x1) * (c_y2 - c_y1); let c_area = c_area.to_f64().unwrap();