brep_kernel/offset/
offset_shell.rs1use crate::boolean::{assemble_open_fragments, edge_interior_lies_on, finalize_assembled_solid};
2use crate::classification::{parameter_point_in_face, PolygonClass};
3use crate::face_merge::merge_same_surface_faces_open;
4use crate::fragment::{fragment_solid, FaceFragmentRecord, FragmentEdgeSource};
5use crate::imprint::{
6 EdgeSplitRecord, FaceImprints, FaceKey, FacePcurve, ImprintOptions, ImprintPieceRecord,
7 ImprintResultRecord, ImprintVertex,
8};
9use crate::mass_properties::parameter_space_area;
10use crate::project_point_to_surface;
11use crate::topology::{
12 BrepSolid, CoedgeRecord, EdgeRecord, FaceRecord, LoopRecord, ShellRecord, VertexRecord,
13};
14use crate::{
15 apply_edge_splits, build_imprints, classify_point, offset_face_carrier, DiagnosticSeverity,
16 KernelDiagnostics, KernelOutcome, KernelStage, KernelTolerances, PointClass, Vec2, Vec3,
17};
18use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
19use serde::Serialize;
20
21const SOURCE_OPERAND: u8 = 250;
22
23const MINIMUM_DISTANCE: f64 = 1e-7;
29
30fn debug_enabled() -> bool {
31 std::env::var("BREP_OS_DEBUG").is_ok_and(|value| !value.is_empty() && value != "0")
32}
33
34macro_rules! os_debug {
35 ($($arg:tt)*) => {
36 if debug_enabled() {
37 eprintln!($($arg)*);
38 }
39 };
40}
41
42#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
43#[serde(rename_all = "lowercase")]
44pub enum OffsetFaceRole {
45 Source,
46 Offset,
47 Wall,
48}
49
50#[derive(Clone, Debug, Serialize)]
51pub struct OffsetShellResultRecord {
52 pub solid: BrepSolid,
53 pub face_images: Vec<OffsetShellFaceImageRecord>,
54}
55
56#[derive(Clone, Debug, Serialize)]
57pub struct OffsetShellFaceImageRecord {
58 pub role: OffsetFaceRole,
59 pub source_face_id: u64,
60}
61
62#[derive(Clone)]
63struct Carrier {
64 solid: BrepSolid,
65 source_face_id: u64,
66 kind: OffsetFaceRole,
67}
68
69#[path = "offset_shell/carriers.rs"]
70mod carriers;
71#[path = "offset_shell/smooth_sync.rs"]
72mod smooth_sync;
73#[path = "offset_shell/carrier_rebuild.rs"]
74mod carrier_rebuild;
75#[path = "offset_shell/connectors.rs"]
76mod connectors;
77#[path = "offset_shell/orientation.rs"]
78mod orientation;
79#[path = "offset_shell/rim_welds.rs"]
80mod rim_welds;
81#[path = "offset_shell/revolved_wedge.rs"]
82mod revolved_wedge;
83#[path = "offset_shell/outline_offset.rs"]
84mod outline_offset;
85#[path = "offset_shell/vacated_rim.rs"]
86mod vacated_rim;
87#[path = "offset_shell/pipeline.rs"]
88mod pipeline;
89#[path = "offset_shell/acceptance.rs"]
90mod acceptance;
91#[path = "offset_shell/profile.rs"]
92mod profile;
93#[path = "offset_shell/solid.rs"]
94mod solid;
95#[path = "offset_shell/refusals.rs"]
96mod refusals;
97
98use carrier_rebuild::*;
99use carriers::*;
100use connectors::*;
101use orientation::*;
102use outline_offset::*;
103use vacated_rim::*;
104use rim_welds::*;
105use smooth_sync::*;
106
107pub use pipeline::{offset_shell, offset_shell_with_diagnostics};
108pub use solid::{offset_shell_by_boolean, offset_solid, OffsetCorners};
109pub(crate) use refusals::{is_offset_shell_no_retained_face, is_offset_shell_open_curved_rim};
110pub(crate) use orientation::{flip_all_faces, flip_shell_faces, orient_open_solid_faces};
111
112fn merge_connected_shells(solid: &mut BrepSolid, shell_unions: Vec<(usize, usize)>) {
114 if shell_unions.is_empty() {
115 return;
116 }
117 let mut parent = (0..solid.shells.len()).collect::<Vec<_>>();
118 fn root(parent: &mut [usize], index: usize) -> usize {
119 if parent[index] != index {
120 parent[index] = root(parent, parent[index]);
121 }
122 parent[index]
123 }
124 for (first, second) in shell_unions {
125 let first_root = root(&mut parent, first);
126 let second_root = root(&mut parent, second);
127 if first_root != second_root {
128 parent[second_root] = first_root;
129 }
130 }
131 let original = std::mem::take(&mut solid.shells);
132 let mut merged = Vec::<ShellRecord>::new();
133 let mut group_of = HashMap::<usize, usize>::default();
134 for (index, shell) in original.into_iter().enumerate() {
135 let group = root(&mut parent, index);
136 if let Some(target) = group_of.get(&group).copied() {
137 merged[target].faces.extend(shell.faces);
138 } else {
139 group_of.insert(group, merged.len());
140 merged.push(shell);
141 }
142 }
143 solid.shells = merged;
144}