Struct truck_topology::Face

source ·
pub struct Face<P, C, S> { /* private fields */ }
Expand description

Face, attached to a simple and closed wire.

The constructors Face::new(), Face::try_new(), and Face::new_unchecked() create a different faces each time, even if the boundary wires are the same one. A face is uniquely identified by their id.

use truck_topology::*;
let v = Vertex::news(&[(), ()]);
let edge0 = Edge::new(&v[0], &v[1], ());
let edge1 = Edge::new(&v[1], &v[0], ());
let wire = Wire::from_iter(vec![&edge0, &edge1]);
let face0 = Face::new(vec![wire.clone()], ());
let face1 = Face::new(vec![wire], ());
assert_ne!(face0.id(), face1.id());

Implementations§

Creates a new face by a wire.

Failure

All wires in boundaries must be non-empty, simple and closed. If not, returns the following errors:

Examples
let v = Vertex::news(&[(); 4]);
let mut wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[3], ()),
    Edge::new(&v[3], &v[0], ()),
]);
assert!(Face::try_new(vec![wire], ()).is_ok());
Examples found in repository?
src/face.rs (line 53)
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
    pub fn new(boundaries: Vec<Wire<P, C>>, surface: S) -> Face<P, C, S> {
        Face::try_new(boundaries, surface).remove_try()
    }

    /// Creates a new face by a wire.
    /// # Remarks
    /// This method is prepared only for performance-critical development and is not recommended.  
    /// This method does NOT check the regularity conditions of `Face::try_new()`.  
    /// The programmer must guarantee this condition before using this method.
    #[inline(always)]
    pub fn new_unchecked(boundaries: Vec<Wire<P, C>>, surface: S) -> Face<P, C, S> {
        Face {
            boundaries,
            orientation: true,
            surface: Arc::new(Mutex::new(surface)),
        }
    }

    /// Creates a new face by a wire.
    /// # Remarks
    /// This method check the regularity conditions of `Face::try_new()` in the debug mode.  
    /// The programmer must guarantee this condition before using this method.
    #[inline(always)]
    pub fn debug_new(boundaries: Vec<Wire<P, C>>, surface: S) -> Face<P, C, S> {
        match cfg!(debug_assertions) {
            true => Face::new(boundaries, surface),
            false => Face::new_unchecked(boundaries, surface),
        }
    }

    /// Returns the boundaries of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let boundaries = face.boundaries();
    /// for (i, vert) in boundaries[0].vertex_iter().enumerate() {
    ///     assert_eq!(vert, v[i]);
    /// }
    ///
    /// // If invert the face, the boundaries is also inverted.
    /// face.invert();
    /// assert_eq!(boundaries[0].inverse(), face.boundaries()[0]);
    /// ```
    #[inline(always)]
    pub fn boundaries(&self) -> Vec<Wire<P, C>> {
        match self.orientation {
            true => self.boundaries.clone(),
            false => self.boundaries.iter().map(|wire| wire.inverse()).collect(),
        }
    }

    /// Consumes `self` and returns the entity of its boundaries.
    /// ```
    /// # use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let boundaries = face.clone().into_boundaries();
    /// for (i, vert) in boundaries[0].vertex_iter().enumerate() {
    ///     assert_eq!(vert, v[i]);
    /// }
    ///
    /// // If invert the face, the boundaries is also inverted.
    /// face.invert();
    /// assert_eq!(boundaries[0].inverse(), face.into_boundaries()[0]);
    /// ```
    #[inline(always)]
    pub fn into_boundaries(self) -> Vec<Wire<P, C>> {
        match self.orientation {
            true => self.boundaries,
            false => self.boundaries(),
        }
    }

    /// Returns the reference of the boundaries wire which is generated by constructor.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let boundaries = face.boundaries();
    /// face.invert();
    ///
    /// // The result of face.boundary() is already inversed.
    /// assert_eq!(face.boundaries()[0], boundaries[0].inverse());
    ///
    /// // The absolute boundaries does never change.
    /// assert_eq!(face.absolute_boundaries(), &boundaries);
    /// ```
    #[inline(always)]
    pub const fn absolute_boundaries(&self) -> &Vec<Wire<P, C>> { &self.boundaries }

    /// Returns a clone of the face without inversion.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// let face2 = face1.absolute_clone();
    /// assert_eq!(face0, face2);
    /// assert_ne!(face1, face2);
    /// assert!(face1.is_same(&face2));
    /// ```
    #[inline(always)]
    pub fn absolute_clone(&self) -> Self {
        Self {
            boundaries: self.boundaries.clone(),
            surface: Arc::clone(&self.surface),
            orientation: true,
        }
    }

    /// Returns an iterator over all edges in the boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// face.invert();
    /// let boundaries = face.boundaries().clone();
    /// let edge_iter0 = boundaries.iter().flat_map(Wire::edge_iter);
    /// let edge_iter1 = face.boundary_iters().into_iter().flatten();
    /// for (edge0, edge1) in edge_iter0.zip(edge_iter1) {
    ///     assert_eq!(edge0, &edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn boundary_iters(&self) -> Vec<BoundaryIter<'_, P, C>> {
        self.boundaries
            .iter()
            .map(|wire| BoundaryIter {
                edge_iter: wire.edge_iter(),
                orientation: self.orientation,
            })
            .collect()
    }

    #[inline(always)]
    fn renew_pointer(&mut self)
    where S: Clone {
        let surface = self.get_surface();
        self.surface = Arc::new(Mutex::new(surface));
    }

    /// Returns an iterator over the edges.
    #[inline(always)]
    pub fn edge_iter(&self) -> impl Iterator<Item = Edge<P, C>> + '_ {
        self.boundary_iters().into_iter().flatten()
    }

    /// Returns an iterator over the vertices.
    #[inline(always)]
    pub fn vertex_iter(&self) -> impl Iterator<Item = Vertex<P>> + '_ {
        self.edge_iter().map(|e| e.front().clone())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.try_add_boundary(wire1.clone()).unwrap();
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.try_add_boundary(wire1.clone()).unwrap();
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.try_add_boundary(wire1).unwrap();
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn try_add_boundary(&mut self, mut wire: Wire<P, C>) -> Result<()>
    where S: Clone {
        if wire.is_empty() {
            return Err(Error::EmptyWire);
        } else if !wire.is_closed() {
            return Err(Error::NotClosedWire);
        } else if !wire.is_simple() {
            return Err(Error::NotSimpleWire);
        }
        if !self.orientation {
            wire.invert();
        }
        self.boundaries.push(wire);
        self.renew_pointer();
        if !Wire::disjoint_wires(&self.boundaries) {
            self.boundaries.pop();
            return Err(Error::NotDisjointWires);
        }
        Ok(())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.add_boundary(wire1.clone());
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.add_boundary(wire1.clone());
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.add_boundary(wire1);
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn add_boundary(&mut self, wire: Wire<P, C>)
    where S: Clone {
        self.try_add_boundary(wire).remove_try()
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }

    /// Returns the orientation of face.
    ///
    /// The result of this method is the same with `self.boundaries() == self.absolute_boundaries().clone()`.
    /// Moreover, if this method returns false, `self.boundaries() == self.absolute_boundaries().inverse()`.
    #[inline(always)]
    pub fn orientation(&self) -> bool { self.orientation }

    /// Returns the clone of surface of face.
    #[inline(always)]
    pub fn get_surface(&self) -> S
    where S: Clone {
        self.surface.lock().unwrap().clone()
    }

    /// Sets the surface of face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], 0);
    /// let face1 = face0.clone();
    ///
    /// // Two faces have the same content.
    /// assert_eq!(face0.get_surface(), 0);
    /// assert_eq!(face1.get_surface(), 0);
    ///
    /// // Set surface
    /// face0.set_surface(1);
    ///
    /// // The contents of two vertices are synchronized.
    /// assert_eq!(face0.get_surface(), 1);
    /// assert_eq!(face1.get_surface(), 1);
    /// ```
    #[inline(always)]
    pub fn set_surface(&self, surface: S) { *self.surface.lock().unwrap() = surface; }

    /// Inverts the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let org_face = face.clone();
    /// let org_bdry = face.boundaries();
    /// face.invert();
    ///
    /// // Two faces are the same face.
    /// face.is_same(&org_face);
    ///
    /// // The boundaries is inverted.
    /// let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut face.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn invert(&mut self) -> &mut Self {
        self.orientation = !self.orientation;
        self
    }

    /// Returns whether two faces are the same. Returns `true` even if the orientaions are different.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// assert_ne!(face0, face1);
    /// assert!(face0.is_same(&face1));
    /// ```
    #[inline(always)]
    pub fn is_same(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
    }

    /// Returns the id that does not depend on the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// let face1 = face0.inverse();
    /// let face2 = Face::new(vec![wire], ());
    /// assert_ne!(face0, face1);
    /// assert_ne!(face0, face2);
    /// assert_eq!(face0.id(), face1.id());
    /// assert_ne!(face0.id(), face2.id());
    /// ```
    #[inline(always)]
    pub fn id(&self) -> FaceID<S> { ID::new(Arc::as_ptr(&self.surface)) }

    /// Returns how many same faces.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    ///
    /// // Create one face
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Create another face, independent from face0
    /// let face1 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Clone face0, the result will be 2.
    /// let face2 = face0.clone();
    /// assert_eq!(face0.count(), 2);
    /// assert_eq!(face2.count(), 2);
    /// // drop face2, the result will be 1.
    /// drop(face2);
    /// assert_eq!(face0.count(), 1);
    /// ```
    #[inline(always)]
    pub fn count(&self) -> usize { Arc::strong_count(&self.surface) }

    /// Returns the inverse face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let inverted = face.inverse();
    ///
    /// // Two faces are the same face.
    /// assert!(face.is_same(&inverted));
    ///
    /// // Two faces has the same id.
    /// assert_eq!(face.id(), inverted.id());
    ///
    /// // The boundaries is inverted.
    /// let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut inverted.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn inverse(&self) -> Face<P, C, S> {
        let mut face = self.clone();
        face.invert();
        face
    }

    /// Returns whether two faces `self` and `other` have a shared edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 4]);
    /// let shared_edge = Edge::new(&v[0], &v[1], ());
    /// let another_edge = Edge::new(&v[0], &v[1], ());
    /// let inversed_edge = shared_edge.inverse();
    /// let wire = vec![
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &another_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[3], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[1], ()), &inversed_edge, &Edge::new(&v[0], &v[3], ())]),
    /// ];
    /// let face: Vec<_> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert!(face[0].border_on(&face[2]));
    /// assert!(!face[1].border_on(&face[2]));
    /// assert!(face[0].border_on(&face[3]));
    /// ```
    pub fn border_on(&self, other: &Face<P, C, S>) -> bool {
        let mut hashmap = HashMap::default();
        let edge_iter = self.boundary_iters().into_iter().flatten();
        edge_iter.for_each(|edge| {
            hashmap.insert(edge.id(), edge);
        });
        let mut edge_iter = other.boundary_iters().into_iter().flatten();
        edge_iter.any(|edge| hashmap.insert(edge.id(), edge).is_some())
    }

    /// Cuts a face with only one boundary by an edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// let (face0, face1) = face.cut_by_edge(Edge::new(&v[1], &v[3], ())).unwrap();
    ///
    /// // The front vertex of face0's boundary becomes the back of cutting edge.
    /// let v0: Vec<Vertex<()>> = face0.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v0, vec![v[3].clone(), v[0].clone(), v[1].clone()]);
    ///
    /// let v1: Vec<Vertex<()>> = face1.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v1, vec![v[1].clone(), v[2].clone(), v[3].clone()]);
    /// ```
    /// # Failures
    /// Returns `None` if:
    /// - `self` has several boundaries, or
    /// - `self` does not include vertices of the end vertices of `edge`.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[2], ())).is_none());
    /// ```
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[4], ())).is_none());
    pub fn cut_by_edge(&self, edge: Edge<P, C>) -> Option<(Self, Self)>
    where S: Clone {
        if self.boundaries.len() != 1 {
            return None;
        }
        let mut face0 = Face {
            boundaries: self.boundaries.clone(),
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        let wire = &mut face0.boundaries[0];
        let i = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.front() == edge.back())
            .map(|(i, _)| i)?;
        let j = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.back() == edge.front())
            .map(|(i, _)| i)?;
        wire.rotate_left(i);
        let j = (j + wire.len() - i) % wire.len();
        let mut new_wire = wire.split_off(j + 1);
        wire.push_back(edge.clone());
        new_wire.push_back(edge.inverse());
        debug_assert!(Face::try_new(self.boundaries.clone(), ()).is_ok());
        debug_assert!(Face::try_new(vec![new_wire.clone()], ()).is_ok());
        let face1 = Face {
            boundaries: vec![new_wire],
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        Some((face0, face1))
    }

    /// Glue two faces at boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 8]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    ///     Edge::new(&v[6], &v[2], ()),
    ///     Edge::new(&v[1], &v[6], ()),
    ///     Edge::new(&v[7], &v[5], ()),
    ///     Edge::new(&v[4], &v[7], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let wire2 = Wire::from(vec![
    ///     edge[6].clone(),
    ///     edge[1].inverse(),
    ///     edge[7].clone(),
    /// ]);
    /// let wire3 = Wire::from(vec![
    ///     edge[8].clone(),
    ///     edge[4].inverse(),
    ///     edge[9].clone(),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], ());
    /// let face1 = Face::new(vec![wire2, wire3], ());
    /// let face = face0.glue_at_boundaries(&face1).unwrap();
    /// let boundaries = face.boundary_iters();
    /// assert_eq!(boundaries.len(), 2);
    /// assert_eq!(boundaries[0].len(), 4);
    /// assert_eq!(boundaries[1].len(), 4);
    /// ```
    pub fn glue_at_boundaries(&self, other: &Self) -> Option<Self>
    where
        S: Clone + PartialEq,
        Wire<P, C>: Debug, {
        let surface = self.get_surface();
        if surface != other.get_surface() || self.orientation() != other.orientation() {
            return None;
        }
        let mut vemap: HashMap<VertexID<P>, &Edge<P, C>> = self
            .absolute_boundaries()
            .iter()
            .flatten()
            .map(|edge| (edge.front().id(), edge))
            .collect();
        other
            .absolute_boundaries()
            .iter()
            .flatten()
            .try_for_each(|edge| {
                if let Some(edge0) = vemap.get(&edge.back().id()) {
                    if edge.front() == edge0.back() {
                        if edge.is_same(edge0) {
                            vemap.remove(&edge.back().id());
                            return Some(());
                        } else {
                            return None;
                        }
                    }
                }
                vemap.insert(edge.front().id(), edge);
                Some(())
            })?;
        if vemap.is_empty() {
            return None;
        }
        let mut boundaries = Vec::new();
        while !vemap.is_empty() {
            let mut wire = Wire::new();
            let v = *vemap.iter().next().unwrap().0;
            let mut edge = vemap.remove(&v).unwrap();
            wire.push_back(edge.clone());
            while let Some(edge0) = vemap.remove(&edge.back().id()) {
                wire.push_back(edge0.clone());
                edge = edge0;
            }
            boundaries.push(wire);
        }
        debug_assert!(Face::try_new(boundaries.clone(), ()).is_ok());
        Some(Face {
            boundaries,
            orientation: self.orientation(),
            surface: Arc::new(Mutex::new(surface)),
        })
    }
More examples
Hide additional examples
src/compress.rs (line 73)
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    fn create_face<P, C>(self, edges: &[Edge<P, C>]) -> Result<Face<P, C, S>> {
        let wires: Vec<Wire<P, C>> = self
            .boundaries
            .into_iter()
            .map(|wire| {
                wire.into_iter()
                    .map(
                        |CompressedEdgeIndex { index, orientation }| match orientation {
                            true => edges[index].clone(),
                            false => edges[index].inverse(),
                        },
                    )
                    .collect()
            })
            .collect();
        let mut face = Face::try_new(wires, self.surface)?;
        if !self.orientation {
            face.invert();
        }
        Ok(face)
    }

