1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Zone analytics configuration.
use crate::{AnalyticsError, AnchorPolicy};
use sightloom_core::ClassId;
/// Configuration for [`crate::ZoneAnalytics`].
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ZoneAnalyticsConfig {
/// Which box anchor is tested for membership.
pub anchor: AnchorPolicy,
/// Consecutive inside samples required to confirm enter/dwell start.
pub enter_hysteresis: u32,
/// Consecutive outside samples required to confirm exit/dwell end.
pub exit_hysteresis: u32,
/// Missed frames tolerated before counting as outside.
pub missed_frame_tolerance: u32,
/// Optional class filter; `None` accepts all classes.
pub class_filter: Option<ClassId>,
/// Debounce dwell start in nanoseconds after enter confirmed.
pub dwell_start_debounce_ns: i64,
}
impl Default for ZoneAnalyticsConfig {
fn default() -> Self {
Self {
anchor: AnchorPolicy::Center,
enter_hysteresis: 1,
exit_hysteresis: 1,
missed_frame_tolerance: 0,
class_filter: None,
dwell_start_debounce_ns: 0,
}
}
}
impl ZoneAnalyticsConfig {
/// Validates hysteresis and debounce fields.
///
/// # Errors
///
/// Returns [`AnalyticsError::InvalidConfig`] when hysteresis is zero.
pub fn validate(self) -> Result<Self, AnalyticsError> {
if self.enter_hysteresis == 0 || self.exit_hysteresis == 0 {
return Err(AnalyticsError::InvalidConfig);
}
if self.dwell_start_debounce_ns < 0 {
return Err(AnalyticsError::InvalidConfig);
}
Ok(self)
}
}