Skip to main content

box_convert

Function box_convert 

Source
pub fn box_convert<'a, N, BA>(
    boxes: BA,
    in_fmt: BoxFormat,
    out_fmt: BoxFormat,
) -> Array2<N>
where N: Num + PartialEq + PartialOrd + ToPrimitive + Clone + Copy + 'a, BA: Into<ArrayView2<'a, N>>,
Expand description

Converts a 2D array of boxes from one format to another.

§Arguments

  • boxes - A 2D array of boxes in the input format.
  • in_fmt - The input format of the boxes.
  • out_fmt - The desired output format of the boxes.

§Returns

A 2D array of boxes in the output format.

§Example

use ndarray::arr2;
use powerboxesrs::boxes::{BoxFormat, box_convert};

let boxes = arr2(&[
    [10.0, 20.0, 30.0, 40.0],
    [75.0, 25.0, 100.0, 200.0],
    [100.0, 100.0, 101.0, 101.0],
]);
let expected_output = arr2(&[
    [20.0, 30.0, 20.0, 20.0],
    [87.5, 112.5, 25.0, 175.0],
    [100.5, 100.5, 1.0, 1.0],
]);
let output = box_convert(&boxes, BoxFormat::XYXY, BoxFormat::CXCYWH);
assert_eq!(output, expected_output);