brep_kernel/csg/imprint.rs
1use crate::classification::{parameter_point_in_face, PolygonClass};
2use crate::curve::KNOT_IDENTITY_TOL;
3use crate::spatial::{Aabb, Bvh};
4use crate::tolerance::{
5 assembler_weld, merge_scale, solid_scale, COINCIDENCE_DISTANCE_FLOOR, WELD_FLOOR,
6};
7use crate::topology::{BrepSolid, EdgeRecord, FaceRecord};
8use crate::{
9 build_pcurve_on_surface, classify_surface_pair_cached,
10 fit_polyline, fit_polyline_of_degree, PolylineFit,
11 intersect_curves, intersect_surfaces, intersect_surfaces_supplemental, project_point_to_curve,
12 project_point_to_surface, project_point_to_surface_seeded, KnotVector, NurbsCurve, NurbsSurface,
13 SurfaceClassifyData,
14 SurfaceIntersectionOptions, SurfacePairClassification, SurfacePairRelation, Vec2, Vec3, Vec4,
15};
16use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
17use serde::{Deserialize, Serialize};
18use std::time::Duration;
19use web_time::Instant;
20
21// The profile line buffer, `profile_line!` and `profile_enabled` live in
22// `crate::profile` (consolidation I8); these paths stay for their callers.
23pub(crate) use crate::profile::{profile_emit, profile_enabled, ProfileSink};
24
25/// Per-step wall-clock accumulators for `build_imprints`, printed to stderr
26/// when `BREP_PROFILE` is set. Native-only in practice (no env vars in wasm).
27#[derive(Default)]
28struct ImprintProfile {
29 enabled: bool,
30 pairs: u64,
31 marched_pairs: u64,
32 whole_reading_reuses: u64,
33 classify: Duration,
34 cosurface: Duration,
35 lies_on: Duration,
36 planar_iso: Duration,
37 analytic: Duration,
38 seeds: Duration,
39 march: Duration,
40 clip_and_fit: Duration,
41 process_curve: Duration,
42 /// `clip_and_fit` split: the swapped-order rescue marches, the trim clip,
43 /// the shared-boundary test, the polyline fit, and `process_curve`.
44 rescue_march: Duration,
45 clip: Duration,
46 shared_boundary: Duration,
47 fit: Duration,
48 process: Duration,
49 hermite_runs: u64,
50 fit_runs: u64,
51 hermite: Duration,
52 /// Appended at the end.
53 pairs_fits: u64,
54 exact_lane_fits: u64,
55 /// Slice 1: planar-iso sections whose exact pcurves were handed to the
56 /// builder, and those declined (a lifted chart, or no pcurve built).
57 exact_iso_sections: u64,
58 exact_iso_declined: u64,
59}
60
61impl ImprintProfile {
62 fn new() -> Self {
63 Self {
64 enabled: profile_enabled(),
65 ..Self::default()
66 }
67 }
68
69 fn lap(&self, started: &mut Option<Instant>) -> Duration {
70 crate::profile::lap(self.enabled, started)
71 }
72
73 fn report(&self) {
74 if !self.enabled {
75 return;
76 }
77 profile_line!("imprint.whole_reading_reuses count={}", self.whole_reading_reuses);
78 let ms = |d: Duration| d.as_secs_f64() * 1_000.0;
79 profile_line!(
80 "imprint.profile pairs={} marched={} classify={:.2} cosurface={:.2} lies_on={:.2} planar_iso={:.2} analytic={:.2} seeds={:.2} march={:.2} clip_fit={:.2} process_curve={:.2}",
81 self.pairs,
82 self.marched_pairs,
83 ms(self.classify),
84 ms(self.cosurface),
85 ms(self.lies_on),
86 ms(self.planar_iso),
87 ms(self.analytic),
88 ms(self.seeds),
89 ms(self.march),
90 ms(self.clip_and_fit),
91 ms(self.process_curve),
92 );
93 profile_line!(
94 "imprint.clip_fit rescue_march={:.2} clip={:.2} shared_boundary={:.2} fit={:.2} process={:.2} hermite={:.2} hermite_runs={} fit_runs={}",
95 ms(self.rescue_march),
96 ms(self.clip),
97 ms(self.shared_boundary),
98 ms(self.fit),
99 ms(self.process),
100 ms(self.hermite),
101 self.hermite_runs,
102 self.fit_runs,
103 );
104 profile_line!(
105 "imprint.fits pairs={} exact_lanes={} exact_iso_sections={} exact_iso_declined={}",
106 self.pairs_fits,
107 self.exact_lane_fits,
108 self.exact_iso_sections,
109 self.exact_iso_declined,
110 );
111 driver::fit_split_report();
112 }
113}
114
115/// Lane P3b row 0 (2026-10-26): where `process_curve`'s crossing loop, the
116/// lies-on span search and the boundary-reuse pass spend their time, read only
117/// under `BREP_PROFILE` and printed once per `build_imprints` as
118/// `imprint.split`. Thread-local because the builder and the support
119/// functions have no profile handle; `take` drains it for the report.
120#[derive(Default, Clone, Copy)]
121pub(crate) struct ImprintSplit {
122 pub pierce: Duration,
123 pub pierce_edges: u64,
124 pub overlap: Duration,
125 pub overlap_edges: u64,
126 pub crossing: Duration,
127 pub crossing_edges: u64,
128 pub recover: Duration,
129 pub recover_pierces: u64,
130 pub lies_whole: Duration,
131 pub lies_whole_calls: u64,
132 pub lies_whole_hits: u64,
133 pub lies_span: Duration,
134 pub lies_span_calls: u64,
135 pub reuse_edges: u64,
136}
137thread_local! {
138 static IMPRINT_SPLIT: std::cell::Cell<ImprintSplit> = const { std::cell::Cell::new(ImprintSplit {
139 pierce: Duration::ZERO, pierce_edges: 0, overlap: Duration::ZERO, overlap_edges: 0,
140 crossing: Duration::ZERO, crossing_edges: 0, recover: Duration::ZERO, recover_pierces: 0,
141 lies_whole: Duration::ZERO, lies_whole_calls: 0, lies_whole_hits: 0,
142 lies_span: Duration::ZERO, lies_span_calls: 0, reuse_edges: 0,
143 }) };
144}
145pub(crate) fn imprint_split_add(update: impl FnOnce(&mut ImprintSplit)) {
146 IMPRINT_SPLIT.with(|cell| { let mut split = cell.get(); update(&mut split); cell.set(split); });
147}
148pub(crate) fn imprint_split_take() -> ImprintSplit {
149 IMPRINT_SPLIT.with(|cell| cell.replace(ImprintSplit::default()))
150}
151
152/// Coarse observation of optional contact/graph calls, including early
153/// declines. It owns no geometry and does not change caller diagnostics.
154struct ImprintSubphaseClock {
155 started: Option<Instant>,
156 label: &'static str,
157}
158impl ImprintSubphaseClock {
159 fn new(label: &'static str) -> Self {
160 Self { started: profile_enabled().then(Instant::now), label }
161 }
162}
163impl Drop for ImprintSubphaseClock {
164 fn drop(&mut self) {
165 if let Some(started) = self.started {
166 profile_line!("imprint.subphase label={} ms={:.3}", self.label, started.elapsed().as_secs_f64() * 1000.0);
167 }
168 }
169}
170
171#[derive(Clone, Debug, Deserialize)]
172pub struct ImprintOptions {
173 #[serde(default = "default_tolerance")]
174 pub tolerance: f64,
175 #[serde(default = "default_maximum_fit_points")]
176 pub maximum_fit_points: usize,
177 #[serde(default)]
178 pub local_fit: bool,
179 #[serde(default)]
180 pub fit_chunk_points: Option<usize>,
181 pub maximum_ssi_step: Option<f64>,
182 /// `None`, the default, marches exactly as before. `BREP_SPAN_BUDGET`
183 /// overrides either way: `fit` is the pair's `intersection_fit` at the
184 /// operands' scale, a number is an absolute budget, `off` is none.
185 /// `BREP_SPAN_CENSUS=<file>` appends one line per clipped section with its
186 /// stations, deviation and refine route (`span-budget census:`), labelled
187 /// by `BREP_CENSUS_LABEL`.
188 #[serde(default)]
189 pub span_budget: Option<f64>,
190 /// Implies a span budget of the pair's `intersection_fit` when none is
191 /// set. Off by default; `BREP_HERMITE_SECTIONS` overrides either way (`0`
192 /// off, anything else on).
193 #[serde(default)]
194 pub hermite_sections: bool,
195 /// The TANGENT-CURVE lane: where an exact lane proves a pair's transverse
196 /// intersection empty, or the tangential-only gate would skip it, and the
197 /// pair classification reads near-tangent, look for an EXTENDED contact
198 /// (`crate::tangent_curve`), march it with one planar carrier, and record it
199 /// as a typed tangent section ([`ImprintResultRecord::tangent_sections`]).
200 /// The boolean then names the contact in any refusal it raises on the pair
201 /// instead of leaking the arrangement's own message. On by default since the
202 /// census of 2026-10-10 (every manifest leaf identical with the lane on and
203 /// off, `hlr_tests` green both ways); the section is recorded, never
204 /// imprinted, so nothing the boolean builds changes.
205 /// `BREP_TANGENT_CURVE_LANE=0` is the escape hatch. Appended at the end of
206 /// the struct (2026-10-10).
207 #[serde(default = "default_tangent_curve_lane")]
208 pub tangent_curve_lane: bool,
209 /// EXACT PCURVES FOR THE PLANAR-ISO LANE (slice 1, 2026-10-11, the
210 /// catalogue's P3 applied to the exact lane): a section the planar-iso
211 /// lane answers is an iso-curve of the ruled carrier and an affine image
212 /// on the plane, so both pcurves are written down on the curve's own
213 /// knots (`support::planar_iso_section`) instead of fitted, and the
214 /// junction pass moves their ends instead of re-marching them. Off by
215 /// default (the fitted pcurves are the shipped bytes);
216 /// `BREP_EXACT_ISO_PCURVES` overrides either way: `0`/`off`, `on`, or
217 /// `check`, which fits as before and appends one census line per pcurve
218 /// comparing the fitted and the exact one in 3-D
219 /// (`BREP_EXACT_ISO_CENSUS=<file>`, labelled by `BREP_CENSUS_LABEL`). A
220 /// face read in a lifted chart declines the exact pcurve (the iso line
221 /// is in the carrier's frame). Appended at the end of the struct.
222 #[serde(default)]
223 pub exact_iso_pcurves: bool,
224 /// MARCH STARTS: every surface/surface march the imprint runs traces
225 /// its starts in order (explicit trim-boundary pierces first, the most
226 /// transverse first, a run-through start consumed with a snapped
227 /// station) and seeds its interior candidates from the two carriers'
228 /// knot-span leaves instead of a fixed grid
229 /// ([`SurfaceIntersectionOptions::ordered_starts`],
230 /// [`SurfaceIntersectionOptions::tree_seeds`]). Off by default (the
231 /// grid-then-seeds march is the shipped one, byte for byte);
232 /// `BREP_MARCH_STARTS` overrides either way: `0`/`off`, `order` (A3's
233 /// ordering alone), `snap` (the ordering with run-through starts
234 /// consumed), `tree` (A4 alone), `order+tree`, anything else all three.
235 /// Appended at the end of the struct.
236 #[serde(default)]
237 pub march_starts: bool,
238 /// Candidates for one junction are captured within the wide residual
239 /// band; two combine only when they are connected (share a support face)
240 /// and lie within the strict radius built from their own evidence radii;
241 /// the surviving position is the lowest-dimensional candidate's, an
242 /// operand vertex over an operand edge's crossing over a section end on
243 /// two carriers. Off by default until the census in the record promotes
244 /// it; `BREP_JUNCTION_COMBINE` overrides either way (`0`/`off`, `check`
245 /// for the census that logs every junction's candidates to
246 /// `BREP_JUNCTION_CENSUS` without moving anything, anything else on).
247 /// Appended at the end of the struct (2026-10-11).
248 #[serde(default)]
249 pub two_radius_junctions: bool,
250 /// IMPRINT THE TANGENT SECTION (the pinched result): a planar-carrier
251 /// contact the tangent-curve lane traced is also IMPRINTED —
252 /// `process_curve` on the clipped run, so the contact becomes a section
253 /// piece on both carriers, the operand edges its ends lie on are split
254 /// there, and every earlier piece the ends lie on (the through-bore's cap
255 /// circles) is split at them — and its piece ids are recorded in
256 /// [`TangentSectionRecord::piece_ids`]. The boolean's assembler then
257 /// pairs the four coedges of such a piece by MATERIAL SIDE (two edge
258 /// records on one locus, each manifold) instead of by arrival, so the
259 /// grazing through-bore builds as one shell whose tangent edge is carried
260 /// twice. On by default since the census of 2026-10-11 (the battery
261 /// moving only the pins that asserted the old refusal and the recentre
262 /// pin whose unguarded far fillet now completes);
263 /// `BREP_TANGENT_CURVE_IMPRINT=0` is the escape hatch. Requires
264 /// `tangent_curve_lane`. Appended at the end of the struct (2026-10-11).
265 #[serde(default = "default_tangent_curve_imprint")]
266 pub tangent_curve_imprint: bool,
267}
268
269fn default_tolerance() -> f64 {
270 1e-7
271}
272
273fn default_tangent_curve_lane() -> bool {
274 switch!(live "BREP_TANGENT_CURVE_LANE", true)
275}
276
277fn default_tangent_curve_imprint() -> bool {
278 switch!(live "BREP_TANGENT_CURVE_IMPRINT", true)
279}
280
281fn default_maximum_fit_points() -> usize {
282 80
283}
284
285/// Angular band inside which two surface normals count as PARALLEL when a face
286/// pair is classified (`|n_a × n_b| <= PAIR_ANGULAR_TOLERANCE` ⇒ the carriers
287/// graze rather than cross there). Single source for the pair classifier's
288/// angular tolerance and for the near-tangency test that picks the march step.
289const PAIR_ANGULAR_TOLERANCE: f64 = 1e-4;
290
291/// Fraction of the part extent used as the FLOOR of the near-tangency march
292/// step when the two carriers actually touch (`minimum_separation == 0`), so
293/// the reachable curve length is a fixed fraction of the model rather than an
294/// absolute distance. See `march_maximum_step`.
295const NEAR_TANGENT_STEP_FRACTION: f64 = 1e-3;
296
297/// Span band for the B2 shared-section-edge decision, as a FRACTION of the part
298/// extent (so it tracks feature size, not an absolute distance). A SSI section
299/// is declared coincident with an existing boundary edge only when it lies
300/// within `SHARED_SECTION_BAND_FRACTION * extent` of that edge along its whole
301/// span in BOTH directions AND their endpoints already coincide within the weld
302/// radius. Sized to admit a genuine near-tangent GRAZE (the marched/analytic
303/// section drifts from the vendor edge by a graze-scale gap two-three orders
304/// above the fit residual — the B1-falsification measurement) while staying far
305/// below the feature scale at which a distinct same-endpoint edge diverges.
306/// Measured on fixture 09 (extent ~3.23, band ~3.23e-3): the two genuine graze
307/// gaps are 8.2e-4 and 1.67e-3 (ratios 2.5e-4 / 5.2e-4) — comfortably inside;
308/// fixtures 12/04 (the wrong-reuse tripwires) produce ZERO reuses and the
309/// prim×prim fuzz shows 0/2800 outcome changes, so the band is well separated
310/// from any distinct-edge scale.
311const SHARED_SECTION_BAND_FRACTION: f64 = 1e-3;
312
313/// Maximum march step for one face pair.
314///
315/// A NEAR-TANGENT pair marches finely: where the carriers graze, the corrector
316/// can hop between the two sheets of the contact, so the step stays inside the
317/// separation band. Two things that step must NOT be:
318///
319/// * **applied to a pair that only crosses.** A pair is classified `Singular`
320/// when any sample near the contact has a DEGENERATE normal (a pole of a
321/// revolution carrier) — that says nothing about tangency, and the pair can
322/// cross at 90°. Marching a transverse crossing at the tangency step crawls,
323/// and a curve longer than `maximum_steps × step` then dies as "trace
324/// exhausted" (2026-08-06 report: a draft-angle extrude wall against a
325/// revolve-of-revolve face — a 2.0-unit curve needing 4014 steps of 4000,
326/// 10 points once marched at its own scale). The step is therefore gated on
327/// the classification's own tangency evidence, not on the relation label.
328/// * **an absolute distance.** A fixed floor is a different fraction of every
329/// model, so the reachable curve length depended on part size. The floor is
330/// a fraction of the part extent instead; `solid_scale` is at least 1, so
331/// unit-scale parts keep the historical `1e-3` exactly.
332fn march_maximum_step(
333 classification: &SurfacePairClassification,
334 requested: Option<f64>,
335 scale: f64,
336) -> Option<f64> {
337 let grazes = matches!(
338 classification.relation,
339 SurfacePairRelation::NearTangent | SurfacePairRelation::Singular
340 ) && classification.minimum_normal_cross <= PAIR_ANGULAR_TOLERANCE;
341 if !grazes {
342 return requested;
343 }
344 Some(
345 requested.unwrap_or(
346 classification
347 .minimum_separation
348 .max(NEAR_TANGENT_STEP_FRACTION * scale),
349 ) * 0.5,
350 )
351}
352
353impl Default for ImprintOptions {
354 fn default() -> Self {
355 Self {
356 tolerance: default_tolerance(),
357 maximum_fit_points: default_maximum_fit_points(),
358 local_fit: false,
359 fit_chunk_points: None,
360 maximum_ssi_step: None,
361 span_budget: None,
362 hermite_sections: false,
363 tangent_curve_lane: default_tangent_curve_lane(),
364 tangent_curve_imprint: default_tangent_curve_imprint(),
365 exact_iso_pcurves: false,
366 march_starts: false,
367 two_radius_junctions: false,
368 }
369 }
370}
371
372#[derive(Clone, Debug, Deserialize, Serialize)]
373pub struct ImprintVertex {
374 pub id: u64,
375 pub point: Vec3,
376}
377
378#[derive(Clone, Debug, Deserialize, Serialize)]
379pub struct FacePcurve {
380 pub operand: u8,
381 pub face_id: u64,
382 pub pcurve: NurbsCurve,
383}
384
385#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Hash, Serialize)]
386pub struct FaceKey {
387 pub operand: u8,
388 pub face_id: u64,
389}
390
391#[derive(Clone, Debug, Deserialize, Serialize)]
392pub struct ImprintPieceRecord {
393 pub id: u64,
394 pub curve: NurbsCurve,
395 pub t0: f64,
396 pub t1: f64,
397 pub start_vertex_id: u64,
398 pub end_vertex_id: u64,
399 pub pcurves: Vec<FacePcurve>,
400 pub support_faces: [FaceKey; 2],
401 /// OCCT common-block / `IsExistingPaveBlock` (B2): when this SSI section
402 /// curve was found to COINCIDE along its whole span with an EXISTING
403 /// boundary edge of one of its support faces, the section is not a new
404 /// 1-cell — it IS that boundary edge. Records `(operand, edge_id, aligned)`
405 /// of the existing edge to REUSE; `aligned` is whether the section's
406 /// start→end runs the same direction as the edge's start→end. The
407 /// assembler then resolves this piece to the shared boundary edge's
408 /// identity so both operands reference ONE edge (no duplicate section /
409 /// one-use edge). `None` = an ordinary freshly-minted section (the
410 /// historical behaviour; also what `BREP_SHARED_SECTION_EDGE=0` forces).
411 #[serde(default, skip_serializing_if = "Option::is_none")]
412 pub shared_edge: Option<(u8, u64, bool)>,
413}
414
415#[derive(Clone, Debug, Deserialize, Serialize)]
416pub struct EdgeSplitRecord {
417 pub operand: u8,
418 pub edge_id: u64,
419 pub parameters: Vec<f64>,
420}
421
422#[derive(Clone, Debug, Deserialize, Serialize)]
423pub struct FaceImprints {
424 pub operand: u8,
425 pub face_id: u64,
426 pub piece_ids: Vec<u64>,
427}
428
429#[derive(Clone, Debug, Deserialize, Serialize)]
430pub struct ImprintResultRecord {
431 pub vertices: Vec<ImprintVertex>,
432 pub pieces: Vec<ImprintPieceRecord>,
433 pub by_face: Vec<FaceImprints>,
434 pub edge_splits: Vec<EdgeSplitRecord>,
435 /// Operand edges geometrically OVERLAPPED by a section curve (the
436 /// cosurface/coincident locus: an inscribed sphere's contact circle
437 /// riding a cap ring). Fragment-selection fate must never flood across
438 /// them — the two sides of such an edge can lie on opposite sides of
439 /// the other operand (the cap disc inside, the wall outside).
440 #[serde(default)]
441 pub barrier_edges: Vec<(u8, u64)>,
442 /// Every ISOLATED TANGENT NODE the imprint admitted: a point where the two
443 /// carriers touch with parallel normals and the section crosses itself, so
444 /// the pair was marched rather than refused (see
445 /// `imprint/tangent_contact.rs`). The boolean attributes a later tearing to
446 /// these rather than reporting an anonymous degeneracy — the second-order
447 /// filter cannot decide a third-order singularity, so the assembly is the
448 /// authority on whether a node it admitted was really imprintable.
449 #[serde(default)]
450 pub tangent_nodes: Vec<Vec3>,
451 /// True when the imprint saw ANY surface-contact evidence — an accepted
452 /// pierce seed, a traced SSI branch (even one later clipped away), or a
453 /// minted piece. Pure material disjointness leaves none, while a
454 /// silently-lost section always leaves at least the upstream evidence, so
455 /// the boolean's legitimate-empty adjudication requires this to be false.
456 #[serde(default)]
457 pub section_evidence: bool,
458 /// Every face pair the imprint read as ONE surface and exchanged boundary
459 /// curves across instead of intersecting (`cosurface_pair`, or the sampled
460 /// pair classification's `Cosurface`). Selection holds a fragment whose
461 /// point lies in such a partner's trim On against it, so the coincidence
462 /// the sections were built on is the one the fragments are kept by.
463 #[serde(default)]
464 pub cosurface_pairs: Vec<(FaceKey, FaceKey)>,
465 /// Every EXTENDED tangential contact the tangent-curve lane recognised
466 /// ([`ImprintOptions::tangent_curve_lane`]): the carriers touch along a
467 /// curve inside both trims. A planar-carrier contact is marched and the
468 /// clipped run described; a curved/curved contact is named at its point
469 /// and not traced. None of these is imprinted yet — the record exists so
470 /// the boolean can attribute a refusal on the pair to the contact by name.
471 /// Appended at the end of the struct (2026-10-10).
472 #[serde(default)]
473 pub tangent_sections: Vec<TangentSectionRecord>,
474}
475
476/// One extended tangential contact the imprint recognised (see
477/// [`ImprintResultRecord::tangent_sections`]).
478#[derive(Clone, Debug, Deserialize, Serialize)]
479pub struct TangentSectionRecord {
480 pub first: FaceKey,
481 pub second: FaceKey,
482 /// Ends of the longest run of the traced contact inside both trims (the
483 /// contact point itself when the contact was not traced).
484 pub start: Vec3,
485 pub end: Vec3,
486 /// Chord length of that run.
487 pub length: f64,
488 /// The run is the whole traced curve and the curve closed on itself.
489 pub closed: bool,
490 /// Stations of the run.
491 pub stations: usize,
492 /// One carrier is a plane: the branch the lane traces. `false` names a
493 /// curved/curved contact the lane recognises but does not trace.
494 pub planar: bool,
495 /// The faces the contact INVOLVES: the two carriers' faces, and every face
496 /// of either operand that shares an edge the run's ends lie on (the
497 /// through-bore's contact line ends on the wall's top and bottom edges,
498 /// so the box's top and bottom faces are involved; a blind pocket's ends
499 /// lie on the bore's cap rings, so the caps are). The boolean's
500 /// attribution rewrites a refusal only when a face it names is in here.
501 #[serde(default)]
502 pub faces: Vec<FaceKey>,
503 /// The section pieces the contact was imprinted as
504 /// ([`ImprintOptions::tangent_curve_imprint`]): `process_curve`'s pieces
505 /// on the clipped run, in mint order. Empty when the section was recorded
506 /// only. The assembler pairs the coedges of these pieces by material side.
507 /// Appended at the end of the struct (2026-10-11).
508 #[serde(default, skip_serializing_if = "Vec::is_empty")]
509 pub piece_ids: Vec<u64>,
510 /// GRAZING PIERCES WITHOUT A SECTION (2026-10-17, the revolve-into-bore
511 /// report): a trim edge of one face pierces the other carrier INSIDE both
512 /// trims, but at an angle below the seed gate, and the march found no
513 /// branch for the pair. The pierce proves a section crosses the faces
514 /// there; the empty march says the crossing is too near tangency to walk
515 /// (a third-order contact: the branch is born tangent to a contact curve
516 /// on a shared boundary, `boolean::attribute_to_tangent_node`). Each
517 /// entry is the pierce point and its `|edge_tangent · normal|`. Such a
518 /// record is attribution only — nothing is imprinted — and names the
519 /// contact when the assembly tears downstream of it. Appended at the end
520 /// of the struct.
521 #[serde(default, skip_serializing_if = "Vec::is_empty")]
522 pub grazing: Vec<(Vec3, f64)>,
523}
524
525impl TangentSectionRecord {
526 /// A record standing on its grazing pierces ALONE — the lane found no
527 /// contact to name, so the driver set its ends to the pierces (its
528 /// `start` IS the first pierce, bit for bit, and nothing was traced). The
529 /// boolean's attribution reads such a record only as a fallback: a
530 /// contact the lane found, or a tangent node the imprint classified, is
531 /// the nearer cause and keeps its own wording.
532 pub fn pierce_only(&self) -> bool {
533 self.stations == 0
534 && self
535 .grazing
536 .first()
537 .is_some_and(|(point, _)| point.sub(self.start).length() == 0.0)
538 }
539}
540
541#[path = "imprint/ruled_torus.rs"]
542mod ruled_torus;
543pub(crate) use ruled_torus::{circular_revolution_profile, construct_ruled_torus, RuledTorusBoundary};
544
545#[path = "imprint/support.rs"]
546mod support;
547#[path = "imprint/builder.rs"]
548mod builder;
549#[path = "imprint/junctions.rs"]
550mod junctions;
551#[path = "imprint/self_touch.rs"]
552mod self_touch;
553#[path = "imprint/sections.rs"]
554mod sections;
555#[path = "imprint/tangent_contact.rs"]
556mod tangent_contact;
557#[path = "imprint/driver.rs"]
558mod driver;
559#[path = "imprint/hermite.rs"]
560mod hermite;
561
562#[path = "imprint/gate_census.rs"]
563mod gate_census;
564
565use builder::*;
566use junctions::*;
567use sections::*;
568use support::*;
569
570#[path = "imprint/section_graph.rs"]
571mod section_graph;
572pub(crate) use section_graph::{plane_section_graph, plane_section_graph_range, plane_section_graph_range_bounded};
573
574/// Reuse imprint's exact ruled-carrier section at the assembly repair boundary.
575/// This exposes the construction, not its arrangement or acceptance policy.
576pub(crate) fn planar_carrier_section(
577 first: &NurbsSurface,
578 second: &NurbsSurface,
579 tolerance: f64,
580) -> Result<Option<NurbsCurve>, crate::KernelRefusal> {
581 support::planar_iso_intersection(first,second,tolerance)
582}
583
584use tangent_contact::classify_tangent_contact;
585
586pub use driver::build_imprints;
587pub(crate) use driver::{build_carrier_imprints, build_carrier_imprints_within, take_rescue_firings};
588pub(crate) use self_touch::self_touch_edge_splits;
589pub(crate) use support::clear_window_memo;
590pub(crate) use self_touch::clear_touch_memo;
591
592
593#[path = "imprint/pcurve_cache.rs"]
594mod pcurve_cache;
595use pcurve_cache::cached_build_pcurve as build_pcurve_on_surface_marched;
596
597#[path = "imprint/intersection_cache.rs"]
598mod intersection_cache;
599use intersection_cache::intersect as intersect_curve_surface;