#[derive(Debug, Clone)]
pub struct MatchConfig {
pub search_multiple_scales: bool,
pub use_grayscale: bool,
pub scale_steps: Vec<f32>,
pub confidence: f32,
pub limit: usize,
pub parallel: bool,
}
impl Default for MatchConfig {
fn default() -> Self {
Self {
search_multiple_scales: true,
use_grayscale: false,
scale_steps: vec![1.0, 0.9, 0.8, 0.7, 0.6, 0.5],
confidence: 0.8,
limit: 100,
parallel: true,
}
}
}
impl MatchConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_multi_scale(mut self, enabled: bool) -> Self {
self.search_multiple_scales = enabled;
self
}
pub fn with_grayscale(mut self, enabled: bool) -> Self {
self.use_grayscale = enabled;
self
}
pub fn with_scale_steps(mut self, steps: Vec<f32>) -> Self {
self.scale_steps = steps;
self
}
pub fn with_confidence(mut self, confidence: f32) -> Self {
self.confidence = confidence.clamp(0.0, 1.0);
self
}
pub fn with_limit(mut self, limit: usize) -> Self {
self.limit = limit;
self
}
pub fn with_parallel(mut self, enabled: bool) -> Self {
self.parallel = enabled;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_defaults() {
let config = MatchConfig::default();
assert!(config.search_multiple_scales);
assert!(!config.use_grayscale);
assert_eq!(config.confidence, 0.8);
assert_eq!(config.limit, 100);
assert!(config.parallel);
assert!(!config.scale_steps.is_empty());
}
#[test]
fn test_config_builder() {
let config = MatchConfig::new()
.with_confidence(0.9)
.with_multi_scale(false)
.with_grayscale(true)
.with_limit(10);
assert_eq!(config.confidence, 0.9);
assert!(!config.search_multiple_scales);
assert!(config.use_grayscale);
assert_eq!(config.limit, 10);
}
#[test]
fn test_confidence_clamping() {
let config = MatchConfig::new().with_confidence(1.5);
assert_eq!(config.confidence, 1.0);
let config = MatchConfig::new().with_confidence(-0.5);
assert_eq!(config.confidence, 0.0);
}
}