opencascade 0.3.0

A high level Rust wrapper to build 3D models in code, using the OpenCascade CAD kernel
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
use crate::{
    angle::Angle,
    law_function::law_function_from_graph,
    make_pipe_shell::make_pipe_shell_with_law_function,
    primitives::{
        make_axis_1, make_point, make_vec, EdgeIterator, JoinType, Shape, Solid, Surface, Wire,
    },
    workplane::Workplane,
};
use cxx::UniquePtr;
use glam::{dvec3, DVec3};
use opencascade_sys as ffi;

pub struct Face {
    pub(crate) inner: UniquePtr<ffi::topo_ds::TopoDS_Face>,
}

impl AsRef<Face> for Face {
    fn as_ref(&self) -> &Face {
        self
    }
}

impl Face {
    pub(crate) fn from_face(face: &ffi::topo_ds::TopoDS_Face) -> Self {
        let inner = ffi::topo_ds::TopoDS_Face_to_owned(face);

        Self { inner }
    }

    fn from_make_face(
        make_face: UniquePtr<ffi::b_rep_builder_api::BRepBuilderAPI_MakeFace>,
    ) -> Self {
        Self::from_face(make_face.Face())
    }

    pub fn from_wire(wire: &Wire) -> Self {
        let only_plane = false;
        let make_face =
            ffi::b_rep_builder_api::BRepBuilderAPI_MakeFace_wire(&wire.inner, only_plane);

        Self::from_make_face(make_face)
    }

    pub fn from_wire_with_holes(outer: &Wire, holes: &[Wire]) -> Self {
        let only_plane = true;
        let mut make_face =
            ffi::b_rep_builder_api::BRepBuilderAPI_MakeFace_wire(&outer.inner, only_plane);
        for hole in holes {
            make_face.pin_mut().add_wire(&hole.inner);
        }
        make_face.pin_mut().Build(&ffi::message::Message_ProgressRange_new());
        Self::from_make_face(make_face)
    }

    pub fn from_surface(surface: &Surface) -> Self {
        const EDGE_TOLERANCE: f64 = 0.0001;

        let make_face =
            ffi::b_rep_builder_api::BRepBuilderAPI_MakeFace_surface(&surface.inner, EDGE_TOLERANCE);

        Self::from_make_face(make_face)
    }

    #[must_use]
    pub fn extrude(&self, dir: DVec3) -> Solid {
        let prism_vec = make_vec(dir);

        let copy = false;
        let canonize = true;

        let inner_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);
        let mut make_solid =
            ffi::b_rep_prim_api::BRepPrimAPI_MakePrism_new(inner_shape, &prism_vec, copy, canonize);
        let extruded_shape = make_solid.pin_mut().Shape();
        let solid = ffi::topo_ds::TopoDS::Solid(extruded_shape);

