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";
32/// A shadowed re-run would omit nothing new: a carrier riding an already
33/// omitted support read shadowed again.
34pub(super) const SHADOW_RETRY_STALLED: &str = "offset_shell_shadow_retry_stalled";
35/// The nested passes passed `MAXIMUM_PASS_DEPTH` without settling.
36pub(super) const PASS_BUDGET: &str = "offset_shell_pass_budget";
37pub(super) const UNWELDED_CURVED_RIM: &str = "offset_shell_unwelded_curved_rim";
38pub(super) const EMPTY_SHELL: &str = "offset_shell_empty_shell";
39/// The sharp-side lane could not continue a curved carrier past its sharp
40/// outward side (`sharp_side_continued_source`): a named deferral.
41pub(super) const SHARP_SIDE_CONTINUATION: &str = "offset_shell_sharp_side_continuation";
42/// The regularity scan found nothing collapsed on a support but could not
43/// certify it regular either (`offset/regularity.rs`, the certainty step): a
44/// named deferral, so the support is neither built whole nor carved.
45pub(super) const REGULARITY_UNCERTAIN: &str = "offset_shell_regularity_uncertain";
46
47/// The certainty step's refinement found a collapsed sample the scan's census
48/// and carve had not seen: the support folds between the samples.
49pub(super) const FOLD_BETWEEN_SAMPLES: &str = "offset_shell_fold_between_samples";
50
51pub(super) fn fold_between_samples(
52    face_id: u64,
53    distance: f64,
54    sample: crate::offset_regularity::FoldSample,
55) -> KernelRefusal {
56    KernelRefusal::unsupported(
57        KernelStage::Classify,
58        FOLD_BETWEEN_SAMPLES,
59        format!(
60            "offset_shell: the offset of source face {face_id} by {distance:.6} folds between the \
61             regularity scan's samples — the certainty step read 1 − δ·κ = {:.3e} at (u={:.6}, \
62             v={:.6}), curvature radius {:.6} against the offset {:.6}, where the census and the \
63             carve had found nothing to divide. The support is refused rather than built whole",
64            sample.factor,
65            sample.u,
66            sample.v,
67            sample.radius(),
68            sample.displacement.abs()
69        ),
70    )
71}
72
73/// A support the scan could not certify: nothing collapsed, and either cells
74/// were still risky at the scan's finest spacing or the dip descent ran out of
75/// budget. Building it whole would ship a carrier that may fold between the
76/// samples and validate.
77pub(super) fn regularity_uncertain(
78    face_id: u64,
79    distance: f64,
80    unresolved: usize,
81    budget_exhausted: bool,
82    least: Option<crate::offset_regularity::FoldSample>,
83) -> KernelRefusal {
84    let because = match (unresolved, budget_exhausted) {
85        (0, _) => "the refinement budget ran out with prominent dips of the fold factor still \
86                   unexplored"
87            .to_string(),
88        (cells, false) => format!(
89            "{cells} cell(s) of the scan were still risky at its finest spacing — the fold \
90             factor sits within a hair of the level over an area no sampling can decide"
91        ),
92        (cells, true) => format!(
93            "{cells} cell(s) of the scan were still risky at its finest spacing and the \
94             refinement budget ran out"
95        ),
96    };
97    let least = least
98        .map(|least| {
99            format!(
100                "; the least 1 − δ·κ seen is {:.3e} at (u={:.6}, v={:.6}), curvature radius {:.6} \
101                 against the offset {:.6}",
102                least.factor,
103                least.u,
104                least.v,
105                least.radius(),
106                least.displacement.abs()
107            )
108        })
109        .unwrap_or_default();
110    KernelRefusal::unsupported(
111        KernelStage::Classify,
112        REGULARITY_UNCERTAIN,
113        format!(
114            "offset_shell: the offset of source face {face_id} by {distance:.6} cannot be \
115             certified regular over the face's trim — nothing collapsed at any sample, but \
116             {because}{least}. The support is refused rather than built whole, because a \
117             carrier folded between the samples welds into a shell that validates and bounds \
118             the wrong solid"
119        ),
120    )
121}
122
123/// Every face was selected as an opening, so no support is left to offset.
124pub fn no_retained_face() -> KernelRefusal {
125    KernelRefusal::input(
126        KernelStage::Collect,
127        NO_RETAINED_FACE,
128        "offset_shell: removing every face cannot produce a shell",
129    )
130}
131
132/// A one-use closed rim the welds could not close on a curved-solid opening.
133pub fn unwelded_curved_rim(edge_id: u64, anchor: crate::Vec3) -> KernelRefusal {
134    KernelRefusal::unsupported(
135        KernelStage::Sew,
136        UNWELDED_CURVED_RIM,
137        format!(
138            "offset_shell: unwelded rim leaves a non-watertight shell \
139             (one-use closed edge {} near ({:.3},{:.3},{:.3})); this \
140             curved-solid opening is not yet supported",
141            edge_id, anchor.x, anchor.y, anchor.z
142        ),
143    )
144}
145
146/// An outward result with shells that enclose no volume
147/// (`outward_shell_is_connected`).
148pub fn empty_shell(shells: usize, empty: usize, floor: f64) -> KernelRefusal {
149    // Internal, not `InvalidResultTopology`: that class is backed as an
150    // arrangement degeneracy and so is perturbation-eligible (the boolean's
151    // retry contract), which a builder's own verdict must not inherit, the
152    // same ruling the loft's "failed validation" sites took.
153    KernelRefusal::internal(
154        KernelStage::Validate,
155        EMPTY_SHELL,
156        format!(
157            "offset_shell: the outward shell assembled {shells} shells, {empty} of which enclose no volume \
158             (under {floor:.1e}); those are fragments of an assembly that cannot be built as it stands"
159        ),
160    )
161}
162
163/// Whether `refusal` is the shell's "every face was selected" refusal: the
164/// class and slug, never the text.
165pub fn is_offset_shell_no_retained_face(refusal: &KernelRefusal) -> bool {
166    matches!(&refusal.class, crate::RefusalClass::InvalidInput { what } if what == NO_RETAINED_FACE)
167}
168
169/// Whether `refusal` is an open curved rim the shell could not close: the
170/// assembly's `NonIntegralGenus` (typed at `finalize_assembled_solid`, carried
171/// through every cause put in front of it) or the unwelded curved rim. The
172/// class, never the text; a genus sentence quoted under another class is not
173/// this refusal.
174pub fn is_offset_shell_open_curved_rim(refusal: &KernelRefusal) -> bool {
175    match &refusal.class {
176        crate::RefusalClass::NonIntegralGenus { .. } => true,
177        crate::RefusalClass::UnsupportedGeometry { what } => what == UNWELDED_CURVED_RIM,
178        _ => false,
179    }
180}
181
182/// A whole-body band carve (`BREP_OFFSET_WHOLE_BODY_FOLD_BAND`) whose fold
183/// boundary's image is not buried under the source's own offset: the kept
184/// pieces' offsets would end on a cusp edge of the erosion boundary.
185pub(super) fn fold_band_uncovered(face_id: u64, distance: f64, pieces: usize) -> KernelRefusal {
186    KernelRefusal::unsupported(
187        KernelStage::Refine,
188        "offset_shell_fold_band",
189        format!(
190            "offset_shell: the offset of source face {face_id} by {distance:.6} folds in a BAND across its \
191             trim, dividing it into {pieces} regular piece(s), and a fold boundary's image is not nearer than \
192             the distance to the source: the pieces' offsets would end on a cusp of the body's boundary \
193             instead of crossing before it, and nothing here re-solves that cusp"
194        ),
195    )
196}