Creates a new face by a wire.

Panic

All wires in boundaries must be non-empty, simple and closed.

Examples found in repository?
src/face.rs (line 77)
75
76
77
78
79
80
    pub fn debug_new(boundaries: Vec<Wire<P, C>>, surface: S) -> Face<P, C, S> {
        match cfg!(debug_assertions) {
            true => Face::new(boundaries, surface),
            false => Face::new_unchecked(boundaries, surface),
        }
    }

Creates a new face by a wire.

Remarks

This method is prepared only for performance-critical development and is not recommended.
This method does NOT check the regularity conditions of Face::try_new().
The programmer must guarantee this condition before using this method.

Examples found in repository?
src/face.rs (line 44)
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
    pub fn try_new(boundaries: Vec<Wire<P, C>>, surface: S) -> Result<Face<P, C, S>> {
        for wire in &boundaries {
            if wire.is_empty() {
                return Err(Error::EmptyWire);
            } else if !wire.is_closed() {
                return Err(Error::NotClosedWire);
            } else if !wire.is_simple() {
                return Err(Error::NotSimpleWire);
            }
        }
        if !Wire::disjoint_wires(&boundaries) {
            Err(Error::NotSimpleWire)
        } else {
            Ok(Face::new_unchecked(boundaries, surface))
        }
    }

    /// Creates a new face by a wire.
    /// # Panic
    /// All wires in `boundaries` must be non-empty, simple and closed.
    #[inline(always)]
    pub fn new(boundaries: Vec<Wire<P, C>>, surface: S) -> Face<P, C, S> {
        Face::try_new(boundaries, surface).remove_try()
    }

    /// Creates a new face by a wire.
    /// # Remarks
    /// This method is prepared only for performance-critical development and is not recommended.  
    /// This method does NOT check the regularity conditions of `Face::try_new()`.  
    /// The programmer must guarantee this condition before using this method.
    #[inline(always)]
    pub fn new_unchecked(boundaries: Vec<Wire<P, C>>, surface: S) -> Face<P, C, S> {
        Face {
            boundaries,
            orientation: true,
            surface: Arc::new(Mutex::new(surface)),
        }
    }

    /// Creates a new face by a wire.
    /// # Remarks
    /// This method check the regularity conditions of `Face::try_new()` in the debug mode.  
    /// The programmer must guarantee this condition before using this method.
    #[inline(always)]
    pub fn debug_new(boundaries: Vec<Wire<P, C>>, surface: S) -> Face<P, C, S> {
        match cfg!(debug_assertions) {
            true => Face::new(boundaries, surface),
            false => Face::new_unchecked(boundaries, surface),
        }
    }

Creates a new face by a wire.

Remarks

This method check the regularity conditions of Face::try_new() in the debug mode.
The programmer must guarantee this condition before using this method.

Examples found in repository?
src/face.rs (line 421)
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
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }
More examples
Hide additional examples
src/shell.rs (line 483)
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
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Shell<Q, D, T>> {
        let mut vertex_map = EntryMap::new(Vertex::id, move |v| v.try_mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_try_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_try_mapped(&mut edge_map))
                    .collect::<Option<Vec<_>>>()?;
                let surface = surface_mapping(&*face.surface.lock().unwrap())?;
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                Some(new_face)
            })
            .collect()
    }

    /// Returns a new shell whose surfaces are mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 7,
    ///     &move |j: &usize| *j + 700,
    ///     &move |k: &usize| *k + 10000,
    /// );
    /// let shell0 = Shell::from(vec![face0, face1.inverse()]);
    /// let shell1 = shell0.mapped(
    ///     &move |i: &usize| *i + 50,
    ///     &move |j: &usize| *j + 5000,
    ///     &move |k: &usize| *k + 500000,
    /// );
    /// # for face in shell1.face_iter() {
    /// #    for bdry in face.absolute_boundaries() {
    /// #        assert!(bdry.is_closed());
    /// #        assert!(bdry.is_simple());
    /// #    }
    /// # }
    ///
    /// for (face0, face1) in shell0.face_iter().zip(shell1.face_iter()) {
    ///     assert_eq!(
    ///         face0.get_surface() + 500000,
    ///         face1.get_surface(),
    ///     );
    ///     assert_eq!(face0.orientation(), face1.orientation());
    ///     let biters0 = face0.boundary_iters();
    ///     let biters1 = face1.boundary_iters();
    ///     for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///         for (edge0, edge1) in biter0.zip(biter1) {
    ///             assert_eq!(
    ///                 edge0.front().get_point() + 50,
    ///                 edge1.front().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.back().get_point() + 50,
    ///                 edge1.back().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.get_curve() + 5000,
    ///                 edge1.get_curve(),
    ///             );
    ///         }
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Shell<Q, D, T> {
        let mut vertex_map = EntryMap::new(Vertex::id, |v| v.mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires: Vec<Wire<_, _>> = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_mapped(&mut edge_map))
                    .collect();
                let surface = surface_mapping(&*face.surface.lock().unwrap());
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                new_face
            })
            .collect()
    }

Returns the boundaries of the face.

Examples
use truck_topology::*;
let v = Vertex::news(&[(); 3]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);
let mut face = Face::new(vec![wire], ());
let boundaries = face.boundaries();
for (i, vert) in boundaries[0].vertex_iter().enumerate() {
    assert_eq!(vert, v[i]);
}

// If invert the face, the boundaries is also inverted.
face.invert();
assert_eq!(boundaries[0].inverse(), face.boundaries()[0]);
Examples found in repository?
src/face.rs (line 133)
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
    pub fn into_boundaries(self) -> Vec<Wire<P, C>> {
        match self.orientation {
            true => self.boundaries,
            false => self.boundaries(),
        }
    }

    /// Returns the reference of the boundaries wire which is generated by constructor.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let boundaries = face.boundaries();
    /// face.invert();
    ///
    /// // The result of face.boundary() is already inversed.
    /// assert_eq!(face.boundaries()[0], boundaries[0].inverse());
    ///
    /// // The absolute boundaries does never change.
    /// assert_eq!(face.absolute_boundaries(), &boundaries);
    /// ```
    #[inline(always)]
    pub const fn absolute_boundaries(&self) -> &Vec<Wire<P, C>> { &self.boundaries }

    /// Returns a clone of the face without inversion.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// let face2 = face1.absolute_clone();
    /// assert_eq!(face0, face2);
    /// assert_ne!(face1, face2);
    /// assert!(face1.is_same(&face2));
    /// ```
    #[inline(always)]
    pub fn absolute_clone(&self) -> Self {
        Self {
            boundaries: self.boundaries.clone(),
            surface: Arc::clone(&self.surface),
            orientation: true,
        }
    }

    /// Returns an iterator over all edges in the boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// face.invert();
    /// let boundaries = face.boundaries().clone();
    /// let edge_iter0 = boundaries.iter().flat_map(Wire::edge_iter);
    /// let edge_iter1 = face.boundary_iters().into_iter().flatten();
    /// for (edge0, edge1) in edge_iter0.zip(edge_iter1) {
    ///     assert_eq!(edge0, &edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn boundary_iters(&self) -> Vec<BoundaryIter<'_, P, C>> {
        self.boundaries
            .iter()
            .map(|wire| BoundaryIter {
                edge_iter: wire.edge_iter(),
                orientation: self.orientation,
            })
            .collect()
    }

    #[inline(always)]
    fn renew_pointer(&mut self)
    where S: Clone {
        let surface = self.get_surface();
        self.surface = Arc::new(Mutex::new(surface));
    }

    /// Returns an iterator over the edges.
    #[inline(always)]
    pub fn edge_iter(&self) -> impl Iterator<Item = Edge<P, C>> + '_ {
        self.boundary_iters().into_iter().flatten()
    }

    /// Returns an iterator over the vertices.
    #[inline(always)]
    pub fn vertex_iter(&self) -> impl Iterator<Item = Vertex<P>> + '_ {
        self.edge_iter().map(|e| e.front().clone())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.try_add_boundary(wire1.clone()).unwrap();
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.try_add_boundary(wire1.clone()).unwrap();
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.try_add_boundary(wire1).unwrap();
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn try_add_boundary(&mut self, mut wire: Wire<P, C>) -> Result<()>
    where S: Clone {
        if wire.is_empty() {
            return Err(Error::EmptyWire);
        } else if !wire.is_closed() {
            return Err(Error::NotClosedWire);
        } else if !wire.is_simple() {
            return Err(Error::NotSimpleWire);
        }
        if !self.orientation {
            wire.invert();
        }
        self.boundaries.push(wire);
        self.renew_pointer();
        if !Wire::disjoint_wires(&self.boundaries) {
            self.boundaries.pop();
            return Err(Error::NotDisjointWires);
        }
        Ok(())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.add_boundary(wire1.clone());
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.add_boundary(wire1.clone());
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.add_boundary(wire1);
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn add_boundary(&mut self, wire: Wire<P, C>)
    where S: Clone {
        self.try_add_boundary(wire).remove_try()
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }

    /// Returns the orientation of face.
    ///
    /// The result of this method is the same with `self.boundaries() == self.absolute_boundaries().clone()`.
    /// Moreover, if this method returns false, `self.boundaries() == self.absolute_boundaries().inverse()`.
    #[inline(always)]
    pub fn orientation(&self) -> bool { self.orientation }

    /// Returns the clone of surface of face.
    #[inline(always)]
    pub fn get_surface(&self) -> S
    where S: Clone {
        self.surface.lock().unwrap().clone()
    }

    /// Sets the surface of face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], 0);
    /// let face1 = face0.clone();
    ///
    /// // Two faces have the same content.
    /// assert_eq!(face0.get_surface(), 0);
    /// assert_eq!(face1.get_surface(), 0);
    ///
    /// // Set surface
    /// face0.set_surface(1);
    ///
    /// // The contents of two vertices are synchronized.
    /// assert_eq!(face0.get_surface(), 1);
    /// assert_eq!(face1.get_surface(), 1);
    /// ```
    #[inline(always)]
    pub fn set_surface(&self, surface: S) { *self.surface.lock().unwrap() = surface; }

    /// Inverts the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let org_face = face.clone();
    /// let org_bdry = face.boundaries();
    /// face.invert();
    ///
    /// // Two faces are the same face.
    /// face.is_same(&org_face);
    ///
    /// // The boundaries is inverted.
    /// let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut face.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn invert(&mut self) -> &mut Self {
        self.orientation = !self.orientation;
        self
    }

    /// Returns whether two faces are the same. Returns `true` even if the orientaions are different.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// assert_ne!(face0, face1);
    /// assert!(face0.is_same(&face1));
    /// ```
    #[inline(always)]
    pub fn is_same(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
    }

    /// Returns the id that does not depend on the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// let face1 = face0.inverse();
    /// let face2 = Face::new(vec![wire], ());
    /// assert_ne!(face0, face1);
    /// assert_ne!(face0, face2);
    /// assert_eq!(face0.id(), face1.id());
    /// assert_ne!(face0.id(), face2.id());
    /// ```
    #[inline(always)]
    pub fn id(&self) -> FaceID<S> { ID::new(Arc::as_ptr(&self.surface)) }

    /// Returns how many same faces.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    ///
    /// // Create one face
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Create another face, independent from face0
    /// let face1 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Clone face0, the result will be 2.
    /// let face2 = face0.clone();
    /// assert_eq!(face0.count(), 2);
    /// assert_eq!(face2.count(), 2);
    /// // drop face2, the result will be 1.
    /// drop(face2);
    /// assert_eq!(face0.count(), 1);
    /// ```
    #[inline(always)]
    pub fn count(&self) -> usize { Arc::strong_count(&self.surface) }

    /// Returns the inverse face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let inverted = face.inverse();
    ///
    /// // Two faces are the same face.
    /// assert!(face.is_same(&inverted));
    ///
    /// // Two faces has the same id.
    /// assert_eq!(face.id(), inverted.id());
    ///
    /// // The boundaries is inverted.
    /// let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut inverted.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn inverse(&self) -> Face<P, C, S> {
        let mut face = self.clone();
        face.invert();
        face
    }

    /// Returns whether two faces `self` and `other` have a shared edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 4]);
    /// let shared_edge = Edge::new(&v[0], &v[1], ());
    /// let another_edge = Edge::new(&v[0], &v[1], ());
    /// let inversed_edge = shared_edge.inverse();
    /// let wire = vec![
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &another_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[3], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[1], ()), &inversed_edge, &Edge::new(&v[0], &v[3], ())]),
    /// ];
    /// let face: Vec<_> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert!(face[0].border_on(&face[2]));
    /// assert!(!face[1].border_on(&face[2]));
    /// assert!(face[0].border_on(&face[3]));
    /// ```
    pub fn border_on(&self, other: &Face<P, C, S>) -> bool {
        let mut hashmap = HashMap::default();
        let edge_iter = self.boundary_iters().into_iter().flatten();
        edge_iter.for_each(|edge| {
            hashmap.insert(edge.id(), edge);
        });
        let mut edge_iter = other.boundary_iters().into_iter().flatten();
        edge_iter.any(|edge| hashmap.insert(edge.id(), edge).is_some())
    }

    /// Cuts a face with only one boundary by an edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// let (face0, face1) = face.cut_by_edge(Edge::new(&v[1], &v[3], ())).unwrap();
    ///
    /// // The front vertex of face0's boundary becomes the back of cutting edge.
    /// let v0: Vec<Vertex<()>> = face0.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v0, vec![v[3].clone(), v[0].clone(), v[1].clone()]);
    ///
    /// let v1: Vec<Vertex<()>> = face1.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v1, vec![v[1].clone(), v[2].clone(), v[3].clone()]);
    /// ```
    /// # Failures
    /// Returns `None` if:
    /// - `self` has several boundaries, or
    /// - `self` does not include vertices of the end vertices of `edge`.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[2], ())).is_none());
    /// ```
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[4], ())).is_none());
    pub fn cut_by_edge(&self, edge: Edge<P, C>) -> Option<(Self, Self)>
    where S: Clone {
        if self.boundaries.len() != 1 {
            return None;
        }
        let mut face0 = Face {
            boundaries: self.boundaries.clone(),
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        let wire = &mut face0.boundaries[0];
        let i = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.front() == edge.back())
            .map(|(i, _)| i)?;
        let j = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.back() == edge.front())
            .map(|(i, _)| i)?;
        wire.rotate_left(i);
        let j = (j + wire.len() - i) % wire.len();
        let mut new_wire = wire.split_off(j + 1);
        wire.push_back(edge.clone());
        new_wire.push_back(edge.inverse());
        debug_assert!(Face::try_new(self.boundaries.clone(), ()).is_ok());
        debug_assert!(Face::try_new(vec![new_wire.clone()], ()).is_ok());
        let face1 = Face {
            boundaries: vec![new_wire],
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        Some((face0, face1))
    }

    /// Glue two faces at boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 8]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    ///     Edge::new(&v[6], &v[2], ()),
    ///     Edge::new(&v[1], &v[6], ()),
    ///     Edge::new(&v[7], &v[5], ()),
    ///     Edge::new(&v[4], &v[7], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let wire2 = Wire::from(vec![
    ///     edge[6].clone(),
    ///     edge[1].inverse(),
    ///     edge[7].clone(),
    /// ]);
    /// let wire3 = Wire::from(vec![
    ///     edge[8].clone(),
    ///     edge[4].inverse(),
    ///     edge[9].clone(),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], ());
    /// let face1 = Face::new(vec![wire2, wire3], ());
    /// let face = face0.glue_at_boundaries(&face1).unwrap();
    /// let boundaries = face.boundary_iters();
    /// assert_eq!(boundaries.len(), 2);
    /// assert_eq!(boundaries[0].len(), 4);
    /// assert_eq!(boundaries[1].len(), 4);
    /// ```
    pub fn glue_at_boundaries(&self, other: &Self) -> Option<Self>
    where
        S: Clone + PartialEq,
        Wire<P, C>: Debug, {
        let surface = self.get_surface();
        if surface != other.get_surface() || self.orientation() != other.orientation() {
            return None;
        }
        let mut vemap: HashMap<VertexID<P>, &Edge<P, C>> = self
            .absolute_boundaries()
            .iter()
            .flatten()
            .map(|edge| (edge.front().id(), edge))
            .collect();
        other
            .absolute_boundaries()
            .iter()
            .flatten()
            .try_for_each(|edge| {
                if let Some(edge0) = vemap.get(&edge.back().id()) {
                    if edge.front() == edge0.back() {
                        if edge.is_same(edge0) {
                            vemap.remove(&edge.back().id());
                            return Some(());
                        } else {
                            return None;
                        }
                    }
                }
                vemap.insert(edge.front().id(), edge);
                Some(())
            })?;
        if vemap.is_empty() {
            return None;
        }
        let mut boundaries = Vec::new();
        while !vemap.is_empty() {
            let mut wire = Wire::new();
            let v = *vemap.iter().next().unwrap().0;
            let mut edge = vemap.remove(&v).unwrap();
            wire.push_back(edge.clone());
            while let Some(edge0) = vemap.remove(&edge.back().id()) {
                wire.push_back(edge0.clone());
                edge = edge0;
            }
            boundaries.push(wire);
        }
        debug_assert!(Face::try_new(boundaries.clone(), ()).is_ok());
        Some(Face {
            boundaries,
            orientation: self.orientation(),
            surface: Arc::new(Mutex::new(surface)),
        })
    }

    /// Creates display struct for debugging the face.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use FaceDisplayFormat as FDF;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], 120);
    ///
    /// let vertex_format = VertexDisplayFormat::AsPoint;
    /// let edge_format = EdgeDisplayFormat::VerticesTuple { vertex_format };
    /// let wire_format = WireDisplayFormat::EdgesList { edge_format };
    ///
    /// assert_eq!(
    ///     format!("{:?}", face.display(FDF::Full { wire_format })),
    ///     format!("Face {{ id: {:?}, boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]], entity: 120 }}", face.id()),
    /// );
    /// assert_eq!(
    ///     format!("{:?}", face.display(FDF::BoundariesAndID { wire_format })),
    ///     format!("Face {{ id: {:?}, boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]] }}", face.id()),
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::BoundariesAndSurface { wire_format })),
    ///     "Face { boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]], entity: 120 }",
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::LoopsListTuple { wire_format })),
    ///     "Face([[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]])",
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::LoopsList { wire_format })),
    ///     "[[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]]",
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::AsSurface)),
    ///     "120",
    /// );
    /// ```
    #[inline(always)]
    pub fn display(&self, format: FaceDisplayFormat) -> DebugDisplay<'_, Self, FaceDisplayFormat> {
        DebugDisplay {
            entity: self,
            format,
        }
    }
}