        Solid::from_solid(solid)
    }

    #[must_use]
    pub fn extrude_to_face(&self, shape_with_face: &Shape, face: &Face) -> Shape {
        let profile_base = &self.inner;
        let sketch_base = ffi::topo_ds::TopoDS_Face_new();
        let angle = 0.0;
        let fuse = 1; // 0 = subtractive, 1 = additive
        let modify = false;

        let mut make_prism = ffi::b_rep_feat::BRepFeat_MakeDPrism_new(
            &shape_with_face.inner,
            profile_base,
            &sketch_base,
            angle,
            fuse,
            modify,
        );

        let until_face = ffi::topo_ds::cast_face_to_shape(&face.inner);
        make_prism.pin_mut().perform_until_face(until_face);

        Shape::from_shape(make_prism.pin_mut().Shape())
    }

    #[must_use]
    pub fn subtractive_extrude(&self, shape_with_face: &Shape, height: f64) -> Shape {
        let profile_base = &self.inner;
        let sketch_base = ffi::topo_ds::TopoDS_Face_new();
        let angle = 0.0;
        let fuse = 0; // 0 = subtractive, 1 = additive
        let modify = false;

        let mut make_prism = ffi::b_rep_feat::BRepFeat_MakeDPrism_new(
            &shape_with_face.inner,
            profile_base,
            &sketch_base,
            angle,
            fuse,
            modify,
        );

        make_prism.pin_mut().perform_with_height(height);

        Shape::from_shape(make_prism.pin_mut().Shape())
    }

    #[must_use]
    pub fn revolve(&self, origin: DVec3, axis: DVec3, angle: Option<Angle>) -> Solid {
        let revol_vec = make_axis_1(origin, axis);

        let angle = angle.map(Angle::radians).unwrap_or(std::f64::consts::PI * 2.0);
        let copy = false;

        let inner_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);
        let mut make_solid =
            ffi::b_rep_prim_api::BRepPrimAPI_MakeRevol_new(inner_shape, &revol_vec, angle, copy);
        let revolved_shape = make_solid.pin_mut().Shape();
        let solid = ffi::topo_ds::TopoDS::Solid(revolved_shape);

        Solid::from_solid(solid)
    }

    /// Fillets the face edges by a given radius at each vertex
    #[must_use]
    pub fn fillet(&self, radius: f64) -> Self {
        let mut make_fillet = ffi::b_rep_fillet_api::BRepFilletAPI_MakeFillet2d_new(&self.inner);

        let face_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);

        // We use a shape map here to avoid duplicates.
        let mut shape_map = ffi::top_tools::new_indexed_map_of_shape();
        ffi::top_exp::TopExp::MapShapes(
            face_shape,
            ffi::top_abs::TopAbs_ShapeEnum::TopAbs_VERTEX,
            shape_map.pin_mut(),
        );

        for i in 1..=shape_map.Extent() {
            let vertex = ffi::topo_ds::TopoDS::Vertex(shape_map.FindKey(i));
            ffi::b_rep_fillet_api::BRepFilletAPI_MakeFillet2d_add_fillet(
                make_fillet.pin_mut(),
                vertex,
                radius,
            );
        }

        make_fillet.pin_mut().Build(&ffi::message::Message_ProgressRange_new());

        let result_shape = make_fillet.pin_mut().Shape();
        let result_face = ffi::topo_ds::TopoDS::Face(result_shape);

        Self::from_face(result_face)
    }

    /// Chamfer the wire edges at each vertex by a given distance
    #[must_use]
    pub fn chamfer(&self, distance_1: f64) -> Self {
        // TODO - Support asymmetric chamfers.
        let distance_2 = distance_1;

        let face_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);

        let mut make_fillet = ffi::b_rep_fillet_api::BRepFilletAPI_MakeFillet2d_new(&self.inner);

        let mut vertex_map = ffi::top_tools::new_indexed_map_of_shape();
        ffi::top_exp::TopExp::MapShapes(
            face_shape,
            ffi::top_abs::TopAbs_ShapeEnum::TopAbs_VERTEX,
            vertex_map.pin_mut(),
        );

        // Get map of vertices to edges so we can find the edges connected to each vertex.
        let mut data_map = ffi::top_tools::new_indexed_data_map_of_shape_list_of_shape();
        ffi::top_exp::TopExp::MapShapesAndAncestors(
            face_shape,
            ffi::top_abs::TopAbs_ShapeEnum::TopAbs_VERTEX,
            ffi::top_abs::TopAbs_ShapeEnum::TopAbs_EDGE,
            data_map.pin_mut(),
        );

        // Chamfer at vertex of all edges.
        for i in 1..=vertex_map.Extent() {
            let edges = ffi::topo_ds::shape_list_to_vector(data_map.FindFromIndex(i));
            let edge_1 = edges.get(0).expect("Vertex has no edges");
            let edge_2 = edges.get(1).expect("Vertex has only one edge");
            ffi::b_rep_fillet_api::BRepFilletAPI_MakeFillet2d_add_chamfer(
                make_fillet.pin_mut(),
                ffi::topo_ds::TopoDS::Edge(edge_1),
                ffi::topo_ds::TopoDS::Edge(edge_2),
                distance_1,
                distance_2,
            );
        }

        let filleted_shape = make_fillet.pin_mut().Shape();
        let result_face = ffi::topo_ds::TopoDS::Face(filleted_shape);

        Self::from_face(result_face)
    }

    /// Offset the face by a given distance and join settings
    #[must_use]
    pub fn offset(&self, distance: f64, join_type: JoinType) -> Self {
        let mut make_offset =
            ffi::b_rep_offset_api::BRepOffsetAPI_MakeOffset_face_new(&self.inner, join_type.into());
        make_offset.pin_mut().Perform(distance, 0.0);

        let offset_shape = make_offset.pin_mut().Shape();
        let result_wire = ffi::topo_ds::TopoDS::Wire(offset_shape);
        let wire = Wire::from_wire(result_wire);

        wire.to_face()
    }

    /// Sweep the face along a path to produce a solid
    #[must_use]
    pub fn sweep_along(&self, path: &Wire) -> Solid {
        let profile_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);
        let mut make_pipe =
            ffi::b_rep_offset_api::BRepOffsetAPI_MakePipe_new(&path.inner, profile_shape);

        let pipe_shape = make_pipe.pin_mut().Shape();
        let result_solid = ffi::topo_ds::TopoDS::Solid(pipe_shape);

        Solid::from_solid(result_solid)
    }

    /// Sweep the face along a path, modulated by a function, to produce a solid
    #[must_use]
    pub fn sweep_along_with_radius_values(
        &self,
        path: &Wire,
        radius_values: impl IntoIterator<Item = (f64, f64)>,
    ) -> Solid {
        let law_function = law_function_from_graph(radius_values);
        let law_handle = ffi::law::Law_Function_to_handle(law_function);

        let profile_wire = ffi::b_rep_tools::outer_wire(&self.inner);
        let mut make_pipe_shell =
            make_pipe_shell_with_law_function(&profile_wire, &path.inner, &law_handle);

        make_pipe_shell.pin_mut().Build(&ffi::message::Message_ProgressRange_new());
        make_pipe_shell.pin_mut().MakeSolid();
        let pipe_shape = make_pipe_shell.pin_mut().Shape();
        let result_solid = ffi::topo_ds::TopoDS::Solid(pipe_shape);

        Solid::from_solid(result_solid)
    }

    pub fn edges(&self) -> EdgeIterator {
        let explorer = ffi::top_exp::TopExp_Explorer_new(
            ffi::topo_ds::cast_face_to_shape(&self.inner),
            ffi::top_abs::TopAbs_ShapeEnum::TopAbs_EDGE,
        );

        EdgeIterator { explorer }
    }

    pub fn center_of_mass(&self) -> DVec3 {
        let mut props = ffi::g_prop::GProps_new();

        let inner_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);
        let skip_shared = false;
        let use_triangulation = false;
        ffi::b_rep_g_prop::BRepGProp::SurfaceProperties(
            inner_shape,
            props.pin_mut(),
            skip_shared,
            use_triangulation,
        );

        let center = ffi::g_prop::GProp_GProps_CentreOfMass(&props);

        dvec3(center.X(), center.Y(), center.Z())
    }

    pub fn normal_at(&self, pos: DVec3) -> DVec3 {
        let surface = ffi::b_rep::BRep_Tool_Surface(&self.inner);
        let projector = ffi::geom_api::GeomAPI_ProjectPointOnSurf_new(&make_point(pos), &surface);
        let mut u: f64 = 0.0;
        let mut v: f64 = 0.0;

        projector.LowerDistanceParameters(&mut u, &mut v);

        let mut p = ffi::gp::new_point(0.0, 0.0, 0.0);
        let mut normal = ffi::gp::new_vec(0.0, 1.0, 0.0);

        let face = ffi::b_rep_g_prop::BRepGProp_Face_new(&self.inner);
        face.Normal(u, v, p.pin_mut(), normal.pin_mut());

        dvec3(normal.X(), normal.Y(), normal.Z())
    }

    pub fn normal_at_center(&self) -> DVec3 {
        let center = self.center_of_mass();
        self.normal_at(center)
    }

    pub fn workplane(&self) -> Workplane {
        const NORMAL_DIFF_TOLERANCE: f64 = 0.0001;

        let center = self.center_of_mass();
        let normal = self.normal_at(center);
        let mut x_dir = dvec3(0.0, 0.0, 1.0).cross(normal);

        if x_dir.length() < NORMAL_DIFF_TOLERANCE {
            // The normal of this face is too close to the same direction
            // as the global Z axis. Use the global X axis for X instead.
            x_dir = dvec3(1.0, 0.0, 0.0);
        }

        let mut workplane = Workplane::new(x_dir, normal);
        workplane.set_translation(center);
        workplane
    }

    pub fn union(&self, other: &Face) -> CompoundFace {
        let inner_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);
        let other_inner_shape = ffi::topo_ds::cast_face_to_shape(&other.inner);

        let mut fuse_operation =
            ffi::b_rep_algo_api::BRepAlgoAPI_Fuse_new(inner_shape, other_inner_shape);

        let fuse_shape = fuse_operation.pin_mut().Shape();

        let compound = ffi::topo_ds::TopoDS::Compound(fuse_shape);

        CompoundFace::from_compound(compound)
    }

    #[must_use]
    pub fn intersect(&self, other: &Face) -> CompoundFace {
        let inner_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);
        let other_inner_shape = ffi::topo_ds::cast_face_to_shape(&other.inner);

        let mut common_operation =
            ffi::b_rep_algo_api::BRepAlgoAPI_Common_new(inner_shape, other_inner_shape);

        let common_shape = common_operation.pin_mut().Shape();

        let compound = ffi::topo_ds::TopoDS::Compound(common_shape);

        CompoundFace::from_compound(compound)
    }

    pub fn subtract(&self, other: &Face) -> CompoundFace {
        let inner_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);
        let other_inner_shape = ffi::topo_ds::cast_face_to_shape(&other.inner);

        let mut fuse_operation =
            ffi::b_rep_algo_api::BRepAlgoAPI_Cut_new(inner_shape, other_inner_shape);

        let cut_shape = fuse_operation.pin_mut().Shape();

        let compound = ffi::topo_ds::TopoDS::Compound(cut_shape);

        CompoundFace::from_compound(compound)
    }

    pub fn surface_area(&self) -> f64 {
        let mut props = ffi::g_prop::GProps_new();

        let inner_shape = ffi::topo_ds::cast_face_to_shape(&self.inner);

        let skip_shared = false;
        let use_triangulation = false;
        ffi::b_rep_g_prop::BRepGProp::SurfaceProperties(
            inner_shape,
            props.pin_mut(),
            skip_shared,
            use_triangulation,
        );

        // Returns surface area, obviously.
        props.Mass()
    }

    pub fn orientation(&self) -> FaceOrientation {
        FaceOrientation::from(self.inner.Orientation())
    }

    #[must_use]
    pub fn outer_wire(&self) -> Wire {
        let inner = ffi::b_rep_tools::outer_wire(&self.inner);

        Wire { inner }
    }
}

