honeycomb_core/cmap/dim2/sews/
one.rs
1use crate::attributes::UnknownAttributeStorage;
2use crate::cmap::{CMap2, DartIdType, NULL_DART_ID, OrbitPolicy, SewError};
3use crate::geometry::CoordsFloat;
4use crate::stm::{Transaction, TransactionClosureResult, try_or_coerce};
5
6#[doc(hidden)]
7impl<T: CoordsFloat> CMap2<T> {
9 pub(super) fn one_sew(
11 &self,
12 trans: &mut Transaction,
13 lhs_dart_id: DartIdType,
14 rhs_dart_id: DartIdType,
15 ) -> TransactionClosureResult<(), SewError> {
16 let b2lhs_dart_id = self.betas[(2, lhs_dart_id)].read(trans)?;
17 if b2lhs_dart_id == NULL_DART_ID {
18 try_or_coerce!(
19 self.betas.one_link_core(trans, lhs_dart_id, rhs_dart_id),
20 SewError
21 );
22 } else {
23 let b2lhs_vid_old = self.vertex_id_transac(trans, b2lhs_dart_id)?;
24 let rhs_vid_old = self.vertex_id_transac(trans, rhs_dart_id)?;
25
26 try_or_coerce!(
27 self.betas.one_link_core(trans, lhs_dart_id, rhs_dart_id),
28 SewError
29 );
30
31 let new_vid = self.vertex_id_transac(trans, rhs_dart_id)?;
32
33 try_or_coerce!(
34 self.vertices
35 .merge(trans, new_vid, b2lhs_vid_old, rhs_vid_old),
36 SewError
37 );
38 try_or_coerce!(
39 self.attributes.merge_attributes(
40 trans,
41 OrbitPolicy::Vertex,
42 new_vid,
43 b2lhs_vid_old,
44 rhs_vid_old,
45 ),
46 SewError
47 );
48 }
49 Ok(())
50 }
51
52 pub(super) fn one_unsew(
54 &self,
55 trans: &mut Transaction,
56 lhs_dart_id: DartIdType,
57 ) -> TransactionClosureResult<(), SewError> {
58 let b2lhs_dart_id = self.betas[(2, lhs_dart_id)].read(trans)?;
59 if b2lhs_dart_id == NULL_DART_ID {
60 try_or_coerce!(self.betas.one_unlink_core(trans, lhs_dart_id), SewError);
61 } else {
62 let rhs_dart_id = self.betas[(1, lhs_dart_id)].read(trans)?;
64 let vid_old = self.vertex_id_transac(trans, rhs_dart_id)?;
65 try_or_coerce!(self.betas.one_unlink_core(trans, lhs_dart_id), SewError);
67 let (new_lhs, new_rhs) = (
69 self.vertex_id_transac(trans, b2lhs_dart_id)?,
70 self.vertex_id_transac(trans, rhs_dart_id)?,
71 );
72 try_or_coerce!(
73 self.vertices.split(trans, new_lhs, new_rhs, vid_old),
74 SewError
75 );
76 try_or_coerce!(
77 self.attributes.split_attributes(
78 trans,
79 OrbitPolicy::Vertex,
80 new_lhs,
81 new_rhs,
82 vid_old
83 ),
84 SewError
85 );
86 }
87 Ok(())
88 }
89}