pub mod analytic_surfaces;
pub mod angled_steps;
pub mod bevel;
pub mod blend_view;
pub mod blends;
pub mod body;
pub mod bosses;
pub mod chamfers;
pub mod channels;
pub mod circular_blind_steps;
pub mod circular_face_patterns;
pub mod through_notches;
pub mod v_channels;
internal_entry! { pub mod context; }
pub mod annular_grooves;
pub mod countersinks;
pub mod cylinders;
pub mod cylindrical_channels;
pub mod cylindrical_end_surface;
pub mod cylindrical_passages;
pub mod cylindrical_pockets;
pub mod cylindrical_seats;
pub mod discovery;
pub mod edge_open;
pub mod edge_open_circular;
pub mod edge_open_prismatic;
pub mod effective_surfaces;
pub mod entry_treatments;
pub mod evidence;
pub mod experimental_geometry;
pub mod fillets;
pub mod flats;
pub mod freeform_surfaces;
pub mod geometry_evidence;
pub mod graph;
pub mod grooves;
pub mod gussets;
pub mod hole_patterns;
pub mod holes;
pub mod interior_voids;
pub mod levels;
pub mod modelled_threads;
pub mod oblique_through_steps;
pub mod oriented_chamfers;
pub mod oriented_slots;
pub mod outer_profile;
pub mod pads;
pub mod paired_ramp_steps;
pub mod passage_compat;
pub mod passages;
pub(crate) mod pattern_geometry;
pub mod placed;
pub mod plane_envelope_passages;
pub mod planes;
pub mod plates;
pub mod pockets;
pub mod policy;
pub mod polygonal_bosses;
pub mod prismatic_pockets;
pub mod probes;
pub mod profiled_bores;
pub mod recess_core;
pub mod recess_faces;
pub mod recess_obround;
pub mod recess_patterns;
pub mod recess_radii;
pub mod recess_records;
pub mod recess_reduce;
pub mod reconcile;
pub mod rectangular_blind_slots;
pub mod regions;
pub mod repeating_profiles;
pub mod rings;
pub mod round_bottom_slots;
pub mod section_passages;
pub mod section_recess;
pub mod section_recess_discovery;
pub mod section_recess_family;
pub mod section_recess_geometry;
pub mod sections;
pub mod semicircular_blind_slots;
pub mod sheet_metal;
pub mod slots;
pub mod solid_properties;
pub mod stacks;
pub mod support_patches;
pub mod thin_walls;
pub mod through_steps;
pub mod turned;
pub mod turned_steps;
pub mod volume_probe;
pub mod wire_seed;
internal_entry! { pub use context::Context; }
pub use evidence::{EvidenceError, Occurrence};
use std::collections::{BTreeMap, BTreeSet};
use serde::Serialize;
use crate::kernel::brep::Part;
#[derive(Clone, Debug, Default, Serialize)]
pub struct Features {
#[serde(skip)]
pub run_mode: evidence::RunMode,
#[serde(skip)]
pub discovery_refusals: BTreeMap<&'static str, Vec<discovery::DiscoveryRefusal>>,
#[serde(skip)]
pub evidence_status: BTreeMap<&'static str, Vec<evidence::EvidenceStatus>>,
pub fillets: Vec<fillets::Fillet>,
pub chamfers: Vec<chamfers::Chamfer>,
pub bosses: Vec<bosses::BossRecord>,
pub angled_steps: Vec<angled_steps::AngledStep>,
pub flats: Vec<flats::Flat>,
pub paired_ramp_steps: Vec<paired_ramp_steps::PairedRampStep>,
pub oriented_chamfers: Vec<oriented_chamfers::OrientedChamfer>,
pub circular_face_patterns: Vec<circular_face_patterns::CircularFacePattern>,
pub oblique_through_steps: Vec<oblique_through_steps::ObliqueThroughStep>,
pub circular_blind_steps: Vec<circular_blind_steps::CircularBlindStep>,
pub holes: Vec<holes::HoleRecord>,
pub countersinks: Vec<countersinks::CounterSink>,
pub hole_patterns: Vec<hole_patterns::HolePattern>,
pub gusset_ribs: Vec<gussets::GussetRib>,
pub gusset_rib_patterns: Vec<gussets::GussetRibPattern>,
pub thin_wall_bodies: Vec<thin_walls::ThinWallBody>,
pub interior_voids: Vec<interior_voids::InteriorVoid>,
#[serde(skip)]
pub interior_void_refusals: Vec<interior_voids::InteriorVoidRefusal>,
pub through_steps: Vec<through_steps::ThroughStep>,
pub turned_steps: Vec<turned_steps::TurnedStep>,
pub grooves: Vec<grooves::Groove>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub annular_grooves: Vec<annular_grooves::AnnularGroove>,
pub plates: Vec<plates::Plate>,
pub round_bottom_blind_slots: Vec<round_bottom_slots::RoundBottomBlindSlot>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub semicircular_blind_slots: Vec<semicircular_blind_slots::SemicircularBlindSlot>,
pub rectangular_blind_slots: Vec<rectangular_blind_slots::RectangularBlindSlot>,
pub double_d_bores: Vec<profiled_bores::DoubleDBore>,
pub edge_open_circular_pockets: Vec<edge_open_circular::EdgeOpenCircularPocket>,
pub edge_open_prismatic_recesses: Vec<edge_open_prismatic::EdgeOpenPrismaticRecess>,
pub blends: Vec<blends::Blend>,
pub sheet_metal_bodies: Vec<sheet_metal::SheetMetalBody>,
pub slots: Vec<slots::Slot>,
pub pockets: Vec<pockets::Pocket>,
pub channels: Vec<channels::Channel>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub v_channels: Vec<v_channels::VChannel>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub rectangular_through_notches: Vec<through_notches::RectangularThroughNotch>,
pub slot_patterns: Vec<recess_patterns::SlotPattern>,
pub pocket_patterns: Vec<recess_patterns::PocketPattern>,
pub repeating_radial_profiles: Vec<repeating_profiles::RepeatingRadialProfile>,
pub freeform_surfaces: Vec<freeform_surfaces::FreeformSurface>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub modelled_threads: Vec<modelled_threads::ModelledThread>,
#[serde(skip)]
pub modelled_thread_refusals: Vec<modelled_threads::ModelledThreadRefusal>,
pub polygonal_bosses: Vec<polygonal_bosses::PolygonalBoss>,
pub polygonal_stock: Vec<polygonal_bosses::PolygonalStock>,
pub section_passages: Vec<passages::SectionPassage>,
pub prismatic_pockets: Vec<prismatic_pockets::PrismaticPocket>,
pub oriented_slots: Vec<oriented_slots::OrientedSlot>,
pub oriented_slot_patterns: Vec<oriented_slots::OrientedSlotPattern>,
pub pads: Vec<pads::RaisedPad>,
pub step_levels: Vec<levels::FaceLevel>,
pub risers: Vec<levels::RiserEvidence>,
pub section_recesses: Vec<section_recess::SectionRecess>,
#[serde(skip)]
pub section_recess_patterns: Vec<section_recess::SectionRecessPattern>,
#[serde(skip)]
pub section_recess_refusals: Vec<section_recess::SectionRecessRefusal>,
#[serde(skip)]
pub section_recess_refusal: Option<section_recess_family::SectionRecessFamilyError>,
#[serde(skip)]
pub defining: Defining,
}
pub type Defining = BTreeMap<&'static str, Vec<Vec<usize>>>;
internal_entry! {
pub fn recognise(part: &Part) -> Features {
take_inventory(part, recognise_in).unwrap_or_else(|error| Features {
discovery_refusals: BTreeMap::from([("reconciliation_refusals", vec![
discovery::DiscoveryRefusal::new(error, 0..part.faces.len())
])]),
..Features::default()
})
}
}
fn recognise_in(ctx: &Context<'_>, inventory: Inventory) -> Features {
let projection = section_recess_family::section_recess_projection_in(ctx, &inventory);
let constituents = |family: &str| -> BTreeMap<Vec<usize>, Vec<usize>> {
inventory.physical.defining[family]
.iter()
.cloned()
.zip(inventory.constituent[family].iter().cloned())
.collect()
};
let hole_constituents = constituents("holes");
let boss_constituents = constituents("polygonal_bosses");
let mut features = inventory.accepted();
let (section_recesses, refusals, patterns, refusal) = match projection {
Ok(p) => (p.section_recesses, p.refusals, p.patterns, None),
Err(e) => (Vec::new(), Vec::new(), Vec::new(), Some(e)),
};
let defining = section_recesses
.iter()
.map(|r| r.evidence().defining_faces().to_vec())
.collect();
features.defining.insert("section_recesses", defining);
features.evidence_status.insert(
"section_recesses",
section_recesses
.iter()
.map(|r| {
evidence::strict_status(
ctx.part,
r.evidence().defining_faces(),
r.evidence().constituent_faces(),
)
})
.collect(),
);
features.section_recesses = section_recesses;
features.section_recess_refusals = refusals;
features.section_recess_patterns = patterns;
features.section_recess_refusal = refusal;
for (record, faces) in features
.holes
.iter()
.zip(features.defining.get_mut("holes").unwrap())
{
if let Some(constituent) = hole_constituents.get(faces) {
holes::claim_drill_point(ctx.part, record, faces, constituent);
}
}
for (record, faces) in features
.slots
.iter()
.zip(features.defining.get_mut("slots").unwrap())
{
slots::claim_rectangular_end_walls(ctx.part, record, faces);
}
for (record, faces) in features
.polygonal_bosses
.iter()
.zip(features.defining.get_mut("polygonal_bosses").unwrap())
{
if let Some(constituent) = boss_constituents.get(faces) {
polygonal_bosses::claim_terminal_cap(ctx.part, record, faces, constituent);
}
}
features
}
#[derive(Clone, Debug)]
pub struct Inventory {
pub physical: Features,
pub evidence: reconcile::Evidence,
pub dispositions: Vec<reconcile::Disposition>,
pub constituent: Defining,
}
impl Inventory {
internal_entry! {
pub fn accepted(self) -> Features {
let mut f = self.physical;
let mut rejected: BTreeMap<reconcile::Family, BTreeSet<usize>> = BTreeMap::new();
for d in &self.dispositions {
if d.outcome == reconcile::Outcome::Rejected {
rejected
.entry(d.candidate.family)
.or_default()
.insert(d.candidate.index);
}
}
for (family, indices) in &rejected {
let field = family.field().unwrap_or("risers");
let statuses = f
.evidence_status
.get_mut(field)
.expect("every candidate has a status");
drop_rejected(statuses, indices);
use reconcile::Family as F;
match family {
F::AngledSteps => drop_rejected(&mut f.angled_steps, indices),
F::Blends => drop_rejected(&mut f.blends, indices),
F::Bosses => drop_rejected(&mut f.bosses, indices),
F::Chamfers => drop_rejected(&mut f.chamfers, indices),
F::CircularBlindSteps => drop_rejected(&mut f.circular_blind_steps, indices),
F::DoubleDBores => drop_rejected(&mut f.double_d_bores, indices),
F::EdgeOpenCircularPockets => {
drop_rejected(&mut f.edge_open_circular_pockets, indices)
}
F::Fillets => drop_rejected(&mut f.fillets, indices),
F::Grooves => drop_rejected(&mut f.grooves, indices),
F::Holes => drop_rejected(&mut f.holes, indices),
F::OrientedSlots => drop_rejected(&mut f.oriented_slots, indices),
F::Passages => drop_rejected(&mut f.section_passages, indices),
F::Plates => drop_rejected(&mut f.plates, indices),
F::Pockets => drop_rejected(&mut f.pockets, indices),
F::PrismaticPockets => drop_rejected(&mut f.prismatic_pockets, indices),
F::RectangularBlindSlots => drop_rejected(&mut f.rectangular_blind_slots, indices),
F::Risers => {
drop_rejected(&mut f.risers, indices);
let defining = f.defining.get_mut("risers").expect("risers are carried");
drop_rejected(defining, indices);
continue;
}
F::Slots => drop_rejected(&mut f.slots, indices),
F::ThinWallBodies => drop_rejected(&mut f.thin_wall_bodies, indices),
F::TurnedSteps => drop_rejected(&mut f.turned_steps, indices),
}
let field = family.field().expect("a carried family has a field");
let defining = f
.defining
.get_mut(field)
.expect("every family has defining faces");
drop_rejected(defining, indices);
}
if let Some(plates) = rejected.get(&reconcile::Family::Plates)
&& let Some(defining) = f.defining.get_mut("rectangular_through_notches")
{
let gone: BTreeSet<usize> = f
.rectangular_through_notches
.iter()
.enumerate()
.filter(|(_, n)| plates.contains(&n.plate))
.map(|(i, _)| i)
.collect();
drop_rejected(&mut f.rectangular_through_notches, &gone);
drop_rejected(defining, &gone);
if let Some(statuses) = f.evidence_status.get_mut("rectangular_through_notches") {
drop_rejected(statuses, &gone);
}
}
f.hole_patterns = hole_patterns::recognise_hole_patterns(&f.holes);
f.gusset_rib_patterns = gussets::recognise_gusset_rib_patterns(&f.gusset_ribs);
f.slot_patterns = recess_patterns::recognise_slot_patterns(&f.slots);
f.pocket_patterns = recess_patterns::recognise_pocket_patterns(&f.pockets);
f.oriented_slot_patterns =
oriented_slots::recognise_oriented_slot_patterns(&f.oriented_slots);
f
}
}
}
fn drop_rejected<T>(items: &mut Vec<T>, indices: &BTreeSet<usize>) {
let mut at = 0;
items.retain(|_| {
let keep = !indices.contains(&at);
at += 1;
keep
});
}
internal_entry! {
pub fn inventory(part: &Part) -> Result<Inventory, reconcile::ReconcileError> {
take_inventory(part, |_, inventory| inventory)
}
}
pub(crate) fn take_inventory<'p, T>(
part: &'p Part,
then: impl FnOnce(&Context<'p>, Inventory) -> T,
) -> Result<T, reconcile::ReconcileError> {
if !evidence::local_degradation() {
let ctx = Context::new(part);
if let Some(inventory) = inventory_in(&ctx)? {
return Ok(then(&ctx, inventory));
}
}
evidence::locally_degraded(|| {
let ctx = Context::new(part);
let inventory = inventory_in(&ctx)?.expect("a locally degraded run does not retry");
Ok(then(&ctx, inventory))
})
}
fn degraded_skip<R>(
found: Vec<Occurrence<R>>,
proved: impl Fn(&Occurrence<R>) -> bool,
) -> Vec<Occurrence<R>> {
if !evidence::local_degradation() {
return found;
}
found.into_iter().filter(|o| proved(o)).collect()
}
fn skip_unproved<R>(part: &Part, found: Vec<Occurrence<R>>) -> Vec<Occurrence<R>> {
degraded_skip(found, |o| evidence::locally_proved(part, o))
}
pub(crate) fn inventory_in(
ctx: &Context<'_>,
) -> Result<Option<Inventory>, reconcile::ReconcileError> {
let part = ctx.part;
let seats = countersinks::discover(ctx);
let found_holes = holes::discover(ctx, &seats);
if !evidence::local_degradation() && holes::strict_refusal_retries(part, &seats, &found_holes) {
return Ok(None);
}
let found_holes = skip_unproved(part, found_holes);
let mut defining = Kept {
part,
claimed: Defining::new(),
defining: Defining::new(),
constituent: Defining::new(),
evidence_status: BTreeMap::new(),
};
let holes = kept(&mut defining, "holes", found_holes);
let countersinks = kept(&mut defining, "countersinks", seats);
let gusset_ribs = kept(&mut defining, "gusset_ribs", gussets::discover(ctx));
let slots = kept(
&mut defining,
"slots",
skip_unproved(part, slots::discover(ctx)),
);
let pocket_occurrences = skip_unproved(part, pockets::discover(ctx));
let thin_wall_bodies =
kept_shared(&mut defining, "thin_wall_bodies", thin_walls::discover(ctx));
let mut discovery_refusals = BTreeMap::new();
let passages = match passages::discover(ctx) {
Ok(found) => found,
Err(error) => {
let faces = passages::proposal_faces(ctx);
discovery_refusals.insert(
"section_passage_refusals",
vec![discovery::DiscoveryRefusal::new(error, faces)],
);
Vec::new()
}
};
let compatibility = if discovery_refusals.contains_key("section_passage_refusals") {
Vec::new()
} else {
passages::compatibility_views(ctx)?
};
let evidence = reconcile::Evidence::with_passage_views(ctx, &pocket_occurrences, compatibility);
let pockets = kept(&mut defining, "pockets", pocket_occurrences);
let oriented_slots = kept(
&mut defining,
"oriented_slots",
match oriented_slots::discover(ctx, &passages) {
Ok(found) => found,
Err(error) => {
discovery_refusals.insert(
"oriented_slot_refusals",
vec![discovery::DiscoveryRefusal::new(
error,
passages
.iter()
.flat_map(|p| p.defining.iter().chain(&p.context))
.copied(),
)],
);
Vec::new()
}
},
);
let thread_analysis = ctx.modelled_threads();
let claimed: BTreeSet<_> = thread_analysis
.threads
.iter()
.flat_map(|o| o.defining.iter().copied())
.collect();
let modelled_threads = if thread_analysis.threads.is_empty() {
Vec::new()
} else {
kept(
&mut defining,
"modelled_threads",
thread_analysis.threads.clone(),
)
};
let freeform_surfaces = kept_shared(
&mut defining,
"freeform_surfaces",
freeform_surfaces::discover(ctx, &thin_wall_bodies)
.into_iter()
.filter(|o| !claimed.contains(&o.record.face))
.collect(),
);
let step_level_occurrences = degraded_skip(levels::discover_step_levels(ctx), |o| {
evidence::locally_valid_solid(part, &o.defining).is_some()
});
let found_risers = degraded_skip(levels::discover_risers(ctx, &step_level_occurrences), |o| {
evidence::locally_valid_solid(part, &o.defining).is_some()
});
let risers = kept(&mut defining, "risers", found_risers);
let step_levels = kept(&mut defining, "step_levels", step_level_occurrences);
let void_analysis = interior_voids::analyse(ctx);
let plate_occurrences = plates::discover(ctx, &Default::default());
let channel_occurrences = skip_unproved(part, channels::discover(ctx));
let notches = through_notches::discover(ctx, &plate_occurrences, &channel_occurrences);
let boss_analysis = polygonal_bosses::analyse(ctx, &Default::default());
if !boss_analysis.refusals.is_empty() {
discovery_refusals.insert("polygonal_boss_refusals", boss_analysis.refusals);
}
let pad_analysis = pads::analyse(ctx, &Default::default());
let prismatic_analysis = prismatic_pockets::analyse(ctx);
if !pad_analysis.refusals.is_empty() {
discovery_refusals.insert("pad_refusals", pad_analysis.refusals);
}
if !prismatic_analysis.refusals.is_empty() {
discovery_refusals.insert("prismatic_pocket_refusals", prismatic_analysis.refusals);
}
let mut physical = Features {
discovery_refusals,
run_mode: if evidence::local_degradation() {
evidence::RunMode::LocallyDegraded
} else {
evidence::RunMode::Strict
},
chamfers: kept(
&mut defining,
"chamfers",
chamfers::discover(ctx, &Default::default()),
),
bosses: kept(&mut defining, "bosses", bosses::discover(ctx)),
angled_steps: kept(&mut defining, "angled_steps", angled_steps::discover(ctx)),
flats: kept(&mut defining, "flats", flats::discover(ctx)),
paired_ramp_steps: kept(
&mut defining,
"paired_ramp_steps",
paired_ramp_steps::discover(ctx),
),
oriented_chamfers: kept(
&mut defining,
"oriented_chamfers",
oriented_chamfers::discover(ctx, &Default::default()),
),
circular_face_patterns: kept(
&mut defining,
"circular_face_patterns",
circular_face_patterns::discover(ctx),
),
oblique_through_steps: kept(
&mut defining,
"oblique_through_steps",
oblique_through_steps::discover(ctx),
),
circular_blind_steps: kept(
&mut defining,
"circular_blind_steps",
circular_blind_steps::discover(ctx),
),
hole_patterns: Vec::new(),
holes,
gusset_rib_patterns: Vec::new(),
gusset_ribs,
countersinks,
thin_wall_bodies,
interior_voids: kept(&mut defining, "interior_voids", void_analysis.accepted),
interior_void_refusals: void_analysis.refusals,
through_steps: kept(&mut defining, "through_steps", through_steps::discover(ctx)),
turned_steps: kept(
&mut defining,
"turned_steps",
turned_steps::sorted_occurrences(turned_steps::discover(ctx)),
),
grooves: kept(&mut defining, "grooves", grooves::discover(ctx)),
annular_grooves: {
let found = annular_grooves::discover(ctx);
if found.is_empty() {
Vec::new()
} else {
kept(&mut defining, "annular_grooves", found)
}
},
plates: kept_shared(&mut defining, "plates", plate_occurrences),
round_bottom_blind_slots: kept(
&mut defining,
"round_bottom_blind_slots",
round_bottom_slots::discover(ctx),
),
semicircular_blind_slots: {
let found = semicircular_blind_slots::discover(ctx);
if found.is_empty() {
Vec::new()
} else {
kept(&mut defining, "semicircular_blind_slots", found)
}
},
rectangular_blind_slots: kept(
&mut defining,
"rectangular_blind_slots",
rectangular_blind_slots::discover(ctx),
),
double_d_bores: kept(
&mut defining,
"double_d_bores",
profiled_bores::discover(ctx),
),
edge_open_circular_pockets: kept(
&mut defining,
"edge_open_circular_pockets",
skip_unproved(part, edge_open_circular::discover(ctx)),
),
edge_open_prismatic_recesses: kept(
&mut defining,
"edge_open_prismatic_recesses",
skip_unproved(part, edge_open_prismatic::discover(ctx)),
),
blends: kept_shared(&mut defining, "blends", blends::discover(ctx)),
sheet_metal_bodies: kept_shared(
&mut defining,
"sheet_metal_bodies",
sheet_metal::discover(ctx),
),
slot_patterns: Vec::new(),
slots,
pocket_patterns: Vec::new(),
pockets,
v_channels: {
let found = v_channels::discover(ctx, &passages);
if found.is_empty() {
Vec::new()
} else {
kept(&mut defining, "v_channels", found)
}
},
channels: kept(&mut defining, "channels", channel_occurrences),
rectangular_through_notches: if notches.is_empty() {
Vec::new()
} else {
kept(&mut defining, "rectangular_through_notches", notches)
},
repeating_radial_profiles: kept(
&mut defining,
"repeating_radial_profiles",
repeating_profiles::discover(ctx),
),
freeform_surfaces,
modelled_threads,
modelled_thread_refusals: thread_analysis.refusals.clone(),
polygonal_bosses: kept(&mut defining, "polygonal_bosses", boss_analysis.accepted),
polygonal_stock: kept_shared(
&mut defining,
"polygonal_stock",
polygonal_bosses::discover_stock(ctx, &Default::default()),
),
section_passages: kept(&mut defining, "section_passages", passages),
prismatic_pockets: kept(
&mut defining,
"prismatic_pockets",
skip_unproved(part, prismatic_analysis.accepted),
),
oriented_slot_patterns: Vec::new(),
oriented_slots,
pads: kept(&mut defining, "pads", pad_analysis.accepted),
step_levels,
risers,
section_recesses: Vec::new(),
section_recess_refusals: Vec::new(),
section_recess_patterns: Vec::new(),
section_recess_refusal: None,
fillets: kept_shared(
&mut defining,
"fillets",
skip_unproved(part, fillets::discover(ctx, &Default::default())),
),
defining: defining.defining,
evidence_status: defining.evidence_status,
};
let mut evidence = evidence;
evidence.risers = physical.defining["risers"].clone();
let mut dispositions = reconcile::reconcile(&physical, &evidence)?;
let rejected: BTreeSet<_> = dispositions
.iter()
.filter(|d| d.outcome == reconcile::Outcome::Rejected)
.map(|d| {
(
d.candidate.family.field().unwrap_or("risers"),
d.candidate.index,
)
})
.collect();
let claimed: BTreeSet<_> = defining
.claimed
.iter()
.flat_map(|(family, records)| {
records
.iter()
.enumerate()
.filter(|(i, _)| !rejected.contains(&(*family, *i)))
.flat_map(|(_, faces)| faces.iter().copied())
})
.collect();
let gone: BTreeSet<_> = physical.defining["fillets"]
.iter()
.enumerate()
.filter(|(i, faces)| {
!rejected.contains(&("fillets", *i)) && faces.iter().any(|f| claimed.contains(f))
})
.map(|(i, _)| i)
.collect();
if !gone.is_empty() {
drop_rejected(&mut physical.fillets, &gone);
drop_rejected(physical.defining.get_mut("fillets").unwrap(), &gone);
drop_rejected(physical.evidence_status.get_mut("fillets").unwrap(), &gone);
drop_rejected(defining.constituent.get_mut("fillets").unwrap(), &gone);
dispositions = reconcile::reconcile(&physical, &evidence)?;
}
Ok(Some(Inventory {
physical,
evidence,
dispositions,
constituent: defining.constituent,
}))
}
struct Kept<'p> {
part: &'p Part,
claimed: Defining,
defining: Defining,
constituent: Defining,
evidence_status: BTreeMap<&'static str, Vec<evidence::EvidenceStatus>>,
}
fn kept<R>(kept: &mut Kept<'_>, family: &'static str, found: Vec<Occurrence<R>>) -> Vec<R> {
kept.claimed
.insert(family, found.iter().map(|o| o.defining.clone()).collect());
kept_shared(kept, family, found)
}
fn kept_shared<R>(kept: &mut Kept<'_>, family: &'static str, found: Vec<Occurrence<R>>) -> Vec<R> {
kept.evidence_status.insert(
family,
found
.iter()
.map(|o| evidence::strict_status(kept.part, &o.defining, &o.context))
.collect(),
);
kept.defining
.insert(family, found.iter().map(|o| o.defining.clone()).collect());
kept.constituent.insert(
family,
found
.iter()
.map(|o| {
let faces: BTreeSet<usize> = o.defining.iter().chain(&o.context).copied().collect();
faces.into_iter().collect()
})
.collect(),
);
records(found)
}
internal_entry! {
pub fn records<R>(found: Vec<Occurrence<R>>) -> Vec<R> {
found.into_iter().map(|o| o.record).collect()
}
}