pub struct CompoundFace {
    inner: UniquePtr<ffi::topo_ds::TopoDS_Compound>,
}

impl AsRef<CompoundFace> for CompoundFace {
    fn as_ref(&self) -> &CompoundFace {
        self
    }
}

impl From<Face> for CompoundFace {
    fn from(face: Face) -> Self {
        let face = ffi::topo_ds::cast_face_to_shape(&face.inner);
        let mut compound = ffi::topo_ds::TopoDS_Compound_new();
        let brep_builder = ffi::b_rep::BRep_Builder_new();
        let topo_builder = ffi::b_rep::BRep_Builder_upcast_to_topods_builder(&brep_builder);
        topo_builder.MakeCompound(compound.pin_mut());
        let mut compound_shape = ffi::topo_ds::TopoDS_Compound_as_shape(compound);
        topo_builder.Add(compound_shape.pin_mut(), face);
        Self::from_compound(ffi::topo_ds::TopoDS::Compound(&compound_shape))
    }
}

impl CompoundFace {
    pub(crate) fn from_compound(compound: &ffi::topo_ds::TopoDS_Compound) -> Self {
        let inner = ffi::topo_ds::TopoDS_Compound_to_owned(compound);

        Self { inner }
    }

    #[must_use]
    pub fn clean(&self) -> Self {
        let shape = ffi::topo_ds::cast_compound_to_shape(&self.inner);
        let shape = Shape::from_shape(shape).clean();

        let compound = ffi::topo_ds::TopoDS::Compound(&shape.inner);

        Self::from_compound(compound)
    }