impl<P, C, S: Clone + Invertible> Face<P, C, S> {
    /// Returns the cloned surface in face.
    /// If face is inverted, then the returned surface is also inverted.
    #[inline(always)]
    pub fn oriented_surface(&self) -> S {
        match self.orientation {
            true => self.surface.lock().unwrap().clone(),
            false => self.surface.lock().unwrap().inverse(),
        }
    }
}

impl<P, C, S> Face<P, C, S>
where
    P: Tolerance,
    C: BoundedCurve<Point = P>,
    S: IncludeCurve<C>,
{
    /// Returns the consistence of the geometry of end vertices
    /// and the geometry of edge.
    #[inline(always)]
    pub fn is_geometric_consistent(&self) -> bool {
        let surface = &*self.surface.lock().unwrap();
        self.boundary_iters().into_iter().flatten().all(|edge| {
            let edge_consist = edge.is_geometric_consistent();
            let curve = &*edge.curve.lock().unwrap();
            let curve_consist = surface.include(curve);
            edge_consist && curve_consist
        })
    }
}

impl<P, C, S> Clone for Face<P, C, S> {
    #[inline(always)]
    fn clone(&self) -> Face<P, C, S> {
        Face {
            boundaries: self.boundaries.clone(),
            orientation: self.orientation,
            surface: Arc::clone(&self.surface),
        }
    }
}

impl<P, C, S> PartialEq for Face<P, C, S> {
    #[inline(always)]
    fn eq(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
            && self.orientation == other.orientation
    }
}

impl<P, C, S> Eq for Face<P, C, S> {}

impl<P, C, S> Hash for Face<P, C, S> {
    #[inline(always)]
    fn hash<H: Hasher>(&self, state: &mut H) {
        std::ptr::hash(Arc::as_ptr(&self.surface), state);
        self.orientation.hash(state);
    }
}

/// An iterator over the edges in the boundaries of a face.
/// # Examples
/// ```
/// use truck_topology::*;
/// let v = Vertex::news(&[(); 4]);
/// let wire = Wire::from(vec![
///     Edge::new(&v[0], &v[1], ()),
///     Edge::new(&v[1], &v[2], ()),
///     Edge::new(&v[2], &v[3], ()),
///     Edge::new(&v[3], &v[0], ()),
/// ]);
/// let face = Face::new(vec![wire.clone()], ());
///
/// let iter = &mut face.boundary_iters()[0];
/// assert_eq!(iter.next().as_ref(), Some(&wire[0]));
/// assert_eq!(iter.next_back().as_ref(), Some(&wire[3])); // double ended
/// assert_eq!(iter.next().as_ref(), Some(&wire[1]));
/// assert_eq!(iter.next().as_ref(), Some(&wire[2]));
/// assert_eq!(iter.next_back().as_ref(), None);
/// assert_eq!(iter.next().as_ref(), None); // fused
/// ```
#[derive(Clone, Debug)]
pub struct BoundaryIter<'a, P, C> {
    edge_iter: EdgeIter<'a, P, C>,
    orientation: bool,
}

impl<'a, P, C> Iterator for BoundaryIter<'a, P, C> {
    type Item = Edge<P, C>;
    #[inline(always)]
    fn next(&mut self) -> Option<Edge<P, C>> {
        match self.orientation {
            true => self.edge_iter.next().cloned(),
            false => self.edge_iter.next_back().map(|edge| edge.inverse()),
        }
    }

    #[inline(always)]
    fn size_hint(&self) -> (usize, Option<usize>) { (self.len(), Some(self.len())) }

    #[inline(always)]
    fn last(mut self) -> Option<Edge<P, C>> { self.next_back() }
}

impl<'a, P, C> DoubleEndedIterator for BoundaryIter<'a, P, C> {
    #[inline(always)]
    fn next_back(&mut self) -> Option<Edge<P, C>> {
        match self.orientation {
            true => self.edge_iter.next_back().cloned(),
            false => self.edge_iter.next().map(|edge| edge.inverse()),
        }
    }
}

impl<'a, P, C> ExactSizeIterator for BoundaryIter<'a, P, C> {
    #[inline(always)]
    fn len(&self) -> usize { self.edge_iter.len() }
}

impl<'a, P, C> std::iter::FusedIterator for BoundaryIter<'a, P, C> {}

impl<'a, P: Debug, C: Debug, S: Debug> Debug
    for DebugDisplay<'a, Face<P, C, S>, FaceDisplayFormat>
{
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self.format {
            FaceDisplayFormat::Full { wire_format } => f
                .debug_struct("Face")
                .field("id", &self.entity.id())
                .field(
                    "boundaries",
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .field("entity", &MutexFmt(&self.entity.surface))
                .finish(),
            FaceDisplayFormat::BoundariesAndID { wire_format } => f
                .debug_struct("Face")
                .field("id", &self.entity.id())
                .field(
                    "boundaries",
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .finish(),
            FaceDisplayFormat::BoundariesAndSurface { wire_format } => f
                .debug_struct("Face")
                .field(
                    "boundaries",
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .field("entity", &MutexFmt(&self.entity.surface))
                .finish(),
            FaceDisplayFormat::LoopsListTuple { wire_format } => f
                .debug_tuple("Face")
                .field(
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .finish(),
            FaceDisplayFormat::LoopsList { wire_format } => f
                .debug_list()
                .entries(
                    self.entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format)),
                )
                .finish(),
            FaceDisplayFormat::AsSurface => {
                f.write_fmt(format_args!("{:?}", &MutexFmt(&self.entity.surface)))
            }
        }
    }

Consumes self and returns the entity of its boundaries.

let v = Vertex::news(&[(), (), ()]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);
let mut face = Face::new(vec![wire], ());
let boundaries = face.clone().into_boundaries();
for (i, vert) in boundaries[0].vertex_iter().enumerate() {
    assert_eq!(vert, v[i]);
}

// If invert the face, the boundaries is also inverted.
face.invert();
assert_eq!(boundaries[0].inverse(), face.into_boundaries()[0]);

Returns the reference of the boundaries wire which is generated by constructor.

Examples
use truck_topology::*;
let v = Vertex::news(&[(), (), ()]);
let wire = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let mut face = Face::new(vec![wire], ());
let boundaries = face.boundaries();
face.invert();

// The result of face.boundary() is already inversed.
assert_eq!(face.boundaries()[0], boundaries[0].inverse());

// The absolute boundaries does never change.
assert_eq!(face.absolute_boundaries(), &boundaries);
Examples found in repository?
src/face.rs (line 416)
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }

    /// Returns the orientation of face.
    ///
    /// The result of this method is the same with `self.boundaries() == self.absolute_boundaries().clone()`.
    /// Moreover, if this method returns false, `self.boundaries() == self.absolute_boundaries().inverse()`.
    #[inline(always)]
    pub fn orientation(&self) -> bool { self.orientation }

    /// Returns the clone of surface of face.
    #[inline(always)]
    pub fn get_surface(&self) -> S
    where S: Clone {
        self.surface.lock().unwrap().clone()
    }

    /// Sets the surface of face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], 0);
    /// let face1 = face0.clone();
    ///
    /// // Two faces have the same content.
    /// assert_eq!(face0.get_surface(), 0);
    /// assert_eq!(face1.get_surface(), 0);
    ///
    /// // Set surface
    /// face0.set_surface(1);
    ///
    /// // The contents of two vertices are synchronized.
    /// assert_eq!(face0.get_surface(), 1);
    /// assert_eq!(face1.get_surface(), 1);
    /// ```
    #[inline(always)]
    pub fn set_surface(&self, surface: S) { *self.surface.lock().unwrap() = surface; }

    /// Inverts the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let org_face = face.clone();
    /// let org_bdry = face.boundaries();
    /// face.invert();
    ///
    /// // Two faces are the same face.
    /// face.is_same(&org_face);
    ///
    /// // The boundaries is inverted.
    /// let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut face.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn invert(&mut self) -> &mut Self {
        self.orientation = !self.orientation;
        self
    }

    /// Returns whether two faces are the same. Returns `true` even if the orientaions are different.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// assert_ne!(face0, face1);
    /// assert!(face0.is_same(&face1));
    /// ```
    #[inline(always)]
    pub fn is_same(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
    }

    /// Returns the id that does not depend on the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// let face1 = face0.inverse();
    /// let face2 = Face::new(vec![wire], ());
    /// assert_ne!(face0, face1);
    /// assert_ne!(face0, face2);
    /// assert_eq!(face0.id(), face1.id());
    /// assert_ne!(face0.id(), face2.id());
    /// ```
    #[inline(always)]
    pub fn id(&self) -> FaceID<S> { ID::new(Arc::as_ptr(&self.surface)) }

    /// Returns how many same faces.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    ///
    /// // Create one face
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Create another face, independent from face0
    /// let face1 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Clone face0, the result will be 2.
    /// let face2 = face0.clone();
    /// assert_eq!(face0.count(), 2);
    /// assert_eq!(face2.count(), 2);
    /// // drop face2, the result will be 1.
    /// drop(face2);
    /// assert_eq!(face0.count(), 1);
    /// ```
    #[inline(always)]
    pub fn count(&self) -> usize { Arc::strong_count(&self.surface) }

    /// Returns the inverse face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let inverted = face.inverse();
    ///
    /// // Two faces are the same face.
    /// assert!(face.is_same(&inverted));
    ///
    /// // Two faces has the same id.
    /// assert_eq!(face.id(), inverted.id());
    ///
    /// // The boundaries is inverted.
    /// let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut inverted.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn inverse(&self) -> Face<P, C, S> {
        let mut face = self.clone();
        face.invert();
        face
    }

    /// Returns whether two faces `self` and `other` have a shared edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 4]);
    /// let shared_edge = Edge::new(&v[0], &v[1], ());
    /// let another_edge = Edge::new(&v[0], &v[1], ());
    /// let inversed_edge = shared_edge.inverse();
    /// let wire = vec![
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &another_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[3], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[1], ()), &inversed_edge, &Edge::new(&v[0], &v[3], ())]),
    /// ];
    /// let face: Vec<_> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert!(face[0].border_on(&face[2]));
    /// assert!(!face[1].border_on(&face[2]));
    /// assert!(face[0].border_on(&face[3]));
    /// ```
    pub fn border_on(&self, other: &Face<P, C, S>) -> bool {
        let mut hashmap = HashMap::default();
        let edge_iter = self.boundary_iters().into_iter().flatten();
        edge_iter.for_each(|edge| {
            hashmap.insert(edge.id(), edge);
        });
        let mut edge_iter = other.boundary_iters().into_iter().flatten();
        edge_iter.any(|edge| hashmap.insert(edge.id(), edge).is_some())
    }

    /// Cuts a face with only one boundary by an edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// let (face0, face1) = face.cut_by_edge(Edge::new(&v[1], &v[3], ())).unwrap();
    ///
    /// // The front vertex of face0's boundary becomes the back of cutting edge.
    /// let v0: Vec<Vertex<()>> = face0.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v0, vec![v[3].clone(), v[0].clone(), v[1].clone()]);
    ///
    /// let v1: Vec<Vertex<()>> = face1.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v1, vec![v[1].clone(), v[2].clone(), v[3].clone()]);
    /// ```
    /// # Failures
    /// Returns `None` if:
    /// - `self` has several boundaries, or
    /// - `self` does not include vertices of the end vertices of `edge`.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[2], ())).is_none());
    /// ```
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[4], ())).is_none());
    pub fn cut_by_edge(&self, edge: Edge<P, C>) -> Option<(Self, Self)>
    where S: Clone {
        if self.boundaries.len() != 1 {
            return None;
        }
        let mut face0 = Face {
            boundaries: self.boundaries.clone(),
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        let wire = &mut face0.boundaries[0];
        let i = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.front() == edge.back())
            .map(|(i, _)| i)?;
        let j = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.back() == edge.front())
            .map(|(i, _)| i)?;
        wire.rotate_left(i);
        let j = (j + wire.len() - i) % wire.len();
        let mut new_wire = wire.split_off(j + 1);
        wire.push_back(edge.clone());
        new_wire.push_back(edge.inverse());
        debug_assert!(Face::try_new(self.boundaries.clone(), ()).is_ok());
        debug_assert!(Face::try_new(vec![new_wire.clone()], ()).is_ok());
        let face1 = Face {
            boundaries: vec![new_wire],
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        Some((face0, face1))
    }

    /// Glue two faces at boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 8]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    ///     Edge::new(&v[6], &v[2], ()),
    ///     Edge::new(&v[1], &v[6], ()),
    ///     Edge::new(&v[7], &v[5], ()),
    ///     Edge::new(&v[4], &v[7], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let wire2 = Wire::from(vec![
    ///     edge[6].clone(),
    ///     edge[1].inverse(),
    ///     edge[7].clone(),
    /// ]);
    /// let wire3 = Wire::from(vec![
    ///     edge[8].clone(),
    ///     edge[4].inverse(),
    ///     edge[9].clone(),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], ());
    /// let face1 = Face::new(vec![wire2, wire3], ());
    /// let face = face0.glue_at_boundaries(&face1).unwrap();
    /// let boundaries = face.boundary_iters();
    /// assert_eq!(boundaries.len(), 2);
    /// assert_eq!(boundaries[0].len(), 4);
    /// assert_eq!(boundaries[1].len(), 4);
    /// ```
    pub fn glue_at_boundaries(&self, other: &Self) -> Option<Self>
    where
        S: Clone + PartialEq,
        Wire<P, C>: Debug, {
        let surface = self.get_surface();
        if surface != other.get_surface() || self.orientation() != other.orientation() {
            return None;
        }
        let mut vemap: HashMap<VertexID<P>, &Edge<P, C>> = self
            .absolute_boundaries()
            .iter()
            .flatten()
            .map(|edge| (edge.front().id(), edge))
            .collect();
        other
            .absolute_boundaries()
            .iter()
            .flatten()
            .try_for_each(|edge| {
                if let Some(edge0) = vemap.get(&edge.back().id()) {
                    if edge.front() == edge0.back() {
                        if edge.is_same(edge0) {
                            vemap.remove(&edge.back().id());
                            return Some(());
                        } else {
                            return None;
                        }
                    }
                }
                vemap.insert(edge.front().id(), edge);
                Some(())
            })?;
        if vemap.is_empty() {
            return None;
        }
        let mut boundaries = Vec::new();
        while !vemap.is_empty() {
            let mut wire = Wire::new();
            let v = *vemap.iter().next().unwrap().0;
            let mut edge = vemap.remove(&v).unwrap();
            wire.push_back(edge.clone());
            while let Some(edge0) = vemap.remove(&edge.back().id()) {
                wire.push_back(edge0.clone());
                edge = edge0;
            }
            boundaries.push(wire);
        }
        debug_assert!(Face::try_new(boundaries.clone(), ()).is_ok());
        Some(Face {
            boundaries,
            orientation: self.orientation(),
            surface: Arc::new(Mutex::new(surface)),
        })
    }
