pico_detect/detect/
detection.rs

1use crate::traits::Region;
2
3/// Object detection data.
4#[derive(Debug, Copy, Clone)]
5pub struct Detection<R: Region> {
6    pub(crate) region: R,
7    pub(crate) score: f32,
8}
9
10impl<R: Region> Detection<R> {
11    /// Create a new detection with the specified region and score.
12    #[inline]
13    pub fn new(region: R, score: f32) -> Self {
14        assert!(score > 0.0);
15        Self { region, score }
16    }
17
18    /// Detection score.
19    #[inline]
20    pub fn score(&self) -> f32 {
21        self.score
22    }
23
24    /// Detection rectangle.
25    #[inline]
26    pub fn region(&self) -> &R {
27        &self.region
28    }
29}
30
31impl<R: Region> AsRef<R> for Detection<R> {
32    #[inline]
33    fn as_ref(&self) -> &R {
34        &self.region
35    }
36}
37
38impl<R: Region> PartialEq for Detection<R> {
39    #[inline]
40    fn eq(&self, other: &Self) -> bool {
41        self.score == other.score
42    }
43}
44
45impl<R: Region> PartialOrd for Detection<R> {
46    #[inline]
47    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
48        self.score.partial_cmp(&other.score)
49    }
50}