pub mod trace {
pub use crate::topological::trace::*;
}
pub use crate::result::{RejectedFeature, RejectionReason};
use crate::detect::{detect_grid_all_internal, DetectionRequest};
use crate::error::{GridError, Result};
use crate::result::GridDetection;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct ComponentDiagnostics {
rejected: Vec<RejectedFeature>,
}
impl ComponentDiagnostics {
pub fn rejected(&self) -> &[RejectedFeature] {
&self.rejected
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct DetectionDiagnostics {
schema_version: u32,
components: Vec<ComponentDiagnostics>,
}
impl DetectionDiagnostics {
pub fn schema_version(&self) -> u32 {
self.schema_version
}
pub fn components(&self) -> &[ComponentDiagnostics] {
&self.components
}
}
pub fn detect_grid_all(
request: DetectionRequest<'_>,
) -> Result<(Vec<GridDetection>, DetectionDiagnostics)> {
let solutions = detect_grid_all_internal(request)?;
let mut detections = Vec::with_capacity(solutions.len());
let mut components = Vec::with_capacity(solutions.len());
for solution in solutions {
detections.push(solution.detection);
components.push(ComponentDiagnostics {
rejected: solution.rejected,
});
}
Ok((
detections,
DetectionDiagnostics {
schema_version: 1,
components,
},
))
}
pub fn detect_grid(request: DetectionRequest<'_>) -> Result<(GridDetection, ComponentDiagnostics)> {
let (mut detections, diagnostics) = detect_grid_all(request)?;
if detections.is_empty() {
return Err(GridError::InsufficientEvidence);
}
let detection = detections.remove(0);
let component = diagnostics
.components
.into_iter()
.next()
.unwrap_or(ComponentDiagnostics {
rejected: Vec::new(),
});
Ok((detection, component))
}