More examples
Hide additional examples
src/shell.rs (line 255)
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
    pub fn face_adjacency(&self) -> FaceAdjacencyMap<'_, P, C, S> {
        let mut adjacency = EntryMap::new(|x| x, |_| Vec::new());
        let mut edge_face_map = EntryMap::new(|x| x, |_| Vec::new());
        self.face_iter().for_each(|face| {
            face.absolute_boundaries()
                .iter()
                .flatten()
                .for_each(|edge| {
                    let vec = edge_face_map.entry_or_insert(edge.id());
                    adjacency.entry_or_insert(face).extend(vec.iter().copied());
                    vec.iter().for_each(|tmp| {
                        adjacency.entry_or_insert(*tmp).push(face);
                    });
                    vec.push(face);
                });
        });
        adjacency.into()
    }

    /// Returns whether the shell is connected or not.
    /// # Examples
    /// ```
    /// // The empty shell is connected.
    /// use truck_topology::*;
    /// assert!(Shell::<(), (), ()>::new().is_connected());
    /// ```
    /// ```
    /// // An example of a connected shell
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 4]);
    /// let shared_edge = Edge::new(&v[1], &v[2], ());
    /// let wire0 = Wire::from_iter(vec![
    ///     &Edge::new(&v[0], &v[1], ()),
    ///     &shared_edge,
    ///     &Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire0], ());
    /// let wire1 = Wire::from_iter(vec![
    ///     &Edge::new(&v[3], &v[1], ()),
    ///     &shared_edge,
    ///     &Edge::new(&v[2], &v[3], ()),
    /// ]);
    /// let face1 = Face::new(vec![wire1], ());
    /// let shell: Shell<_, _, _> = vec![face0, face1].into();
    /// assert!(shell.is_connected());
    /// ```
    /// ```
    /// // An example of a non-connected shell
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 6]);
    /// let wire0 = Wire::from_iter(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ())
    /// ]);
    /// let face0 = Face::new(vec![wire0], ());
    /// let wire1 = Wire::from_iter(vec![
    ///     &Edge::new(&v[3], &v[4], ()),
    ///     &Edge::new(&v[4], &v[5], ()),
    ///     &Edge::new(&v[5], &v[3], ())
    /// ]);
    /// let face1 = Face::new(vec![wire1], ());
    /// let shell: Shell<_, _, _> = vec![face0, face1].into();
    /// assert!(!shell.is_connected());
    /// ```
    pub fn is_connected(&self) -> bool {
        let mut adjacency = self.vertex_adjacency();
        // Connecting another boundary of the same face with an edge
        for face in self {
            for wire in face.boundaries.windows(2) {
                let v0 = wire[0].front_vertex().unwrap();
                let v1 = wire[1].front_vertex().unwrap();
                adjacency.get_mut(&v0.id()).unwrap().push(v1.id());
                adjacency.get_mut(&v1.id()).unwrap().push(v0.id());
            }
        }
        check_connectivity(&mut adjacency)
    }

    /// Returns a vector consisting of shells of each connected components.
    /// # Examples
    /// ```
    /// use truck_topology::Shell;
    /// // The empty shell has no connected component.
    /// assert!(Shell::<(), (), ()>::new().connected_components().is_empty());
    /// ```
    /// # Remarks
    /// Since this method uses the face adjacency matrix, multiple components
    /// are perhaps generated even if the shell is connected. In that case,
    /// there is a pair of faces such that share vertices but not edges.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 5]);
    /// let wire0 = Wire::from_iter(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from_iter(vec![
    ///     Edge::new(&v[0], &v[3], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[0], ()),
    /// ]);
    /// let shell = Shell::from(vec![
    ///     Face::new(vec![wire0], ()),
    ///     Face::new(vec![wire1], ()),
    /// ]);
    /// assert!(shell.is_connected());
    /// assert_eq!(shell.connected_components().len(), 2);
    /// ```
    pub fn connected_components(&self) -> Vec<Shell<P, C, S>> {
        let mut adjacency = self.face_adjacency();
        let components = create_components(&mut adjacency);
        components
            .into_iter()
            .map(|vec| vec.into_iter().cloned().collect())
            .collect()
    }

    /// Returns the vector of all singular vertices.
    ///
    /// Here, we say that a vertex is singular if, for a sufficiently small neighborhood U of
    /// the vertex, the set U - {the vertex} is not connected.
    ///
    /// A regular, oriented, or closed shell becomes a manifold if and only if the shell has
    /// no singular vertices.
    /// # Examples
    /// ```
    /// // A regular manifold: Mobius bundle
    /// use truck_topology::*;
    /// use truck_topology::shell::ShellCondition;
    ///
    /// let v = Vertex::news(&[(), (), (), ()]);
    /// let edge = [
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[1], &v[3], ()),
    ///     Edge::new(&v[3], &v[2], ()),
    ///     Edge::new(&v[0], &v[3], ()),
    /// ];
    /// let wire = vec![
    ///     Wire::from_iter(vec![&edge[0], &edge[3], &edge[4], &edge[2]]),
    ///     Wire::from_iter(vec![&edge[1], &edge[2], &edge[5], &edge[3].inverse()]),
    /// ];
    /// let shell: Shell<_, _, _> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert_eq!(shell.shell_condition(), ShellCondition::Regular);
    /// assert!(shell.singular_vertices().is_empty());
    /// ```
    /// ```
    /// // A closed and connected shell which has a singular vertex.
    /// use truck_topology::*;
    /// use truck_topology::shell::*;
    ///
    /// let v = Vertex::news(&[(); 7]);
    /// let edge = [
    ///     Edge::new(&v[0], &v[1], ()), // 0
    ///     Edge::new(&v[0], &v[2], ()), // 1
    ///     Edge::new(&v[0], &v[3], ()), // 2
    ///     Edge::new(&v[1], &v[2], ()), // 3
    ///     Edge::new(&v[2], &v[3], ()), // 4
    ///     Edge::new(&v[3], &v[1], ()), // 5
    ///     Edge::new(&v[0], &v[4], ()), // 6
    ///     Edge::new(&v[0], &v[5], ()), // 7
    ///     Edge::new(&v[0], &v[6], ()), // 8
    ///     Edge::new(&v[4], &v[5], ()), // 9
    ///     Edge::new(&v[5], &v[6], ()), // 10
    ///     Edge::new(&v[6], &v[4], ()), // 11
    /// ];
    /// let wire = vec![
    ///     Wire::from_iter(vec![&edge[0].inverse(), &edge[1], &edge[3].inverse()]),
    ///     Wire::from_iter(vec![&edge[1].inverse(), &edge[2], &edge[4].inverse()]),
    ///     Wire::from_iter(vec![&edge[2].inverse(), &edge[0], &edge[5].inverse()]),
    ///     Wire::from_iter(vec![&edge[3], &edge[4], &edge[5]]),
    ///     Wire::from_iter(vec![&edge[6].inverse(), &edge[7], &edge[9].inverse()]),
    ///     Wire::from_iter(vec![&edge[7].inverse(), &edge[8], &edge[10].inverse()]),
    ///     Wire::from_iter(vec![&edge[8].inverse(), &edge[6], &edge[11].inverse()]),
    ///     Wire::from_iter(vec![&edge[9], &edge[10], &edge[11]]),
    /// ];
    /// let shell: Shell<_, _, _> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert_eq!(shell.shell_condition(), ShellCondition::Closed);
    /// assert!(shell.is_connected());
    /// assert_eq!(shell.singular_vertices(), vec![v[0].clone()]);
    /// ```
    pub fn singular_vertices(&self) -> Vec<Vertex<P>> {
        let mut vert_wise_adjacency =
            EntryMap::new(Vertex::clone, |_| EntryMap::new(Edge::id, |_| Vec::new()));
        self.face_iter()
            .flat_map(Face::absolute_boundaries)
            .for_each(|wire| {
                let first_edge = &wire[0];
                let mut edge_iter = wire.iter().peekable();
                while let Some(edge) = edge_iter.next() {
                    let adjacency = vert_wise_adjacency.entry_or_insert(edge.back());
                    let next_edge = *edge_iter.peek().unwrap_or(&first_edge);
                    adjacency.entry_or_insert(edge).push(next_edge.id());
                    adjacency.entry_or_insert(next_edge).push(edge.id());
                }
            });
        vert_wise_adjacency
            .into_iter()
            .filter_map(|(vertex, adjacency)| {
                Some(vertex).filter(|_| !check_connectivity(&mut adjacency.into()))
            })
            .collect()
    }

    /// Returns a new shell whose surfaces are mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Shell<Q, D, T>> {
        let mut vertex_map = EntryMap::new(Vertex::id, move |v| v.try_mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_try_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_try_mapped(&mut edge_map))
                    .collect::<Option<Vec<_>>>()?;
                let surface = surface_mapping(&*face.surface.lock().unwrap())?;
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                Some(new_face)
            })
            .collect()
    }

    /// Returns a new shell whose surfaces are mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 7,
    ///     &move |j: &usize| *j + 700,
    ///     &move |k: &usize| *k + 10000,
    /// );
    /// let shell0 = Shell::from(vec![face0, face1.inverse()]);
    /// let shell1 = shell0.mapped(
    ///     &move |i: &usize| *i + 50,
    ///     &move |j: &usize| *j + 5000,
    ///     &move |k: &usize| *k + 500000,
    /// );
    /// # for face in shell1.face_iter() {
    /// #    for bdry in face.absolute_boundaries() {
    /// #        assert!(bdry.is_closed());
    /// #        assert!(bdry.is_simple());
    /// #    }
    /// # }
    ///
    /// for (face0, face1) in shell0.face_iter().zip(shell1.face_iter()) {
    ///     assert_eq!(
    ///         face0.get_surface() + 500000,
    ///         face1.get_surface(),
    ///     );
    ///     assert_eq!(face0.orientation(), face1.orientation());
    ///     let biters0 = face0.boundary_iters();
    ///     let biters1 = face1.boundary_iters();
    ///     for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///         for (edge0, edge1) in biter0.zip(biter1) {
    ///             assert_eq!(
    ///                 edge0.front().get_point() + 50,
    ///                 edge1.front().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.back().get_point() + 50,
    ///                 edge1.back().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.get_curve() + 5000,
    ///                 edge1.get_curve(),
    ///             );
    ///         }
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Shell<Q, D, T> {
        let mut vertex_map = EntryMap::new(Vertex::id, |v| v.mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires: Vec<Wire<_, _>> = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_mapped(&mut edge_map))
                    .collect();
                let surface = surface_mapping(&*face.surface.lock().unwrap());
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                new_face
            })
            .collect()
    }

Returns a clone of the face without inversion.

Examples
use truck_topology::*;
let v = Vertex::news(&[(), (), ()]);
let wire = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let face0 = Face::new(vec![wire], ());
let face1 = face0.inverse();
let face2 = face1.absolute_clone();
assert_eq!(face0, face2);
assert_ne!(face1, face2);
assert!(face1.is_same(&face2));

Returns an iterator over all edges in the boundaries.

