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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Occurrences issued from geometry-facade faces (`quiddity._geometry_evidence.
//! GeometryEvidenceBridge`): faces resolved against the facade's own faces, in its order, and
//! published only when they keep one valid solid's proof.
//!
//! Python writes through an aggregate evidence writer; here the bridge builds the
//! [`Occurrence`] the family returns, its defining faces and the further constituent faces the
//! claim covers. Python's `local_degradation` (the aggregate's retry that skips, rather than
//! refuses, a candidate whose faces prove no solid) is not ported here: three corpus parts reach
//! that retry (`tests/fixtures/captured/local_degradation/capture.json`), but none of its skips
//! is a polygonal boss, the one family issuing through this bridge, so no capture shows the
//! bridge's degraded branch. Families whose skips the capture does show carry their own degraded
//! path (holes and pockets, `discover_locally_degraded`).
use super::evidence::{EvidenceError, Occurrence, common_valid_solid};
use super::experimental_geometry::GeometryGraph;
/// `GeometryEvidenceBridge`.
pub struct GeometryEvidence<'g, 'a> {
pub geometry: &'g GeometryGraph<'a>,
}
impl<'g, 'a> GeometryEvidence<'g, 'a> {
pub fn new(geometry: &'g GeometryGraph<'a>) -> Self {
GeometryEvidence { geometry }
}
/// `refs`: the distinct faces among *faces*, in the graph's order. A face outside the graph
/// is the caller's mistake and panics (Python raises).
pub fn refs(&self, faces: &[usize]) -> Vec<usize> {
for &f in faces {
assert!(
self.geometry.contains(f),
"face {f} is foreign to this geometry graph"
);
}
self.geometry
.faces()
.iter()
.copied()
.filter(|f| faces.contains(f))
.collect()
}
/// `proves_solid`: the faces all belong to one valid solid.
pub fn proves_solid(&self, refs: &[usize]) -> bool {
common_valid_solid(self.geometry.part, refs).is_some()
}
/// `validate_defining`: refuse a publication whose faces do not belong to one valid solid.
pub fn validate_defining(&self, refs: &[usize]) -> Result<(), EvidenceError> {
if self.proves_solid(refs) {
Ok(())
} else {
Err(EvidenceError::NoValidSolid)
}
}
/// `add_defining`: the occurrence of *record* defined by *refs*, its claim covering also the
/// *constituent* faces beyond them (held as the occurrence's consulted faces).
pub fn occurrence<R>(&self, record: R, refs: &[usize], constituent: &[usize]) -> Occurrence<R> {
Occurrence {
record,
defining: refs.to_vec(),
context: constituent
.iter()
.copied()
.filter(|f| !refs.contains(f))
.collect(),
}
}
}