brepkit_operations/
offset_v2.rs1use brepkit_offset::{JointType, OffsetError, OffsetOptions};
4use brepkit_topology::Topology;
5use brepkit_topology::face::FaceId;
6use brepkit_topology::solid::SolidId;
7
8use crate::OperationsError;
9
10fn map_offset_error(e: OffsetError) -> OperationsError {
13 match e {
14 OffsetError::Topology(t) => OperationsError::Topology(t),
15 OffsetError::Math(m) => OperationsError::Math(m),
16
17 other => OperationsError::InvalidInput {
18 reason: format!("{other}"),
19 },
20 }
21}
22
23pub fn offset_solid_v2(
29 topo: &mut Topology,
30 solid: SolidId,
31 distance: f64,
32) -> Result<SolidId, OperationsError> {
33 brepkit_offset::offset_solid(topo, solid, distance, OffsetOptions::default())
34 .map_err(map_offset_error)
35}
36
37pub fn shell_v2(
43 topo: &mut Topology,
44 solid: SolidId,
45 thickness: f64,
46 exclude: &[FaceId],
47) -> Result<SolidId, OperationsError> {
48 brepkit_offset::thick_solid(topo, solid, thickness, exclude, OffsetOptions::default())
49 .map_err(map_offset_error)
50}
51
52pub fn offset_solid_arc_v2(
58 topo: &mut Topology,
59 solid: SolidId,
60 distance: f64,
61) -> Result<SolidId, OperationsError> {
62 let options = OffsetOptions {
63 joint: JointType::Arc,
64 ..Default::default()
65 };
66 brepkit_offset::offset_solid(topo, solid, distance, options).map_err(map_offset_error)
67}
68
69#[cfg(test)]
70mod tests {
71 #![allow(clippy::unwrap_used)]
72 use super::*;
73 use brepkit_topology::Topology;
74
75 #[test]
76 fn offset_v2_box() {
77 let mut topo = Topology::new();
78 let solid = crate::primitives::make_box(&mut topo, 2.0, 2.0, 2.0).unwrap();
79 let result = offset_solid_v2(&mut topo, solid, 0.5).unwrap();
80 let shell = topo
81 .shell(topo.solid(result).unwrap().outer_shell())
82 .unwrap();
83 assert_eq!(shell.faces().len(), 6);
84 }
85}