Examples
use truck_topology::*;
let v = Vertex::news(&[(), (), ()]);
let wire = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let mut face = Face::new(vec![wire], ());
face.invert();
let boundaries = face.boundaries().clone();
let edge_iter0 = boundaries.iter().flat_map(Wire::edge_iter);
let edge_iter1 = face.boundary_iters().into_iter().flatten();
for (edge0, edge1) in edge_iter0.zip(edge_iter1) {
    assert_eq!(edge0, &edge1);
}
Examples found in repository?
src/face.rs (line 226)
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
    pub fn edge_iter(&self) -> impl Iterator<Item = Edge<P, C>> + '_ {
        self.boundary_iters().into_iter().flatten()
    }

    /// Returns an iterator over the vertices.
    #[inline(always)]
    pub fn vertex_iter(&self) -> impl Iterator<Item = Vertex<P>> + '_ {
        self.edge_iter().map(|e| e.front().clone())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.try_add_boundary(wire1.clone()).unwrap();
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.try_add_boundary(wire1.clone()).unwrap();
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.try_add_boundary(wire1).unwrap();
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn try_add_boundary(&mut self, mut wire: Wire<P, C>) -> Result<()>
    where S: Clone {
        if wire.is_empty() {
            return Err(Error::EmptyWire);
        } else if !wire.is_closed() {
            return Err(Error::NotClosedWire);
        } else if !wire.is_simple() {
            return Err(Error::NotSimpleWire);
        }
        if !self.orientation {
            wire.invert();
        }
        self.boundaries.push(wire);
        self.renew_pointer();
        if !Wire::disjoint_wires(&self.boundaries) {
            self.boundaries.pop();
            return Err(Error::NotDisjointWires);
        }
        Ok(())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.add_boundary(wire1.clone());
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.add_boundary(wire1.clone());
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.add_boundary(wire1);
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn add_boundary(&mut self, wire: Wire<P, C>)
    where S: Clone {
        self.try_add_boundary(wire).remove_try()
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }

    /// Returns the orientation of face.
    ///
    /// The result of this method is the same with `self.boundaries() == self.absolute_boundaries().clone()`.
    /// Moreover, if this method returns false, `self.boundaries() == self.absolute_boundaries().inverse()`.
    #[inline(always)]
    pub fn orientation(&self) -> bool { self.orientation }

    /// Returns the clone of surface of face.
    #[inline(always)]
    pub fn get_surface(&self) -> S
    where S: Clone {
        self.surface.lock().unwrap().clone()
    }

    /// Sets the surface of face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], 0);
    /// let face1 = face0.clone();
    ///
    /// // Two faces have the same content.
    /// assert_eq!(face0.get_surface(), 0);
    /// assert_eq!(face1.get_surface(), 0);
    ///
    /// // Set surface
    /// face0.set_surface(1);
    ///
    /// // The contents of two vertices are synchronized.
    /// assert_eq!(face0.get_surface(), 1);
    /// assert_eq!(face1.get_surface(), 1);
    /// ```
    #[inline(always)]
    pub fn set_surface(&self, surface: S) { *self.surface.lock().unwrap() = surface; }

    /// Inverts the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let org_face = face.clone();
    /// let org_bdry = face.boundaries();
    /// face.invert();
    ///
    /// // Two faces are the same face.
    /// face.is_same(&org_face);
    ///
    /// // The boundaries is inverted.
    /// let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut face.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn invert(&mut self) -> &mut Self {
        self.orientation = !self.orientation;
        self
    }

    /// Returns whether two faces are the same. Returns `true` even if the orientaions are different.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// assert_ne!(face0, face1);
    /// assert!(face0.is_same(&face1));
    /// ```
    #[inline(always)]
    pub fn is_same(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
    }

    /// Returns the id that does not depend on the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// let face1 = face0.inverse();
    /// let face2 = Face::new(vec![wire], ());
    /// assert_ne!(face0, face1);
    /// assert_ne!(face0, face2);
    /// assert_eq!(face0.id(), face1.id());
    /// assert_ne!(face0.id(), face2.id());
    /// ```
    #[inline(always)]
    pub fn id(&self) -> FaceID<S> { ID::new(Arc::as_ptr(&self.surface)) }

    /// Returns how many same faces.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    ///
    /// // Create one face
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Create another face, independent from face0
    /// let face1 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Clone face0, the result will be 2.
    /// let face2 = face0.clone();
    /// assert_eq!(face0.count(), 2);
    /// assert_eq!(face2.count(), 2);
    /// // drop face2, the result will be 1.
    /// drop(face2);
    /// assert_eq!(face0.count(), 1);
    /// ```
    #[inline(always)]
    pub fn count(&self) -> usize { Arc::strong_count(&self.surface) }

    /// Returns the inverse face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let inverted = face.inverse();
    ///
    /// // Two faces are the same face.
    /// assert!(face.is_same(&inverted));
    ///
    /// // Two faces has the same id.
    /// assert_eq!(face.id(), inverted.id());
    ///
    /// // The boundaries is inverted.
    /// let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut inverted.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn inverse(&self) -> Face<P, C, S> {
        let mut face = self.clone();
        face.invert();
        face
    }

    /// Returns whether two faces `self` and `other` have a shared edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 4]);
    /// let shared_edge = Edge::new(&v[0], &v[1], ());
    /// let another_edge = Edge::new(&v[0], &v[1], ());
    /// let inversed_edge = shared_edge.inverse();
    /// let wire = vec![
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &another_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[3], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[1], ()), &inversed_edge, &Edge::new(&v[0], &v[3], ())]),
    /// ];
    /// let face: Vec<_> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert!(face[0].border_on(&face[2]));
    /// assert!(!face[1].border_on(&face[2]));
    /// assert!(face[0].border_on(&face[3]));
    /// ```
    pub fn border_on(&self, other: &Face<P, C, S>) -> bool {
        let mut hashmap = HashMap::default();
        let edge_iter = self.boundary_iters().into_iter().flatten();
        edge_iter.for_each(|edge| {
            hashmap.insert(edge.id(), edge);
        });
        let mut edge_iter = other.boundary_iters().into_iter().flatten();
        edge_iter.any(|edge| hashmap.insert(edge.id(), edge).is_some())
    }

    /// Cuts a face with only one boundary by an edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// let (face0, face1) = face.cut_by_edge(Edge::new(&v[1], &v[3], ())).unwrap();
    ///
    /// // The front vertex of face0's boundary becomes the back of cutting edge.
    /// let v0: Vec<Vertex<()>> = face0.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v0, vec![v[3].clone(), v[0].clone(), v[1].clone()]);
    ///
    /// let v1: Vec<Vertex<()>> = face1.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v1, vec![v[1].clone(), v[2].clone(), v[3].clone()]);
    /// ```
    /// # Failures
    /// Returns `None` if:
    /// - `self` has several boundaries, or
    /// - `self` does not include vertices of the end vertices of `edge`.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[2], ())).is_none());
    /// ```
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[4], ())).is_none());
    pub fn cut_by_edge(&self, edge: Edge<P, C>) -> Option<(Self, Self)>
    where S: Clone {
        if self.boundaries.len() != 1 {
            return None;
        }
        let mut face0 = Face {
            boundaries: self.boundaries.clone(),
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        let wire = &mut face0.boundaries[0];
        let i = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.front() == edge.back())
            .map(|(i, _)| i)?;
        let j = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.back() == edge.front())
            .map(|(i, _)| i)?;
        wire.rotate_left(i);
        let j = (j + wire.len() - i) % wire.len();
        let mut new_wire = wire.split_off(j + 1);
        wire.push_back(edge.clone());
        new_wire.push_back(edge.inverse());
        debug_assert!(Face::try_new(self.boundaries.clone(), ()).is_ok());
        debug_assert!(Face::try_new(vec![new_wire.clone()], ()).is_ok());
        let face1 = Face {
            boundaries: vec![new_wire],
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        Some((face0, face1))
    }

    /// Glue two faces at boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 8]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    ///     Edge::new(&v[6], &v[2], ()),
    ///     Edge::new(&v[1], &v[6], ()),
    ///     Edge::new(&v[7], &v[5], ()),
    ///     Edge::new(&v[4], &v[7], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let wire2 = Wire::from(vec![
    ///     edge[6].clone(),
    ///     edge[1].inverse(),
    ///     edge[7].clone(),
    /// ]);
    /// let wire3 = Wire::from(vec![
    ///     edge[8].clone(),
    ///     edge[4].inverse(),
    ///     edge[9].clone(),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], ());
    /// let face1 = Face::new(vec![wire2, wire3], ());
    /// let face = face0.glue_at_boundaries(&face1).unwrap();
    /// let boundaries = face.boundary_iters();
    /// assert_eq!(boundaries.len(), 2);
    /// assert_eq!(boundaries[0].len(), 4);
    /// assert_eq!(boundaries[1].len(), 4);
    /// ```
    pub fn glue_at_boundaries(&self, other: &Self) -> Option<Self>
    where
        S: Clone + PartialEq,
        Wire<P, C>: Debug, {
        let surface = self.get_surface();
        if surface != other.get_surface() || self.orientation() != other.orientation() {
            return None;
        }
        let mut vemap: HashMap<VertexID<P>, &Edge<P, C>> = self
            .absolute_boundaries()
            .iter()
            .flatten()
            .map(|edge| (edge.front().id(), edge))
            .collect();
        other
            .absolute_boundaries()
            .iter()
            .flatten()
            .try_for_each(|edge| {
                if let Some(edge0) = vemap.get(&edge.back().id()) {
                    if edge.front() == edge0.back() {
                        if edge.is_same(edge0) {
                            vemap.remove(&edge.back().id());
                            return Some(());
                        } else {
                            return None;
                        }
                    }
                }
                vemap.insert(edge.front().id(), edge);
                Some(())
            })?;
        if vemap.is_empty() {
            return None;
        }
        let mut boundaries = Vec::new();
        while !vemap.is_empty() {
            let mut wire = Wire::new();
            let v = *vemap.iter().next().unwrap().0;
            let mut edge = vemap.remove(&v).unwrap();
            wire.push_back(edge.clone());
            while let Some(edge0) = vemap.remove(&edge.back().id()) {
                wire.push_back(edge0.clone());
                edge = edge0;
            }
            boundaries.push(wire);
        }
        debug_assert!(Face::try_new(boundaries.clone(), ()).is_ok());
        Some(Face {
            boundaries,
            orientation: self.orientation(),
            surface: Arc::new(Mutex::new(surface)),
        })
    }

    /// Creates display struct for debugging the face.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use FaceDisplayFormat as FDF;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], 120);
    ///
    /// let vertex_format = VertexDisplayFormat::AsPoint;
    /// let edge_format = EdgeDisplayFormat::VerticesTuple { vertex_format };
    /// let wire_format = WireDisplayFormat::EdgesList { edge_format };
    ///
    /// assert_eq!(
    ///     format!("{:?}", face.display(FDF::Full { wire_format })),
    ///     format!("Face {{ id: {:?}, boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]], entity: 120 }}", face.id()),
    /// );
    /// assert_eq!(
    ///     format!("{:?}", face.display(FDF::BoundariesAndID { wire_format })),
    ///     format!("Face {{ id: {:?}, boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]] }}", face.id()),
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::BoundariesAndSurface { wire_format })),
    ///     "Face { boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]], entity: 120 }",
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::LoopsListTuple { wire_format })),
    ///     "Face([[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]])",
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::LoopsList { wire_format })),
    ///     "[[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]]",
    /// );
    /// assert_eq!(
    ///     &format!("{:?}", face.display(FDF::AsSurface)),
    ///     "120",
    /// );
    /// ```
    #[inline(always)]
    pub fn display(&self, format: FaceDisplayFormat) -> DebugDisplay<'_, Self, FaceDisplayFormat> {
        DebugDisplay {
            entity: self,
            format,
        }
    }
}

impl<P, C, S: Clone + Invertible> Face<P, C, S> {
    /// Returns the cloned surface in face.
    /// If face is inverted, then the returned surface is also inverted.
    #[inline(always)]
    pub fn oriented_surface(&self) -> S {
        match self.orientation {
            true => self.surface.lock().unwrap().clone(),
            false => self.surface.lock().unwrap().inverse(),
        }
    }
}

impl<P, C, S> Face<P, C, S>
where
    P: Tolerance,
    C: BoundedCurve<Point = P>,
    S: IncludeCurve<C>,
{
    /// Returns the consistence of the geometry of end vertices
    /// and the geometry of edge.
    #[inline(always)]
    pub fn is_geometric_consistent(&self) -> bool {
        let surface = &*self.surface.lock().unwrap();
        self.boundary_iters().into_iter().flatten().all(|edge| {
            let edge_consist = edge.is_geometric_consistent();
            let curve = &*edge.curve.lock().unwrap();
            let curve_consist = surface.include(curve);
            edge_consist && curve_consist
        })
    }
More examples
Hide additional examples
src/compress.rs (line 274)
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
fn same_topology<P, C, S, Q, D, T>(one: &Shell<P, C, S>, other: &Shell<Q, D, T>) -> bool {
    let mut vmap = HashMap::<VertexID<P>, VertexID<Q>>::default();
    let mut emap = HashMap::<EdgeID<C>, EdgeID<D>>::default();
    if one.len() != other.len() {
        return false;
    }
    for (face0, face1) in one.iter().zip(other.iter()) {
        let biters0 = face0.boundary_iters();
        let biters1 = face1.boundary_iters();
        if biters0.len() != biters1.len() {
            return false;
        }
        for (biter0, biter1) in biters0.into_iter().zip(biters1) {
            if biter0.len() != biter1.len() {
                return false;
            }
            for (edge0, edge1) in biter0.zip(biter1) {
                if !emap_subroutin(&edge0, &edge1, &mut vmap, &mut emap) {
                    return false;
                }
            }
        }
    }
    true
}

Returns an iterator over the edges.

Examples found in repository?
src/face.rs (line 232)
231
232
233
    pub fn vertex_iter(&self) -> impl Iterator<Item = Vertex<P>> + '_ {
        self.edge_iter().map(|e| e.front().clone())
    }

Returns an iterator over the vertices.

Adds a boundary to the face.

Examples
use truck_topology::*;
let v = Vertex::news(&[(), (), (), (), (), ()]);
let wire0 = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let wire1 = Wire::from(vec![
     Edge::new(&v[3], &v[4], ()),
     Edge::new(&v[4], &v[5], ()),
     Edge::new(&v[5], &v[3], ()),
]);
let mut face0 = Face::new(vec![wire0.clone()], ());
face0.try_add_boundary(wire1.clone()).unwrap();
let face1 = Face::new(vec![wire0, wire1], ());
assert_eq!(face0.boundaries(), face1.boundaries());
Remarks
  1. If the face is inverted, then the added wire is inverted as absolute boundary.
use truck_topology::*;
let v = Vertex::news(&[(), (), (), (), (), ()]);
let wire0 = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let wire1 = Wire::from(vec![
     Edge::new(&v[3], &v[4], ()),
     Edge::new(&v[5], &v[4], ()).inverse(),
     Edge::new(&v[5], &v[3], ()),
]);
let mut face = Face::new(vec![wire0], ());
face.invert();
face.try_add_boundary(wire1.clone()).unwrap();

// The boundary is added in compatible with the face orientation.
assert_eq!(face.boundaries()[1], wire1);

// The absolute boundary is inverted!
let iter0 = face.absolute_boundaries()[1].edge_iter();
let iter1 = wire1.edge_iter().rev();
for (edge0, edge1) in iter0.zip(iter1) {
    assert_eq!(edge0.id(), edge1.id());
    assert_eq!(edge0.orientation(), !edge1.orientation());
}
  1. This method renew the face id.
use truck_topology::*;
let v = Vertex::news(&[(), (), (), (), (), ()]);
let wire0 = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let wire1 = Wire::from(vec![
     Edge::new(&v[3], &v[4], ()),
     Edge::new(&v[5], &v[4], ()).inverse(),
     Edge::new(&v[5], &v[3], ()),
]);
let mut face0 = Face::new(vec![wire0], ());
let face1 = face0.clone();
assert_eq!(face0.id(), face1.id());
face0.try_add_boundary(wire1).unwrap();
assert_ne!(face0.id(), face1.id());
Examples found in repository?
src/face.rs (line 400)
398
399
400
401
    pub fn add_boundary(&mut self, wire: Wire<P, C>)
    where S: Clone {
        self.try_add_boundary(wire).remove_try()
    }

Adds a boundary to the face.

Examples
use truck_topology::*;
let v = Vertex::news(&[(), (), (), (), (), ()]);
let wire0 = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let wire1 = Wire::from(vec![
     Edge::new(&v[3], &v[4], ()),
     Edge::new(&v[4], &v[5], ()),
     Edge::new(&v[5], &v[3], ()),
]);
let mut face0 = Face::new(vec![wire0.clone()], ());
face0.add_boundary(wire1.clone());
let face1 = Face::new(vec![wire0, wire1], ());
assert_eq!(face0.boundaries(), face1.boundaries());
Remarks
  1. If the face is inverted, then the added wire is inverted as absolute boundary.
use truck_topology::*;
let v = Vertex::news(&[(), (), (), (), (), ()]);
let wire0 = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let wire1 = Wire::from(vec![
     Edge::new(&v[3], &v[4], ()),
     Edge::new(&v[5], &v[4], ()).inverse(),
     Edge::new(&v[5], &v[3], ()),
]);
let mut face = Face::new(vec![wire0], ());
face.invert();
face.add_boundary(wire1.clone());

// The boundary is added in compatible with the face orientation.
assert_eq!(face.boundaries()[1], wire1);

// The absolute boundary is inverted!
let iter0 = face.absolute_boundaries()[1].edge_iter();
let iter1 = wire1.edge_iter().rev();
for (edge0, edge1) in iter0.zip(iter1) {
    assert_eq!(edge0.id(), edge1.id());
    assert_eq!(edge0.orientation(), !edge1.orientation());
}
  1. This method renew the face id.
use truck_topology::*;
let v = Vertex::news(&[(), (), (), (), (), ()]);
let wire0 = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let wire1 = Wire::from(vec![
     Edge::new(&v[3], &v[4], ()),
     Edge::new(&v[5], &v[4], ()).inverse(),
     Edge::new(&v[5], &v[3], ()),
]);
let mut face0 = Face::new(vec![wire0], ());
let face1 = face0.clone();
assert_eq!(face0.id(), face1.id());
face0.add_boundary(wire1);
assert_ne!(face0.id(), face1.id());

Returns the orientation of face.

The result of this method is the same with self.boundaries() == self.absolute_boundaries().clone(). Moreover, if this method returns false, self.boundaries() == self.absolute_boundaries().inverse().

Examples found in repository?
src/compress.rs (line 153)
146
147
148
149
150
151
152
153
154
155
156
    fn create_cface<S: Clone>(&mut self, face: &Face<P, C, S>) -> CompressedFace<S> {
        CompressedFace {
            boundaries: face
                .boundaries
                .iter()
                .map(|wire| self.create_boundary(wire))
                .collect(),
            orientation: face.orientation(),
            surface: face.get_surface(),
        }
    }