    #[must_use]
    pub fn extrude(&self, dir: DVec3) -> Shape {
        let prism_vec = make_vec(dir);

        let copy = false;
        let canonize = true;

        let inner_shape = ffi::topo_ds::cast_compound_to_shape(&self.inner);

        let mut make_solid =
            ffi::b_rep_prim_api::BRepPrimAPI_MakePrism_new(inner_shape, &prism_vec, copy, canonize);
        let extruded_shape = make_solid.pin_mut().Shape();

        Shape::from_shape(extruded_shape)
    }

    #[must_use]
    pub fn revolve(&self, origin: DVec3, axis: DVec3, angle: Option<Angle>) -> Shape {
        let revol_axis = make_axis_1(origin, axis);

        let angle = angle.map(Angle::radians).unwrap_or(std::f64::consts::PI * 2.0);
        let copy = false;

        let inner_shape = ffi::topo_ds::cast_compound_to_shape(&self.inner);

        let mut make_solid =
            ffi::b_rep_prim_api::BRepPrimAPI_MakeRevol_new(inner_shape, &revol_axis, angle, copy);
        let revolved_shape = make_solid.pin_mut().Shape();

        Shape::from_shape(revolved_shape)
    }

    #[must_use]
    pub fn union(&self, other: &CompoundFace) -> CompoundFace {
        let inner_shape = ffi::topo_ds::cast_compound_to_shape(&self.inner);
        let other_inner_shape = ffi::topo_ds::cast_compound_to_shape(&other.inner);

        let mut fuse_operation =
            ffi::b_rep_algo_api::BRepAlgoAPI_Fuse_new(inner_shape, other_inner_shape);

        let fuse_shape = fuse_operation.pin_mut().Shape();

        let compound = ffi::topo_ds::TopoDS::Compound(fuse_shape);

        CompoundFace::from_compound(compound)
    }

