Skip to main content

brep_offset/offset/offset_shell/
refusals.rs

1//! The offset shell's own refusals, minted as TYPED `KernelRefusal`s at their
2//! origin with stable slugs (census item 4, 2026-09-27), and the predicates
3//! `features/offset_shell.rs` dispatches on — the class and slug, never the
4//! text:
5//!
6//! | feature branch | predicate | class |
7//! |---|---|---|
8//! | every face selected: warn and no-op | `is_offset_shell_no_retained_face` | `InvalidInput { what: "offset_shell_no_retained_face" }` |
9//! | an open curved rim: the reorder advice | `is_offset_shell_open_curved_rim` | `NonIntegralGenus` (typed at `finalize_assembled_solid`, carried through every cause put in front of it) or `UnsupportedGeometry { what: "offset_shell_unwelded_curved_rim" }` |
10//!
11//! plus the outward guard's `Internal { what: "offset_shell_empty_shell" }`,
12//! the sharp-side lane's `UnsupportedGeometry { what:
13//! "offset_shell_sharp_side_continuation" }` and the certainty step's
14//! `UnsupportedGeometry { what: "offset_shell_regularity_uncertain" }` and
15//! `{ what: "offset_shell_fold_between_samples" }`, the selection's
16//! `UnsupportedGeometry { what: "offset_shell_tangent_offsets" }` (two offsets
17//! touch tangentially: the cavity pinches to a line) and the assembly's
18//! `UnsupportedGeometry { what: "offset_shell_sealed_hollow" }` (a cavity skin
19//! with no path to the opening, refused when the assembly fails), which no
20//! feature branch matches — the last two so a refusal naming its cause never
21//! takes the reorder advice.
22
23use crate::{KernelRefusal, KernelStage};
24
25pub(super) const NO_RETAINED_FACE: &str = "offset_shell_no_retained_face";
26/// Two offsets touch tangentially, so the cavity would pinch to a line
27/// (`BREP_OFFSET_TANGENT_TOUCH`).
28pub(super) const TANGENT_OFFSETS: &str = "offset_shell_tangent_offsets";
29/// A cavity skin is sealed off from the opening and the assembly failed
30/// (`BREP_OFFSET_SEALED_HOLLOW`).
31pub(super) const SEALED_HOLLOW: &str = "offset_shell_sealed_hollow";
32pub(super) const UNWELDED_CURVED_RIM: &str = "offset_shell_unwelded_curved_rim";
33pub(super) const EMPTY_SHELL: &str = "offset_shell_empty_shell";
34/// The sharp-side lane could not continue a curved carrier past its sharp
35/// outward side (`sharp_side_continued_source`): a named deferral.
36pub(super) const SHARP_SIDE_CONTINUATION: &str = "offset_shell_sharp_side_continuation";
37/// The regularity scan found nothing collapsed on a support but could not
38/// certify it regular either (`offset/regularity.rs`, the certainty step): a
39/// named deferral, so the support is neither built whole nor carved.
40pub(super) const REGULARITY_UNCERTAIN: &str = "offset_shell_regularity_uncertain";
41
42/// The certainty step's refinement found a collapsed sample the scan's census
43/// and carve had not seen: the support folds between the samples.
44pub(super) const FOLD_BETWEEN_SAMPLES: &str = "offset_shell_fold_between_samples";
45
46pub(super) fn fold_between_samples(
47    face_id: u64,
48    distance: f64,
49    sample: crate::offset_regularity::FoldSample,
50) -> KernelRefusal {
51    KernelRefusal::unsupported(
52        KernelStage::Classify,
53        FOLD_BETWEEN_SAMPLES,
54        format!(
55            "offset_shell: the offset of source face {face_id} by {distance:.6} folds between the \
56             regularity scan's samples — the certainty step read 1 − δ·κ = {:.3e} at (u={:.6}, \
57             v={:.6}), curvature radius {:.6} against the offset {:.6}, where the census and the \
58             carve had found nothing to divide. The support is refused rather than built whole",
59            sample.factor,
60            sample.u,
61            sample.v,
62            sample.radius(),
63            sample.displacement.abs()
64        ),
65    )
66}
67
68/// A support the scan could not certify: nothing collapsed, and either cells
69/// were still risky at the scan's finest spacing or the dip descent ran out of
70/// budget. Building it whole would ship a carrier that may fold between the
71/// samples and validate.
72pub(super) fn regularity_uncertain(
73    face_id: u64,
74    distance: f64,
75    unresolved: usize,
76    budget_exhausted: bool,
77    least: Option<crate::offset_regularity::FoldSample>,
78) -> KernelRefusal {
79    let because = match (unresolved, budget_exhausted) {
80        (0, _) => "the refinement budget ran out with prominent dips of the fold factor still \
81                   unexplored"
82            .to_string(),
83        (cells, false) => format!(
84            "{cells} cell(s) of the scan were still risky at its finest spacing — the fold \
85             factor sits within a hair of the level over an area no sampling can decide"
86        ),
87        (cells, true) => format!(
88            "{cells} cell(s) of the scan were still risky at its finest spacing and the \
89             refinement budget ran out"
90        ),
91    };
92    let least = least
93        .map(|least| {
94            format!(
95                "; the least 1 − δ·κ seen is {:.3e} at (u={:.6}, v={:.6}), curvature radius {:.6} \
96                 against the offset {:.6}",
97                least.factor,
98                least.u,
99                least.v,
100                least.radius(),
101                least.displacement.abs()
102            )
103        })
104        .unwrap_or_default();
105    KernelRefusal::unsupported(
106        KernelStage::Classify,
107        REGULARITY_UNCERTAIN,
108        format!(
109            "offset_shell: the offset of source face {face_id} by {distance:.6} cannot be \
110             certified regular over the face's trim — nothing collapsed at any sample, but \
111             {because}{least}. The support is refused rather than built whole, because a \
112             carrier folded between the samples welds into a shell that validates and bounds \
113             the wrong solid"
114        ),
115    )
116}
117
118/// Every face was selected as an opening, so no support is left to offset.
119pub fn no_retained_face() -> KernelRefusal {
120    KernelRefusal::input(
121        KernelStage::Collect,
122        NO_RETAINED_FACE,
123        "offset_shell: removing every face cannot produce a shell",
124    )
125}
126
127/// A one-use closed rim the welds could not close on a curved-solid opening.
128pub fn unwelded_curved_rim(edge_id: u64, anchor: crate::Vec3) -> KernelRefusal {
129    KernelRefusal::unsupported(
130        KernelStage::Sew,
131        UNWELDED_CURVED_RIM,
132        format!(
133            "offset_shell: unwelded rim leaves a non-watertight shell \
134             (one-use closed edge {} near ({:.3},{:.3},{:.3})); this \
135             curved-solid opening is not yet supported",
136            edge_id, anchor.x, anchor.y, anchor.z
137        ),
138    )
139}
140
141/// An outward result with shells that enclose no volume
142/// (`outward_shell_is_connected`).
143pub fn empty_shell(shells: usize, empty: usize, floor: f64) -> KernelRefusal {
144    // Internal, not `InvalidResultTopology`: that class is backed as an
145    // arrangement degeneracy and so is perturbation-eligible (the boolean's
146    // retry contract), which a builder's own verdict must not inherit, the
147    // same ruling the loft's "failed validation" sites took.
148    KernelRefusal::internal(
149        KernelStage::Validate,
150        EMPTY_SHELL,
151        format!(
152            "offset_shell: the outward shell assembled {shells} shells, {empty} of which enclose no volume \
153             (under {floor:.1e}); those are fragments of an assembly that cannot be built as it stands"
154        ),
155    )
156}
157
158/// Whether `refusal` is the shell's "every face was selected" refusal: the
159/// class and slug, never the text.
160pub fn is_offset_shell_no_retained_face(refusal: &KernelRefusal) -> bool {
161    matches!(&refusal.class, crate::RefusalClass::InvalidInput { what } if what == NO_RETAINED_FACE)
162}
163
164/// Whether `refusal` is an open curved rim the shell could not close: the
165/// assembly's `NonIntegralGenus` (typed at `finalize_assembled_solid`, carried
166/// through every cause put in front of it) or the unwelded curved rim. The
167/// class, never the text; a genus sentence quoted under another class is not
168/// this refusal.
169pub fn is_offset_shell_open_curved_rim(refusal: &KernelRefusal) -> bool {
170    match &refusal.class {
171        crate::RefusalClass::NonIntegralGenus { .. } => true,
172        crate::RefusalClass::UnsupportedGeometry { what } => what == UNWELDED_CURVED_RIM,
173        _ => false,
174    }
175}