More examples
Hide additional examples
src/face.rs (line 422)
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }

    /// Returns the orientation of face.
    ///
    /// The result of this method is the same with `self.boundaries() == self.absolute_boundaries().clone()`.
    /// Moreover, if this method returns false, `self.boundaries() == self.absolute_boundaries().inverse()`.
    #[inline(always)]
    pub fn orientation(&self) -> bool { self.orientation }

    /// Returns the clone of surface of face.
    #[inline(always)]
    pub fn get_surface(&self) -> S
    where S: Clone {
        self.surface.lock().unwrap().clone()
    }

    /// Sets the surface of face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], 0);
    /// let face1 = face0.clone();
    ///
    /// // Two faces have the same content.
    /// assert_eq!(face0.get_surface(), 0);
    /// assert_eq!(face1.get_surface(), 0);
    ///
    /// // Set surface
    /// face0.set_surface(1);
    ///
    /// // The contents of two vertices are synchronized.
    /// assert_eq!(face0.get_surface(), 1);
    /// assert_eq!(face1.get_surface(), 1);
    /// ```
    #[inline(always)]
    pub fn set_surface(&self, surface: S) { *self.surface.lock().unwrap() = surface; }

    /// Inverts the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let org_face = face.clone();
    /// let org_bdry = face.boundaries();
    /// face.invert();
    ///
    /// // Two faces are the same face.
    /// face.is_same(&org_face);
    ///
    /// // The boundaries is inverted.
    /// let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut face.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn invert(&mut self) -> &mut Self {
        self.orientation = !self.orientation;
        self
    }

    /// Returns whether two faces are the same. Returns `true` even if the orientaions are different.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// assert_ne!(face0, face1);
    /// assert!(face0.is_same(&face1));
    /// ```
    #[inline(always)]
    pub fn is_same(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
    }

    /// Returns the id that does not depend on the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// let face1 = face0.inverse();
    /// let face2 = Face::new(vec![wire], ());
    /// assert_ne!(face0, face1);
    /// assert_ne!(face0, face2);
    /// assert_eq!(face0.id(), face1.id());
    /// assert_ne!(face0.id(), face2.id());
    /// ```
    #[inline(always)]
    pub fn id(&self) -> FaceID<S> { ID::new(Arc::as_ptr(&self.surface)) }

    /// Returns how many same faces.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    ///
    /// // Create one face
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Create another face, independent from face0
    /// let face1 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Clone face0, the result will be 2.
    /// let face2 = face0.clone();
    /// assert_eq!(face0.count(), 2);
    /// assert_eq!(face2.count(), 2);
    /// // drop face2, the result will be 1.
    /// drop(face2);
    /// assert_eq!(face0.count(), 1);
    /// ```
    #[inline(always)]
    pub fn count(&self) -> usize { Arc::strong_count(&self.surface) }

    /// Returns the inverse face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let inverted = face.inverse();
    ///
    /// // Two faces are the same face.
    /// assert!(face.is_same(&inverted));
    ///
    /// // Two faces has the same id.
    /// assert_eq!(face.id(), inverted.id());
    ///
    /// // The boundaries is inverted.
    /// let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut inverted.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn inverse(&self) -> Face<P, C, S> {
        let mut face = self.clone();
        face.invert();
        face
    }

    /// Returns whether two faces `self` and `other` have a shared edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 4]);
    /// let shared_edge = Edge::new(&v[0], &v[1], ());
    /// let another_edge = Edge::new(&v[0], &v[1], ());
    /// let inversed_edge = shared_edge.inverse();
    /// let wire = vec![
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &another_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[3], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[1], ()), &inversed_edge, &Edge::new(&v[0], &v[3], ())]),
    /// ];
    /// let face: Vec<_> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert!(face[0].border_on(&face[2]));
    /// assert!(!face[1].border_on(&face[2]));
    /// assert!(face[0].border_on(&face[3]));
    /// ```
    pub fn border_on(&self, other: &Face<P, C, S>) -> bool {
        let mut hashmap = HashMap::default();
        let edge_iter = self.boundary_iters().into_iter().flatten();
        edge_iter.for_each(|edge| {
            hashmap.insert(edge.id(), edge);
        });
        let mut edge_iter = other.boundary_iters().into_iter().flatten();
        edge_iter.any(|edge| hashmap.insert(edge.id(), edge).is_some())
    }

    /// Cuts a face with only one boundary by an edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// let (face0, face1) = face.cut_by_edge(Edge::new(&v[1], &v[3], ())).unwrap();
    ///
    /// // The front vertex of face0's boundary becomes the back of cutting edge.
    /// let v0: Vec<Vertex<()>> = face0.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v0, vec![v[3].clone(), v[0].clone(), v[1].clone()]);
    ///
    /// let v1: Vec<Vertex<()>> = face1.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v1, vec![v[1].clone(), v[2].clone(), v[3].clone()]);
    /// ```
    /// # Failures
    /// Returns `None` if:
    /// - `self` has several boundaries, or
    /// - `self` does not include vertices of the end vertices of `edge`.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[2], ())).is_none());
    /// ```
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[4], ())).is_none());
    pub fn cut_by_edge(&self, edge: Edge<P, C>) -> Option<(Self, Self)>
    where S: Clone {
        if self.boundaries.len() != 1 {
            return None;
        }
        let mut face0 = Face {
            boundaries: self.boundaries.clone(),
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        let wire = &mut face0.boundaries[0];
        let i = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.front() == edge.back())
            .map(|(i, _)| i)?;
        let j = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.back() == edge.front())
            .map(|(i, _)| i)?;
        wire.rotate_left(i);
        let j = (j + wire.len() - i) % wire.len();
        let mut new_wire = wire.split_off(j + 1);
        wire.push_back(edge.clone());
        new_wire.push_back(edge.inverse());
        debug_assert!(Face::try_new(self.boundaries.clone(), ()).is_ok());
        debug_assert!(Face::try_new(vec![new_wire.clone()], ()).is_ok());
        let face1 = Face {
            boundaries: vec![new_wire],
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        Some((face0, face1))
    }

    /// Glue two faces at boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 8]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    ///     Edge::new(&v[6], &v[2], ()),
    ///     Edge::new(&v[1], &v[6], ()),
    ///     Edge::new(&v[7], &v[5], ()),
    ///     Edge::new(&v[4], &v[7], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let wire2 = Wire::from(vec![
    ///     edge[6].clone(),
    ///     edge[1].inverse(),
    ///     edge[7].clone(),
    /// ]);
    /// let wire3 = Wire::from(vec![
    ///     edge[8].clone(),
    ///     edge[4].inverse(),
    ///     edge[9].clone(),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], ());
    /// let face1 = Face::new(vec![wire2, wire3], ());
    /// let face = face0.glue_at_boundaries(&face1).unwrap();
    /// let boundaries = face.boundary_iters();
    /// assert_eq!(boundaries.len(), 2);
    /// assert_eq!(boundaries[0].len(), 4);
    /// assert_eq!(boundaries[1].len(), 4);
    /// ```
    pub fn glue_at_boundaries(&self, other: &Self) -> Option<Self>
    where
        S: Clone + PartialEq,
        Wire<P, C>: Debug, {
        let surface = self.get_surface();
        if surface != other.get_surface() || self.orientation() != other.orientation() {
            return None;
        }
        let mut vemap: HashMap<VertexID<P>, &Edge<P, C>> = self
            .absolute_boundaries()
            .iter()
            .flatten()
            .map(|edge| (edge.front().id(), edge))
            .collect();
        other
            .absolute_boundaries()
            .iter()
            .flatten()
            .try_for_each(|edge| {
                if let Some(edge0) = vemap.get(&edge.back().id()) {
                    if edge.front() == edge0.back() {
                        if edge.is_same(edge0) {
                            vemap.remove(&edge.back().id());
                            return Some(());
                        } else {
                            return None;
                        }
                    }
                }
                vemap.insert(edge.front().id(), edge);
                Some(())
            })?;
        if vemap.is_empty() {
            return None;
        }
        let mut boundaries = Vec::new();
        while !vemap.is_empty() {
            let mut wire = Wire::new();
            let v = *vemap.iter().next().unwrap().0;
            let mut edge = vemap.remove(&v).unwrap();
            wire.push_back(edge.clone());
            while let Some(edge0) = vemap.remove(&edge.back().id()) {
                wire.push_back(edge0.clone());
                edge = edge0;
            }
            boundaries.push(wire);
        }
        debug_assert!(Face::try_new(boundaries.clone(), ()).is_ok());
        Some(Face {
            boundaries,
            orientation: self.orientation(),
            surface: Arc::new(Mutex::new(surface)),
        })
    }
src/shell.rs (line 484)
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
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Shell<Q, D, T>> {
        let mut vertex_map = EntryMap::new(Vertex::id, move |v| v.try_mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_try_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_try_mapped(&mut edge_map))
                    .collect::<Option<Vec<_>>>()?;
                let surface = surface_mapping(&*face.surface.lock().unwrap())?;
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                Some(new_face)
            })
            .collect()
    }

    /// Returns a new shell whose surfaces are mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 7,
    ///     &move |j: &usize| *j + 700,
    ///     &move |k: &usize| *k + 10000,
    /// );
    /// let shell0 = Shell::from(vec![face0, face1.inverse()]);
    /// let shell1 = shell0.mapped(
    ///     &move |i: &usize| *i + 50,
    ///     &move |j: &usize| *j + 5000,
    ///     &move |k: &usize| *k + 500000,
    /// );
    /// # for face in shell1.face_iter() {
    /// #    for bdry in face.absolute_boundaries() {
    /// #        assert!(bdry.is_closed());
    /// #        assert!(bdry.is_simple());
    /// #    }
    /// # }
    ///
    /// for (face0, face1) in shell0.face_iter().zip(shell1.face_iter()) {
    ///     assert_eq!(
    ///         face0.get_surface() + 500000,
    ///         face1.get_surface(),
    ///     );
    ///     assert_eq!(face0.orientation(), face1.orientation());
    ///     let biters0 = face0.boundary_iters();
    ///     let biters1 = face1.boundary_iters();
    ///     for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///         for (edge0, edge1) in biter0.zip(biter1) {
    ///             assert_eq!(
    ///                 edge0.front().get_point() + 50,
    ///                 edge1.front().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.back().get_point() + 50,
    ///                 edge1.back().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.get_curve() + 5000,
    ///                 edge1.get_curve(),
    ///             );
    ///         }
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Shell<Q, D, T> {
        let mut vertex_map = EntryMap::new(Vertex::id, |v| v.mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires: Vec<Wire<_, _>> = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_mapped(&mut edge_map))
                    .collect();
                let surface = surface_mapping(&*face.surface.lock().unwrap());
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                new_face
            })
            .collect()
    }

Returns the clone of surface of face.