    #[must_use]
    pub fn intersect(&self, other: &CompoundFace) -> CompoundFace {
        let inner_shape = ffi::topo_ds::cast_compound_to_shape(&self.inner);
        let other_inner_shape = ffi::topo_ds::cast_compound_to_shape(&other.inner);

        let mut common_operation =
            ffi::b_rep_algo_api::BRepAlgoAPI_Common_new(inner_shape, other_inner_shape);

        let common_shape = common_operation.pin_mut().Shape();

        let compound = ffi::topo_ds::TopoDS::Compound(common_shape);

        CompoundFace::from_compound(compound)
    }

    #[must_use]
    pub fn subtract(&self, other: &CompoundFace) -> CompoundFace {
        let inner_shape = ffi::topo_ds::cast_compound_to_shape(&self.inner);
        let other_inner_shape = ffi::topo_ds::cast_compound_to_shape(&other.inner);

        let mut fuse_operation =
            ffi::b_rep_algo_api::BRepAlgoAPI_Cut_new(inner_shape, other_inner_shape);

        let cut_shape = fuse_operation.pin_mut().Shape();

        let compound = ffi::topo_ds::TopoDS::Compound(cut_shape);

        CompoundFace::from_compound(compound)
    }

    pub fn set_global_translation(&mut self, translation: DVec3) {
        let shape = ffi::topo_ds::cast_compound_to_shape(&self.inner);
        let mut shape = Shape::from_shape(shape);

        shape.set_global_translation(translation);

        let compound = ffi::topo_ds::TopoDS::Compound(&shape.inner);
        *self = Self::from_compound(compound);
    }
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum FaceOrientation {
    Forward,
    Reversed,
    Internal,
    External,
}

impl From<ffi::top_abs::TopAbs_Orientation> for FaceOrientation {
    fn from(orientation: ffi::top_abs::TopAbs_Orientation) -> Self {
        match orientation {
            ffi::top_abs::TopAbs_Orientation::TopAbs_FORWARD => Self::Forward,
            ffi::top_abs::TopAbs_Orientation::TopAbs_REVERSED => Self::Reversed,
            ffi::top_abs::TopAbs_Orientation::TopAbs_INTERNAL => Self::Internal,
            ffi::top_abs::TopAbs_Orientation::TopAbs_EXTERNAL => Self::External,
            ffi::top_abs::TopAbs_Orientation { repr } => {
                panic!("TopAbs_Orientation had an unrepresentable value: {repr}")
            },
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_add() {
        let face = Workplane::xy().rect(7.0, 5.0).to_face();
        assert!(
            (face.surface_area() - 35.0).abs() <= 0.00001,
            "Expected surface_area() to be ~35.0, was actually {}",
            face.surface_area()
        );
    }

    #[test]
    fn test_from_wire_with_no_holes() {
        let outer = Workplane::xy().rect(10.0, 10.0);
        let face = Face::from_wire_with_holes(&outer, &[]);
        assert!(
            (face.surface_area() - 100.0).abs() <= 0.00001,
            "Expected surface_area() to be ~100.0, was actually {}",
            face.surface_area()
        );
    }

    #[test]
    fn test_from_wire_with_holes() {
        let outer = Workplane::xy().rect(10.0, 10.0);
        let hole = Workplane::xy().circle(0.0, 0.0, 2.0);
        let face = Face::from_wire_with_holes(&outer, &[hole]);
        let expected = 100.0 - std::f64::consts::PI * 4.0;
        assert!(
            (face.surface_area() - expected).abs() <= 0.01,
            "Expected surface_area() to be ~{expected}, was actually {}",
            face.surface_area()
        );
    }

    #[test]
    fn test_from_wire_with_multiple_holes() {
        let outer = Workplane::xy().rect(10.0, 10.0);
        let hole1 = Workplane::xy().circle(-2.0, -2.0, 2.0);
        let hole2 = Workplane::xy().circle(3.0, 3.0, 1.0);
        let face = Face::from_wire_with_holes(&outer, &[hole1, hole2]);
        let expected = 100.0 - std::f64::consts::PI * (4.0 + 1.0);
        assert!(
            (face.surface_area() - expected).abs() <= 0.01,
            "Expected surface_area() to be ~{expected}, was actually {}",
            face.surface_area()
        );
    }
}