use crate::classify::{Classification, Depth, Label, Status};
use crate::error::Result;
use crate::model::Model;
use crate::trace::{check_lines, Line, Segment, Tracing};
use crate::vec3::Vec3;
pub fn classify(model: &Model, points: &[Vec3], depth: Depth) -> Classification {
model.classify_impl(points, true, depth.level())
}
pub fn trace(model: &Model, lines: &[Line], depth: Depth) -> Result<Tracing> {
check_lines(lines)?;
Ok(model.trace_unchecked(lines, true, depth.level()))
}
pub fn traces_agree(model: &Model, line: &Line, a: &[Segment], b: &[Segment]) -> bool {
model.traces_agree(line, a, b)
}
pub fn segments_agree(model: &Model, line: &Line, a: &Segment, b: &Segment) -> bool {
model.segments_agree(line, a, b)
}
pub fn on_surface_next_to(point: &Label, segment: &Label) -> bool {
let k = point.path.len();
point.status == Status::OnSurface
&& segment.path.len() > k
&& segment.path[..k] == point.path[..]
&& point.involved.contains(&segment.path[k].cell)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::classify::Step;
fn step(cell: u32) -> Step {
Step {
cell,
lattice: None,
}
}
#[test]
fn on_surface_next_to_any_level_of_the_path() {
let segment = Label {
status: Status::Inside,
path: vec![step(7), step(40)],
involved: vec![],
};
let at = |path: Vec<Step>, cells: Vec<u32>| Label {
status: Status::OnSurface,
path,
involved: cells,
};
assert!(on_surface_next_to(
&at(vec![step(7)], vec![40, 41]),
&segment
));
assert!(on_surface_next_to(&at(vec![], vec![7, 9]), &segment));
assert!(!on_surface_next_to(&at(vec![], vec![8, 9]), &segment));
assert!(!on_surface_next_to(&at(vec![step(8)], vec![40]), &segment));
let gap = Label {
status: Status::Gap,
..at(vec![], vec![7])
};
assert!(!on_surface_next_to(&gap, &segment));
}
}