Examples found in repository?
src/face.rs (line 219)
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
    fn renew_pointer(&mut self)
    where S: Clone {
        let surface = self.get_surface();
        self.surface = Arc::new(Mutex::new(surface));
    }

    /// Returns an iterator over the edges.
    #[inline(always)]
    pub fn edge_iter(&self) -> impl Iterator<Item = Edge<P, C>> + '_ {
        self.boundary_iters().into_iter().flatten()
    }

    /// Returns an iterator over the vertices.
    #[inline(always)]
    pub fn vertex_iter(&self) -> impl Iterator<Item = Vertex<P>> + '_ {
        self.edge_iter().map(|e| e.front().clone())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.try_add_boundary(wire1.clone()).unwrap();
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.try_add_boundary(wire1.clone()).unwrap();
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.try_add_boundary(wire1).unwrap();
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn try_add_boundary(&mut self, mut wire: Wire<P, C>) -> Result<()>
    where S: Clone {
        if wire.is_empty() {
            return Err(Error::EmptyWire);
        } else if !wire.is_closed() {
            return Err(Error::NotClosedWire);
        } else if !wire.is_simple() {
            return Err(Error::NotSimpleWire);
        }
        if !self.orientation {
            wire.invert();
        }
        self.boundaries.push(wire);
        self.renew_pointer();
        if !Wire::disjoint_wires(&self.boundaries) {
            self.boundaries.pop();
            return Err(Error::NotDisjointWires);
        }
        Ok(())
    }

    /// Adds a boundary to the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[4], &v[5], ()),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0.clone()], ());
    /// face0.add_boundary(wire1.clone());
    /// let face1 = Face::new(vec![wire0, wire1], ());
    /// assert_eq!(face0.boundaries(), face1.boundaries());
    /// ```
    /// # Remarks
    /// 1. If the face is inverted, then the added wire is inverted as absolute boundary.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire0], ());
    /// face.invert();
    /// face.add_boundary(wire1.clone());
    ///
    /// // The boundary is added in compatible with the face orientation.
    /// assert_eq!(face.boundaries()[1], wire1);
    ///
    /// // The absolute boundary is inverted!
    /// let iter0 = face.absolute_boundaries()[1].edge_iter();
    /// let iter1 = wire1.edge_iter().rev();
    /// for (edge0, edge1) in iter0.zip(iter1) {
    ///     assert_eq!(edge0.id(), edge1.id());
    ///     assert_eq!(edge0.orientation(), !edge1.orientation());
    /// }
    /// ```
    /// 2. This method renew the face id.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), (), ()]);
    /// let wire0 = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///      Edge::new(&v[3], &v[4], ()),
    ///      Edge::new(&v[5], &v[4], ()).inverse(),
    ///      Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let mut face0 = Face::new(vec![wire0], ());
    /// let face1 = face0.clone();
    /// assert_eq!(face0.id(), face1.id());
    /// face0.add_boundary(wire1);
    /// assert_ne!(face0.id(), face1.id());
    /// ```
    #[inline(always)]
    pub fn add_boundary(&mut self, wire: Wire<P, C>)
    where S: Clone {
        self.try_add_boundary(wire).remove_try()
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }

    /// Returns the orientation of face.
    ///
    /// The result of this method is the same with `self.boundaries() == self.absolute_boundaries().clone()`.
    /// Moreover, if this method returns false, `self.boundaries() == self.absolute_boundaries().inverse()`.
    #[inline(always)]
    pub fn orientation(&self) -> bool { self.orientation }

    /// Returns the clone of surface of face.
    #[inline(always)]
    pub fn get_surface(&self) -> S
    where S: Clone {
        self.surface.lock().unwrap().clone()
    }

    /// Sets the surface of face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], 0);
    /// let face1 = face0.clone();
    ///
    /// // Two faces have the same content.
    /// assert_eq!(face0.get_surface(), 0);
    /// assert_eq!(face1.get_surface(), 0);
    ///
    /// // Set surface
    /// face0.set_surface(1);
    ///
    /// // The contents of two vertices are synchronized.
    /// assert_eq!(face0.get_surface(), 1);
    /// assert_eq!(face1.get_surface(), 1);
    /// ```
    #[inline(always)]
    pub fn set_surface(&self, surface: S) { *self.surface.lock().unwrap() = surface; }

    /// Inverts the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let org_face = face.clone();
    /// let org_bdry = face.boundaries();
    /// face.invert();
    ///
    /// // Two faces are the same face.
    /// face.is_same(&org_face);
    ///
    /// // The boundaries is inverted.
    /// let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut face.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn invert(&mut self) -> &mut Self {
        self.orientation = !self.orientation;
        self
    }

    /// Returns whether two faces are the same. Returns `true` even if the orientaions are different.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// assert_ne!(face0, face1);
    /// assert!(face0.is_same(&face1));
    /// ```
    #[inline(always)]
    pub fn is_same(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
    }

    /// Returns the id that does not depend on the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// let face1 = face0.inverse();
    /// let face2 = Face::new(vec![wire], ());
    /// assert_ne!(face0, face1);
    /// assert_ne!(face0, face2);
    /// assert_eq!(face0.id(), face1.id());
    /// assert_ne!(face0.id(), face2.id());
    /// ```
    #[inline(always)]
    pub fn id(&self) -> FaceID<S> { ID::new(Arc::as_ptr(&self.surface)) }

    /// Returns how many same faces.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    ///
    /// // Create one face
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Create another face, independent from face0
    /// let face1 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Clone face0, the result will be 2.
    /// let face2 = face0.clone();
    /// assert_eq!(face0.count(), 2);
    /// assert_eq!(face2.count(), 2);
    /// // drop face2, the result will be 1.
    /// drop(face2);
    /// assert_eq!(face0.count(), 1);
    /// ```
    #[inline(always)]
    pub fn count(&self) -> usize { Arc::strong_count(&self.surface) }

    /// Returns the inverse face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let inverted = face.inverse();
    ///
    /// // Two faces are the same face.
    /// assert!(face.is_same(&inverted));
    ///
    /// // Two faces has the same id.
    /// assert_eq!(face.id(), inverted.id());
    ///
    /// // The boundaries is inverted.
    /// let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut inverted.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn inverse(&self) -> Face<P, C, S> {
        let mut face = self.clone();
        face.invert();
        face
    }

    /// Returns whether two faces `self` and `other` have a shared edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 4]);
    /// let shared_edge = Edge::new(&v[0], &v[1], ());
    /// let another_edge = Edge::new(&v[0], &v[1], ());
    /// let inversed_edge = shared_edge.inverse();
    /// let wire = vec![
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &another_edge, &Edge::new(&v[1], &v[2], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[3], ())]),
    ///     Wire::from_iter(vec![&Edge::new(&v[3], &v[1], ()), &inversed_edge, &Edge::new(&v[0], &v[3], ())]),
    /// ];
    /// let face: Vec<_> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
    /// assert!(face[0].border_on(&face[2]));
    /// assert!(!face[1].border_on(&face[2]));
    /// assert!(face[0].border_on(&face[3]));
    /// ```
    pub fn border_on(&self, other: &Face<P, C, S>) -> bool {
        let mut hashmap = HashMap::default();
        let edge_iter = self.boundary_iters().into_iter().flatten();
        edge_iter.for_each(|edge| {
            hashmap.insert(edge.id(), edge);
        });
        let mut edge_iter = other.boundary_iters().into_iter().flatten();
        edge_iter.any(|edge| hashmap.insert(edge.id(), edge).is_some())
    }

    /// Cuts a face with only one boundary by an edge.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// let (face0, face1) = face.cut_by_edge(Edge::new(&v[1], &v[3], ())).unwrap();
    ///
    /// // The front vertex of face0's boundary becomes the back of cutting edge.
    /// let v0: Vec<Vertex<()>> = face0.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v0, vec![v[3].clone(), v[0].clone(), v[1].clone()]);
    ///
    /// let v1: Vec<Vertex<()>> = face1.boundaries()[0].vertex_iter().collect();
    /// assert_eq!(v1, vec![v[1].clone(), v[2].clone(), v[3].clone()]);
    /// ```
    /// # Failures
    /// Returns `None` if:
    /// - `self` has several boundaries, or
    /// - `self` does not include vertices of the end vertices of `edge`.
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    /// ]);
    /// let face = Face::new(vec![wire0, wire1], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[2], ())).is_none());
    /// ```
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), (), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[3], ()),
    ///     Edge::new(&v[3], &v[0], ()),
    /// ]);
    /// let face = Face::new(vec![wire], ());
    /// assert!(face.cut_by_edge(Edge::new(&v[1], &v[4], ())).is_none());
    pub fn cut_by_edge(&self, edge: Edge<P, C>) -> Option<(Self, Self)>
    where S: Clone {
        if self.boundaries.len() != 1 {
            return None;
        }
        let mut face0 = Face {
            boundaries: self.boundaries.clone(),
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        let wire = &mut face0.boundaries[0];
        let i = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.front() == edge.back())
            .map(|(i, _)| i)?;
        let j = wire
            .edge_iter()
            .enumerate()
            .find(|(_, e)| e.back() == edge.front())
            .map(|(i, _)| i)?;
        wire.rotate_left(i);
        let j = (j + wire.len() - i) % wire.len();
        let mut new_wire = wire.split_off(j + 1);
        wire.push_back(edge.clone());
        new_wire.push_back(edge.inverse());
        debug_assert!(Face::try_new(self.boundaries.clone(), ()).is_ok());
        debug_assert!(Face::try_new(vec![new_wire.clone()], ()).is_ok());
        let face1 = Face {
            boundaries: vec![new_wire],
            orientation: self.orientation,
            surface: Arc::new(Mutex::new(self.get_surface())),
        };
        Some((face0, face1))
    }

    /// Glue two faces at boundaries.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 8]);
    /// let edge = vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    ///     Edge::new(&v[3], &v[4], ()),
    ///     Edge::new(&v[4], &v[5], ()),
    ///     Edge::new(&v[5], &v[3], ()),
    ///     Edge::new(&v[6], &v[2], ()),
    ///     Edge::new(&v[1], &v[6], ()),
    ///     Edge::new(&v[7], &v[5], ()),
    ///     Edge::new(&v[4], &v[7], ()),
    /// ];
    /// let wire0 = Wire::from(vec![
    ///     edge[0].clone(),
    ///     edge[1].clone(),
    ///     edge[2].clone(),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     edge[3].clone(),
    ///     edge[4].clone(),
    ///     edge[5].clone(),
    /// ]);
    /// let wire2 = Wire::from(vec![
    ///     edge[6].clone(),
    ///     edge[1].inverse(),
    ///     edge[7].clone(),
    /// ]);
    /// let wire3 = Wire::from(vec![
    ///     edge[8].clone(),
    ///     edge[4].inverse(),
    ///     edge[9].clone(),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], ());
    /// let face1 = Face::new(vec![wire2, wire3], ());
    /// let face = face0.glue_at_boundaries(&face1).unwrap();
    /// let boundaries = face.boundary_iters();
    /// assert_eq!(boundaries.len(), 2);
    /// assert_eq!(boundaries[0].len(), 4);
    /// assert_eq!(boundaries[1].len(), 4);
    /// ```
    pub fn glue_at_boundaries(&self, other: &Self) -> Option<Self>
    where
        S: Clone + PartialEq,
        Wire<P, C>: Debug, {
        let surface = self.get_surface();
        if surface != other.get_surface() || self.orientation() != other.orientation() {
            return None;
        }
        let mut vemap: HashMap<VertexID<P>, &Edge<P, C>> = self
            .absolute_boundaries()
            .iter()
            .flatten()
            .map(|edge| (edge.front().id(), edge))
            .collect();
        other
            .absolute_boundaries()
            .iter()
            .flatten()
            .try_for_each(|edge| {
                if let Some(edge0) = vemap.get(&edge.back().id()) {
                    if edge.front() == edge0.back() {
                        if edge.is_same(edge0) {
                            vemap.remove(&edge.back().id());
                            return Some(());
                        } else {
                            return None;
                        }
                    }
                }
                vemap.insert(edge.front().id(), edge);
                Some(())
            })?;
        if vemap.is_empty() {
            return None;
        }
        let mut boundaries = Vec::new();
        while !vemap.is_empty() {
            let mut wire = Wire::new();
            let v = *vemap.iter().next().unwrap().0;
            let mut edge = vemap.remove(&v).unwrap();
            wire.push_back(edge.clone());
            while let Some(edge0) = vemap.remove(&edge.back().id()) {
                wire.push_back(edge0.clone());
                edge = edge0;
            }
            boundaries.push(wire);
        }
        debug_assert!(Face::try_new(boundaries.clone(), ()).is_ok());
        Some(Face {
            boundaries,
            orientation: self.orientation(),
            surface: Arc::new(Mutex::new(surface)),
        })
    }
More examples
Hide additional examples
src/compress.rs (line 154)
146
147
148
149
150
151
152
153
154
155
156
    fn create_cface<S: Clone>(&mut self, face: &Face<P, C, S>) -> CompressedFace<S> {
        CompressedFace {
            boundaries: face
                .boundaries
                .iter()
                .map(|wire| self.create_boundary(wire))
                .collect(),
            orientation: face.orientation(),
            surface: face.get_surface(),
        }
    }

Sets the surface of face.

Examples
use truck_topology::*;
let v = Vertex::news(&[(), (), ()]);
let wire = Wire::from(vec![
     Edge::new(&v[0], &v[1], ()),
     Edge::new(&v[1], &v[2], ()),
     Edge::new(&v[2], &v[0], ()),
]);
let face0 = Face::new(vec![wire], 0);
let face1 = face0.clone();

// Two faces have the same content.
assert_eq!(face0.get_surface(), 0);
assert_eq!(face1.get_surface(), 0);

// Set surface
face0.set_surface(1);

// The contents of two vertices are synchronized.
assert_eq!(face0.get_surface(), 1);
assert_eq!(face1.get_surface(), 1);

Inverts the direction of the face.

Examples
use truck_topology::*;
use truck_topology::errors::Error;
let v = Vertex::news(&[(), (), ()]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);
let mut face = Face::new(vec![wire], ());
let org_face = face.clone();
let org_bdry = face.boundaries();
face.invert();

// Two faces are the same face.
face.is_same(&org_face);

// The boundaries is inverted.
let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
let face_edge_iter = &mut face.boundary_iters()[0];
for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    assert_eq!(edge0, edge1);
}
Examples found in repository?
src/solid.rs (line 86)
81
82
83
84
85
86
87
88
    pub fn not(&mut self) {
        self.boundaries
            .iter_mut()
            .flat_map(|shell| shell.face_iter_mut())
            .for_each(|face| {
                face.invert();
            })
    }
More examples
Hide additional examples
src/face.rs (line 423)
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Face<Q, D, T>> {
        let wires = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.try_mapped(&mut point_mapping, &mut curve_mapping))
            .collect::<Option<Vec<_>>>()?;
        let surface = surface_mapping(&*self.surface.lock().unwrap())?;
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        Some(face)
    }

    /// Returns a new face whose surface is mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 10,
    ///     &move |j: &usize| *j + 1000,
    ///     &move |k: &usize| *k + 100000,
    /// );
    /// # for wire in face1.boundaries() {
    /// #    assert!(wire.is_closed());
    /// #    assert!(wire.is_simple());
    /// # }
    ///
    /// assert_eq!(
    ///     face0.get_surface() + 100000,
    ///     face1.get_surface(),
    /// );
    /// let biters0 = face0.boundary_iters();
    /// let biters1 = face1.boundary_iters();
    /// for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///     for (edge0, edge1) in biter0.zip(biter1) {
    ///         assert_eq!(
    ///             edge0.front().get_point() + 10,
    ///             edge1.front().get_point(),
    ///         );
    ///         assert_eq!(
    ///             edge0.back().get_point() + 10,
    ///             edge1.back().get_point(),
    ///         );
    ///         assert_eq!(edge0.orientation(), edge1.orientation());
    ///         assert_eq!(
    ///             edge0.get_curve() + 1000,
    ///             edge1.get_curve(),
    ///         );
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Face<Q, D, T> {
        let wires: Vec<_> = self
            .absolute_boundaries()
            .iter()
            .map(|wire| wire.mapped(&mut point_mapping, &mut curve_mapping))
            .collect();
        let surface = surface_mapping(&*self.surface.lock().unwrap());
        let mut face = Face::debug_new(wires, surface);
        if !self.orientation() {
            face.invert();
        }
        face
    }

    /// Returns the orientation of face.
    ///
    /// The result of this method is the same with `self.boundaries() == self.absolute_boundaries().clone()`.
    /// Moreover, if this method returns false, `self.boundaries() == self.absolute_boundaries().inverse()`.
    #[inline(always)]
    pub fn orientation(&self) -> bool { self.orientation }

    /// Returns the clone of surface of face.
    #[inline(always)]
    pub fn get_surface(&self) -> S
    where S: Clone {
        self.surface.lock().unwrap().clone()
    }

    /// Sets the surface of face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///      Edge::new(&v[0], &v[1], ()),
    ///      Edge::new(&v[1], &v[2], ()),
    ///      Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], 0);
    /// let face1 = face0.clone();
    ///
    /// // Two faces have the same content.
    /// assert_eq!(face0.get_surface(), 0);
    /// assert_eq!(face1.get_surface(), 0);
    ///
    /// // Set surface
    /// face0.set_surface(1);
    ///
    /// // The contents of two vertices are synchronized.
    /// assert_eq!(face0.get_surface(), 1);
    /// assert_eq!(face1.get_surface(), 1);
    /// ```
    #[inline(always)]
    pub fn set_surface(&self, surface: S) { *self.surface.lock().unwrap() = surface; }

    /// Inverts the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let org_face = face.clone();
    /// let org_bdry = face.boundaries();
    /// face.invert();
    ///
    /// // Two faces are the same face.
    /// face.is_same(&org_face);
    ///
    /// // The boundaries is inverted.
    /// let inversed_edge_iter = org_bdry[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut face.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn invert(&mut self) -> &mut Self {
        self.orientation = !self.orientation;
        self
    }

    /// Returns whether two faces are the same. Returns `true` even if the orientaions are different.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire], ());
    /// let face1 = face0.inverse();
    /// assert_ne!(face0, face1);
    /// assert!(face0.is_same(&face1));
    /// ```
    #[inline(always)]
    pub fn is_same(&self, other: &Self) -> bool {
        std::ptr::eq(Arc::as_ptr(&self.surface), Arc::as_ptr(&other.surface))
    }

    /// Returns the id that does not depend on the direction of the face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// let face1 = face0.inverse();
    /// let face2 = Face::new(vec![wire], ());
    /// assert_ne!(face0, face1);
    /// assert_ne!(face0, face2);
    /// assert_eq!(face0.id(), face1.id());
    /// assert_ne!(face0.id(), face2.id());
    /// ```
    #[inline(always)]
    pub fn id(&self) -> FaceID<S> { ID::new(Arc::as_ptr(&self.surface)) }

    /// Returns how many same faces.
    ///
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[(); 3]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    ///
    /// // Create one face
    /// let face0 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Create another face, independent from face0
    /// let face1 = Face::new(vec![wire.clone()], ());
    /// assert_eq!(face0.count(), 1);
    /// // Clone face0, the result will be 2.
    /// let face2 = face0.clone();
    /// assert_eq!(face0.count(), 2);
    /// assert_eq!(face2.count(), 2);
    /// // drop face2, the result will be 1.
    /// drop(face2);
    /// assert_eq!(face0.count(), 1);
    /// ```
    #[inline(always)]
    pub fn count(&self) -> usize { Arc::strong_count(&self.surface) }

    /// Returns the inverse face.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// use truck_topology::errors::Error;
    /// let v = Vertex::news(&[(), (), ()]);
    /// let wire = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], ()),
    ///     Edge::new(&v[1], &v[2], ()),
    ///     Edge::new(&v[2], &v[0], ()),
    /// ]);
    /// let mut face = Face::new(vec![wire], ());
    /// let inverted = face.inverse();
    ///
    /// // Two faces are the same face.
    /// assert!(face.is_same(&inverted));
    ///
    /// // Two faces has the same id.
    /// assert_eq!(face.id(), inverted.id());
    ///
    /// // The boundaries is inverted.
    /// let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
    /// let face_edge_iter = &mut inverted.boundary_iters()[0];
    /// for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    ///     assert_eq!(edge0, edge1);
    /// }
    /// ```
    #[inline(always)]
    pub fn inverse(&self) -> Face<P, C, S> {
        let mut face = self.clone();
        face.invert();
        face
    }
src/compress.rs (line 75)
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    fn create_face<P, C>(self, edges: &[Edge<P, C>]) -> Result<Face<P, C, S>> {
        let wires: Vec<Wire<P, C>> = self
            .boundaries
            .into_iter()
            .map(|wire| {
                wire.into_iter()
                    .map(
                        |CompressedEdgeIndex { index, orientation }| match orientation {
                            true => edges[index].clone(),
                            false => edges[index].inverse(),
                        },
                    )
                    .collect()
            })
            .collect();
        let mut face = Face::try_new(wires, self.surface)?;
        if !self.orientation {
            face.invert();
        }
        Ok(face)
    }
