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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Issue #3913: a COMMITTED, deterministic sweep harness for the `union_many`
//! N-ary residual left after the #3912 weld. #3913's own numbers (294 on
//! `main`, 88 after the weld) came from an uncommitted local script — every
//! prior figure in this defect family (#3874's 2090->0 / 2388->0 pairwise
//! sweeps, its prose-only "105 of 147" three-box counts, and #3913's own
//! 294/88) was produced the same throwaway way, so nothing here is
//! reproducible or regression-testable from an earlier PR. This file exists
//! to fix that: every number this file's tests print comes from THIS
//! committed code, run by `cargo test`, forever.
//!
//! ## Shape: reproducing #3913's "441 configurations"
//!
//! #3913 measured a "7x7 corner grid x 3 dz values x 3 operand orderings"
//! sweep over `union_many`. This harness reproduces that shape exactly:
//!
//! - **7x7 corner grid**: `three_boxes_at(bx, by, dz)` below extends
//! `mesh_bridge_tests::issue_3353_nary_near_coplanar::three_boxes` (the
//! pinned #3353 N-ary fixture: A axis-aligned at the origin, B rotated +30
//! degrees about Z overlapping A's +X+Y corner, C rotated -20 degrees
//! overlapping A's -X+Y corner) by letting B and C's corner offset `(bx,
//! by)` vary instead of sitting fixed at `(0.4, 0.4)`. `CORNER_OFFSETS`
//! below is 7 values spanning a shallow-to-deep overlap range, swept on
//! both axes: 7x7 = 49 corner positions.
//! - **3 dz values**: `DZ_VALUES` samples the exactly-flush case (`dz = 0`,
//! `three_boxes`'s own control) plus one `SNAP_GRID` step in EACH
//! direction (`+SG`, `-SG`) — `three_boxes`'s doc names the one-step-off
//! regime as the one that tears, and sampling both signs (rather than only
//! `+SG`, which is all the pinned fixture checks) lets the sweep below
//! answer #3913's "does a `dz` sign correlate with tearing" question
//! directly, instead of only being able to speculate about the untested
//! sign.
//! - **6 operand orderings**: `three_boxes_at` returns `[a, b, c]` in a fixed
//! spatial arrangement; `ORDERINGS` permutes which mesh `union_many` sees
//! first/second/third. The pinned #3353 fixture checks all 6 permutations
//! and so does this sweep: `[A,B,C]` (identity), `[A,C,B]`, `[B,A,C]`,
//! `[B,C,A]`, `[C,A,B]`, and `[C,B,A]` (full reversal). The full set
//! answers whether the #3912 weld's observed `BCA => 0` is genuinely special
//! or an artefact of sampling only 3 of 6.
//! (`promote_operands_mutually` walks operands in index order per
//! #3912's PR description, so which mesh is index 0 is a plausible axis of
//! asymmetry, not an arbitrary choice).
//!
//! 7 x 7 x 3 x 6 = 882.
//!
//! ## Determinism
//!
//! Every configuration is a pure function of its `(bx, by, dz, ordering)`
//! grid indices - no RNG anywhere in this file (unlike
//! `issue_3353_unrecovered_crosstab.rs`'s splitmix64 sweeps). `union_many`
//! and `consolidate_coplanar` are themselves pure functions of their input
//! triangles computed in exact/rational arithmetic (see the kernel's own
//! determinism documentation), so the same 441 configurations produce the
//! same per-configuration tear verdict on every run, on every platform - the
//! same guarantee `mesh_determinism.json` pins for the mesh pipeline at
//! large. No wall-clock, thread count, or memory layout enters the
//! computation.
//!
//! ## CI wiring
//!
//! `union_many_nary_sweep_regression_gate` (below) is NOT `#[ignore]`d: it
//! runs on every `cargo test -p ifc-lite-geometry` / `cargo test --workspace`
//! (measured locally at well under a second for all 441 configurations - see
//! that test's doc comment for the actual timing). A harness nothing runs is
//! exactly the "gate nobody turns" failure `scripts/check-test-wiring.mjs`
//! exists to catch; being fast enough to run by default avoids needing that
//! opt-in at all.
//!
//! ## Verification (this harness actually detects tearing)
//!
//! `open_edges` below is the same "weld by position, count directed edge
//! uses per undirected edge, flag anything other than exactly (1, 1)"
//! convention `issue_3353_nary_near_coplanar::open_edges` and
//! `issue_3353_unrecovered_crosstab.rs::open_edges` already use, so it is not
//! a new, unverified detector - see `csg_property_test.rs`'s
//! `watertight_checker_rejects_non_manifold_and_open_meshes` for the standing
//! proof that this exact check-shape (implemented independently there)
//! rejects both a duplicated-shell false-negative and a plain open mesh.
//! `sweep_self_check_open_edges_detects_known_bad_meshes` below re-proves the
//! same two cases against THIS file's copy directly, since each
//! `issue_3353_*`/`issue_3913_*` file keeps its own copy rather than sharing
//! one (see `issue_3353_unrecovered_crosstab.rs`'s module doc for why no
//! shared sweep-generator module exists in this repo).
//!
//! Refs #3913, #3353, #3912, #3874
use crateClippingProcessor;
use crateunion_many;
use crateMesh;
use ;
use HashMap;
/// `SNAP_GRID`, spelled out so `DZ_VALUES` is visibly scaled to the grid -
/// same constant `issue_3353_nary_near_coplanar` names `SG`.
const SG: f64 = 1.0 / 65536.0;
/// Outward-wound axis-aligned box, optionally rigidly rotated about `about`.
/// Verbatim copy of `issue_3353_nary_near_coplanar::boxed` (itself matching
/// `issue_3353_unrecovered_crosstab.rs`'s copy) - each `issue_3353_*`/
/// `issue_3913_*` file keeps its own per that file's documented convention,
/// rather than a shared module nothing else in the repo provides.
/// Unmatched directed edges after welding by position at 0.1 mm - identical
/// convention to `issue_3353_nary_near_coplanar::open_edges`. `Err` covers
/// both "union produced nothing" and "a triangle degenerated to a repeated
/// welded vertex", both of which are tears (an empty or degenerate union of
/// three closed, disjoint-from-empty boxes is never correct), so callers
/// treat `Err` the same as `Ok(n > 0)`.
/// Self-check on `open_edges` itself, mirroring
/// `csg_property_test.rs::watertight_checker_rejects_non_manifold_and_open_meshes`:
/// a closed box is clean, a duplicated shell (signed edge counts cancel, but
/// every edge has 4 total directed uses) is rejected, and an open mesh (one
/// triangle removed) is rejected. Proves this file's copy of the detector
/// actually detects both failure shapes, not merely "runs without panicking"
/// - the verification bar #3913 asks for.
/// A axis-aligned at the origin; B rotated +30 degrees about Z overlapping
/// its corner at offset `(bx, by)`; C rotated -20 degrees overlapping the
/// mirrored corner at `(-bx, by)`. Both rotated boxes sit `dz` above A.
/// Extends `issue_3353_nary_near_coplanar::three_boxes` (which fixes
/// `bx = by = 0.4`) by letting the corner offset vary — see the module doc
/// for why.
/// 7 corner-grid steps, shallow to deep overlap (a=1x1x1 boxes, so an offset
/// approaching 1.0 leaves almost no overlap and an offset near 0 is a very
/// deep overlap). Matches #3913's "7x7 corner grid".
const CORNER_OFFSETS: = ;
/// 3 `dz` values: exactly flush (the `three_boxes` control) and one snap
/// step in EACH direction. See the module doc for why both signs are swept.
const DZ_VALUES: = ;
const DZ_LABELS: = ;
/// All 6 permutations of the three operands `union_many` can see, in
/// standard permutation order. See the module doc.
const ORDERINGS: = ;
const ORDERING_LABELS: = ;
/// One sweep configuration's verdict.
/// Runs the full 882-configuration sweep and returns every verdict, in
/// deterministic enumeration order (bx outer, by, dz, ordering inner).
/// Shared by the CI gate test and can be driven standalone (e.g. from a
/// `#[test] #[ignore]` or a future `examples/` binary) to print just the
/// torn subset.
/// The shipped #3912 N-ary weld measured 136 / 882 torn configurations.
/// #3925 preserves that union path; the unshipped raw-first experiment improved
/// this synthetic sweep but regressed real large-model cuts and was discarded.
/// #3917 then found and fixed the mechanism behind all 136: `union_many`'s
/// `arrange` now retries the other 5 orderings of a 3-operand union (and only
/// a 3-operand union — this sweep's exact shape) when the caller's own order
/// comes back open, keeping the caller's order unchanged whenever it already
/// closes. That takes the measured count to 0 / 882 across every one of the 6
/// orderings; see `nary_union.rs` for the mechanism and why it does not
/// regress the 746 configurations that were already closed.
const KNOWN_TORN_CEILING: usize = 0;
/// The primary #3913 deliverable: a committed, deterministic, CI-run sweep
/// over the exact 882-configuration shape (7x7 corner grid x 3 dz x 6
/// orderings) #3913 measured with an uncommitted script (extended from 3 to
/// all 6 permutations to answer whether the #3912 weld's `BCA => 0` is
/// genuinely special or an artefact). Reports how many of the 882
/// configurations tear, breaks the torn set down by `dz` sign and by
/// operand ordering (#3913's suggested characterisation axes), and asserts
/// the count has not REGRESSED past `KNOWN_TORN_CEILING` - #3917's fix took
/// this to 0, so any future regression here is exactly that, a regression,
/// not a re-discovery of a known residual.
///
/// Not `#[ignore]`d: measured locally at 882 `union_many` + consolidate
/// calls over 3 twelve-triangle boxes each, taking ~2.6 seconds total wall
/// time (`cargo test -p ifc-lite-geometry --lib
/// kernel::issue_3913_sweep_tests -- --nocapture`), so it runs on every
/// `cargo test -p ifc-lite-geometry` / `cargo test --workspace` like any
/// other fast unit test - no opt-in needed.