opencv_core/
range.rs

1//! Range structure for OpenCV
2
3use std::fmt;
4
5/// Range structure
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct Range {
8    pub start: i32,
9    pub end: i32,
10}
11
12impl Range {
13    /// Create a new range
14    pub fn new(start: i32, end: i32) -> Self {
15        Self { start, end }
16    }
17
18    /// Create an all-inclusive range
19    pub fn all() -> Self {
20        Self { start: i32::MIN, end: i32::MAX }
21    }
22
23    /// Get the size of the range
24    pub fn size(&self) -> i32 {
25        self.end - self.start
26    }
27
28    /// Check if the range is empty
29    pub fn empty(&self) -> bool {
30        self.start >= self.end
31    }
32}
33
34impl Default for Range {
35    fn default() -> Self {
36        Self::all()
37    }
38}
39
40impl fmt::Display for Range {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        write!(f, "[{}, {})", self.start, self.end)
43    }
44}