src/shell.rs (line 485)
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
    pub fn try_mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Option<Q>,
        mut curve_mapping: impl FnMut(&C) -> Option<D>,
        mut surface_mapping: impl FnMut(&S) -> Option<T>,
    ) -> Option<Shell<Q, D, T>> {
        let mut vertex_map = EntryMap::new(Vertex::id, move |v| v.try_mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_try_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_try_mapped(&mut edge_map))
                    .collect::<Option<Vec<_>>>()?;
                let surface = surface_mapping(&*face.surface.lock().unwrap())?;
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                Some(new_face)
            })
            .collect()
    }

    /// Returns a new shell whose surfaces are mapped by `surface_mapping`,
    /// curves are mapped by `curve_mapping` and points are mapped by `point_mapping`.
    /// # Examples
    /// ```
    /// use truck_topology::*;
    /// let v = Vertex::news(&[0, 1, 2, 3, 4, 5, 6]);
    /// let wire0 = Wire::from(vec![
    ///     Edge::new(&v[0], &v[1], 100),
    ///     Edge::new(&v[1], &v[2], 200),
    ///     Edge::new(&v[2], &v[3], 300),
    ///     Edge::new(&v[3], &v[0], 400),
    /// ]);
    /// let wire1 = Wire::from(vec![
    ///     Edge::new(&v[4], &v[5], 500),
    ///     Edge::new(&v[6], &v[5], 600).inverse(),
    ///     Edge::new(&v[6], &v[4], 700),
    /// ]);
    /// let face0 = Face::new(vec![wire0, wire1], 10000);
    /// let face1 = face0.mapped(
    ///     &move |i: &usize| *i + 7,
    ///     &move |j: &usize| *j + 700,
    ///     &move |k: &usize| *k + 10000,
    /// );
    /// let shell0 = Shell::from(vec![face0, face1.inverse()]);
    /// let shell1 = shell0.mapped(
    ///     &move |i: &usize| *i + 50,
    ///     &move |j: &usize| *j + 5000,
    ///     &move |k: &usize| *k + 500000,
    /// );
    /// # for face in shell1.face_iter() {
    /// #    for bdry in face.absolute_boundaries() {
    /// #        assert!(bdry.is_closed());
    /// #        assert!(bdry.is_simple());
    /// #    }
    /// # }
    ///
    /// for (face0, face1) in shell0.face_iter().zip(shell1.face_iter()) {
    ///     assert_eq!(
    ///         face0.get_surface() + 500000,
    ///         face1.get_surface(),
    ///     );
    ///     assert_eq!(face0.orientation(), face1.orientation());
    ///     let biters0 = face0.boundary_iters();
    ///     let biters1 = face1.boundary_iters();
    ///     for (biter0, biter1) in biters0.into_iter().zip(biters1) {
    ///         for (edge0, edge1) in biter0.zip(biter1) {
    ///             assert_eq!(
    ///                 edge0.front().get_point() + 50,
    ///                 edge1.front().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.back().get_point() + 50,
    ///                 edge1.back().get_point(),
    ///             );
    ///             assert_eq!(
    ///                 edge0.get_curve() + 5000,
    ///                 edge1.get_curve(),
    ///             );
    ///         }
    ///     }
    /// }
    /// ```
    /// # Remarks
    /// Accessing geometry elements directly in the closure will result in a deadlock.
    /// So, this method does not appear to the document.
    #[doc(hidden)]
    pub fn mapped<Q, D, T>(
        &self,
        mut point_mapping: impl FnMut(&P) -> Q,
        mut curve_mapping: impl FnMut(&C) -> D,
        mut surface_mapping: impl FnMut(&S) -> T,
    ) -> Shell<Q, D, T> {
        let mut vertex_map = EntryMap::new(Vertex::id, |v| v.mapped(&mut point_mapping));
        let mut edge_map = EntryMap::new(
            Edge::id,
            wire::edge_entry_map_closure(&mut vertex_map, &mut curve_mapping),
        );
        self.face_iter()
            .map(|face| {
                let wires: Vec<Wire<_, _>> = face
                    .absolute_boundaries()
                    .iter()
                    .map(|wire| wire.sub_mapped(&mut edge_map))
                    .collect();
                let surface = surface_mapping(&*face.surface.lock().unwrap());
                let mut new_face = Face::debug_new(wires, surface);
                if !face.orientation() {
                    new_face.invert();
                }
                new_face
            })
            .collect()
    }

Returns whether two faces are the same. Returns true even if the orientaions are different.

Examples
use truck_topology::*;
let v = Vertex::news(&[(); 3]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);
let face0 = Face::new(vec![wire], ());
let face1 = face0.inverse();
assert_ne!(face0, face1);
assert!(face0.is_same(&face1));

Returns the id that does not depend on the direction of the face.

Examples
use truck_topology::*;
let v = Vertex::news(&[(); 3]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);
let face0 = Face::new(vec![wire.clone()], ());
let face1 = face0.inverse();
let face2 = Face::new(vec![wire], ());
assert_ne!(face0, face1);
assert_ne!(face0, face2);
assert_eq!(face0.id(), face1.id());
assert_ne!(face0.id(), face2.id());
Examples found in repository?
src/solid.rs (line 191)
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
    pub fn cut_face_by_edge(&mut self, face_id: FaceID<S>, edge: Edge<P, C>) -> bool
    where S: Clone {
        let tuple = self.boundaries.iter_mut().find_map(|shell| {
            let find_res = shell
                .face_iter_mut()
                .enumerate()
                .find(move |(_, face)| face.id() == face_id)
                .map(move |(i, _)| i);
            find_res.map(move |i| (shell, i))
        });
        if let Some((shell, i)) = tuple {
            if let Some((face0, face1)) = shell[i].cut_by_edge(edge) {
                shell[i] = face0;
                shell.push(face1);
                return true;
            }
        }
        false
    }
More examples
Hide additional examples
src/face.rs (line 1091)
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self.format {
            FaceDisplayFormat::Full { wire_format } => f
                .debug_struct("Face")
                .field("id", &self.entity.id())
                .field(
                    "boundaries",
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .field("entity", &MutexFmt(&self.entity.surface))
                .finish(),
            FaceDisplayFormat::BoundariesAndID { wire_format } => f
                .debug_struct("Face")
                .field("id", &self.entity.id())
                .field(
                    "boundaries",
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .finish(),
            FaceDisplayFormat::BoundariesAndSurface { wire_format } => f
                .debug_struct("Face")
                .field(
                    "boundaries",
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .field("entity", &MutexFmt(&self.entity.surface))
                .finish(),
            FaceDisplayFormat::LoopsListTuple { wire_format } => f
                .debug_tuple("Face")
                .field(
                    &self
                        .entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format))
                        .collect::<Vec<_>>(),
                )
                .finish(),
            FaceDisplayFormat::LoopsList { wire_format } => f
                .debug_list()
                .entries(
                    self.entity
                        .boundaries()
                        .iter()
                        .map(|wire| wire.display(wire_format)),
                )
                .finish(),
            FaceDisplayFormat::AsSurface => {
                f.write_fmt(format_args!("{:?}", &MutexFmt(&self.entity.surface)))
            }
        }
    }

Returns how many same faces.

Examples
use truck_topology::*;
let v = Vertex::news(&[(); 3]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);

// Create one face
let face0 = Face::new(vec![wire.clone()], ());
assert_eq!(face0.count(), 1);
// Create another face, independent from face0
let face1 = Face::new(vec![wire.clone()], ());
assert_eq!(face0.count(), 1);
// Clone face0, the result will be 2.
let face2 = face0.clone();
assert_eq!(face0.count(), 2);
assert_eq!(face2.count(), 2);
// drop face2, the result will be 1.
drop(face2);
assert_eq!(face0.count(), 1);

Returns the inverse face.

Examples
use truck_topology::*;
use truck_topology::errors::Error;
let v = Vertex::news(&[(), (), ()]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);
let mut face = Face::new(vec![wire], ());
let inverted = face.inverse();

// Two faces are the same face.
assert!(face.is_same(&inverted));

// Two faces has the same id.
assert_eq!(face.id(), inverted.id());

// The boundaries is inverted.
let mut inversed_edge_iter = face.boundaries()[0].inverse().edge_into_iter();
let face_edge_iter = &mut inverted.boundary_iters()[0];
for (edge0, edge1) in inversed_edge_iter.zip(face_edge_iter) {
    assert_eq!(edge0, edge1);
}

Returns whether two faces self and other have a shared edge.

Examples
use truck_topology::*;
let v = Vertex::news(&[(); 4]);
let shared_edge = Edge::new(&v[0], &v[1], ());
let another_edge = Edge::new(&v[0], &v[1], ());
let inversed_edge = shared_edge.inverse();
let wire = vec![
    Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[2], ())]),
    Wire::from_iter(vec![&Edge::new(&v[2], &v[0], ()), &another_edge, &Edge::new(&v[1], &v[2], ())]),
    Wire::from_iter(vec![&Edge::new(&v[3], &v[0], ()), &shared_edge, &Edge::new(&v[1], &v[3], ())]),
    Wire::from_iter(vec![&Edge::new(&v[3], &v[1], ()), &inversed_edge, &Edge::new(&v[0], &v[3], ())]),
];
let face: Vec<_> = wire.into_iter().map(|w| Face::new(vec![w], ())).collect();
assert!(face[0].border_on(&face[2]));
assert!(!face[1].border_on(&face[2]));
assert!(face[0].border_on(&face[3]));

Cuts a face with only one boundary by an edge.

Examples
use truck_topology::*;
let v = Vertex::news(&[(), (), (), ()]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[3], ()),
    Edge::new(&v[3], &v[0], ()),
]);
let face = Face::new(vec![wire], ());
let (face0, face1) = face.cut_by_edge(Edge::new(&v[1], &v[3], ())).unwrap();

// The front vertex of face0's boundary becomes the back of cutting edge.
let v0: Vec<Vertex<()>> = face0.boundaries()[0].vertex_iter().collect();
assert_eq!(v0, vec![v[3].clone(), v[0].clone(), v[1].clone()]);

let v1: Vec<Vertex<()>> = face1.boundaries()[0].vertex_iter().collect();
assert_eq!(v1, vec![v[1].clone(), v[2].clone(), v[3].clone()]);
Failures

Returns None if:

  • self has several boundaries, or
  • self does not include vertices of the end vertices of edge.
use truck_topology::*;
let v = Vertex::news(&[(); 6]);
let wire0 = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
]);
let wire1 = Wire::from(vec![
    Edge::new(&v[3], &v[4], ()),
    Edge::new(&v[4], &v[5], ()),
    Edge::new(&v[5], &v[3], ()),
]);
let face = Face::new(vec![wire0, wire1], ());
assert!(face.cut_by_edge(Edge::new(&v[1], &v[2], ())).is_none());
use truck_topology::*;
let v = Vertex::news(&[(), (), (), (), ()]);
let wire = Wire::from(vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[3], ()),
    Edge::new(&v[3], &v[0], ()),
]);
let face = Face::new(vec![wire], ());
assert!(face.cut_by_edge(Edge::new(&v[1], &v[4], ())).is_none());
Examples found in repository?
src/solid.rs (line 196)
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
    pub fn cut_face_by_edge(&mut self, face_id: FaceID<S>, edge: Edge<P, C>) -> bool
    where S: Clone {
        let tuple = self.boundaries.iter_mut().find_map(|shell| {
            let find_res = shell
                .face_iter_mut()
                .enumerate()
                .find(move |(_, face)| face.id() == face_id)
                .map(move |(i, _)| i);
            find_res.map(move |i| (shell, i))
        });
        if let Some((shell, i)) = tuple {
            if let Some((face0, face1)) = shell[i].cut_by_edge(edge) {
                shell[i] = face0;
                shell.push(face1);
                return true;
            }
        }
        false
    }

Glue two faces at boundaries.

Examples
use truck_topology::*;
let v = Vertex::news(&[(); 8]);
let edge = vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
    Edge::new(&v[3], &v[4], ()),
    Edge::new(&v[4], &v[5], ()),
    Edge::new(&v[5], &v[3], ()),
    Edge::new(&v[6], &v[2], ()),
    Edge::new(&v[1], &v[6], ()),
    Edge::new(&v[7], &v[5], ()),
    Edge::new(&v[4], &v[7], ()),
];
let wire0 = Wire::from(vec![
    edge[0].clone(),
    edge[1].clone(),
    edge[2].clone(),
]);
let wire1 = Wire::from(vec![
    edge[3].clone(),
    edge[4].clone(),
    edge[5].clone(),
]);
let wire2 = Wire::from(vec![
    edge[6].clone(),
    edge[1].inverse(),
    edge[7].clone(),
]);
let wire3 = Wire::from(vec![
    edge[8].clone(),
    edge[4].inverse(),
    edge[9].clone(),
]);
let face0 = Face::new(vec![wire0, wire1], ());
let face1 = Face::new(vec![wire2, wire3], ());
let face = face0.glue_at_boundaries(&face1).unwrap();
let boundaries = face.boundary_iters();
assert_eq!(boundaries.len(), 2);
assert_eq!(boundaries[0].len(), 4);
assert_eq!(boundaries[1].len(), 4);

Creates display struct for debugging the face.

Examples
use truck_topology::*;
use FaceDisplayFormat as FDF;
let v = Vertex::news(&[0, 1, 2, 3, 4, 5]);
let edge = vec![
    Edge::new(&v[0], &v[1], ()),
    Edge::new(&v[1], &v[2], ()),
    Edge::new(&v[2], &v[0], ()),
    Edge::new(&v[3], &v[4], ()),
    Edge::new(&v[4], &v[5], ()),
    Edge::new(&v[5], &v[3], ()),
];
let wire0 = Wire::from(vec![
    edge[0].clone(),
    edge[1].clone(),
    edge[2].clone(),
]);
let wire1 = Wire::from(vec![
    edge[3].clone(),
    edge[4].clone(),
    edge[5].clone(),
]);
let face = Face::new(vec![wire0, wire1], 120);

let vertex_format = VertexDisplayFormat::AsPoint;
let edge_format = EdgeDisplayFormat::VerticesTuple { vertex_format };
let wire_format = WireDisplayFormat::EdgesList { edge_format };

assert_eq!(
    format!("{:?}", face.display(FDF::Full { wire_format })),
    format!("Face {{ id: {:?}, boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]], entity: 120 }}", face.id()),
);
assert_eq!(
    format!("{:?}", face.display(FDF::BoundariesAndID { wire_format })),
    format!("Face {{ id: {:?}, boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]] }}", face.id()),
);
assert_eq!(
    &format!("{:?}", face.display(FDF::BoundariesAndSurface { wire_format })),
    "Face { boundaries: [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]], entity: 120 }",
);
assert_eq!(
    &format!("{:?}", face.display(FDF::LoopsListTuple { wire_format })),
    "Face([[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]])",
);
assert_eq!(
    &format!("{:?}", face.display(FDF::LoopsList { wire_format })),
    "[[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]]",
);
assert_eq!(
    &format!("{:?}", face.display(FDF::AsSurface)),
    "120",
);
Examples found in repository?
src/shell.rs (line 1065)
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self.format {
            ShellDisplayFormat::FacesList { face_format } => f
                .debug_list()
                .entries(
                    self.entity
                        .face_iter()
                        .map(|face| face.display(face_format)),
                )
                .finish(),
            ShellDisplayFormat::FacesListTuple { face_format } => f
                .debug_tuple("Shell")
                .field(&DebugDisplay {
                    entity: self.entity,
                    format: ShellDisplayFormat::FacesList { face_format },
                })
                .finish(),
        }
    }

Returns the cloned surface in face. If face is inverted, then the returned surface is also inverted.

Returns the consistence of the geometry of end vertices and the geometry of edge.

Examples found in repository?
src/shell.rs (line 594)
589
590
591
592
593
594
595
    pub fn is_geometric_consistent(&self) -> bool
    where
        P: Tolerance,
        C: BoundedCurve<Point = P>,
        S: IncludeCurve<C>, {
        self.iter().all(|face| face.is_geometric_consistent())
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Creates a value from an iterator. Read more
Creates an instance of the collection from the parallel iterator par_iter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
Extends an instance of the collection with the elements drawn from the parallel iterator par_iter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.