Skip to content

Commit 762c114

Browse files
committed
refactor(core): use min instead of recomputing cell IDs in sews methods
1 parent a46db61 commit 762c114

4 files changed

Lines changed: 128 additions & 92 deletions

File tree

honeycomb-core/src/cmap/dim2/sews/one.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<T: CoordsFloat> CMap2<T> {
1313
lhs_dart_id: DartIdType,
1414
rhs_dart_id: DartIdType,
1515
) -> TransactionClosureResult<(), SewError> {
16-
let b2lhs_dart_id = self.betas[(2, lhs_dart_id)].read(t)?;
16+
let b2lhs_dart_id = self.beta_tx::<2>(t, lhs_dart_id)?;
1717
if b2lhs_dart_id == NULL_DART_ID {
1818
try_or_coerce!(
1919
self.betas.one_link_core(t, lhs_dart_id, rhs_dart_id),
@@ -28,17 +28,20 @@ impl<T: CoordsFloat> CMap2<T> {
2828
SewError
2929
);
3030

31-
let new_vid = self.vertex_id_tx(t, rhs_dart_id)?;
32-
3331
try_or_coerce!(
34-
self.vertices.merge(t, new_vid, b2lhs_vid_old, rhs_vid_old),
32+
self.vertices.merge(
33+
t,
34+
b2lhs_vid_old.min(rhs_vid_old),
35+
b2lhs_vid_old,
36+
rhs_vid_old,
37+
),
3538
SewError
3639
);
3740
try_or_coerce!(
3841
self.attributes.merge_attributes(
3942
t,
4043
OrbitPolicy::Vertex,
41-
new_vid,
44+
b2lhs_vid_old.min(rhs_vid_old),
4245
b2lhs_vid_old,
4346
rhs_vid_old,
4447
),
@@ -54,24 +57,32 @@ impl<T: CoordsFloat> CMap2<T> {
5457
t: &mut Transaction,
5558
lhs_dart_id: DartIdType,
5659
) -> TransactionClosureResult<(), SewError> {
57-
let b2lhs_dart_id = self.betas[(2, lhs_dart_id)].read(t)?;
60+
let b2lhs_dart_id = self.beta_tx::<2>(t, lhs_dart_id)?;
5861
if b2lhs_dart_id == NULL_DART_ID {
5962
try_or_coerce!(self.betas.one_unlink_core(t, lhs_dart_id), SewError);
6063
} else {
6164
// fetch IDs before topology update
62-
let rhs_dart_id = self.betas[(1, lhs_dart_id)].read(t)?;
63-
let vid_old = self.vertex_id_tx(t, rhs_dart_id)?;
65+
let rhs_dart_id = self.beta_tx::<1>(t, lhs_dart_id)?;
6466
// update the topology
6567
try_or_coerce!(self.betas.one_unlink_core(t, lhs_dart_id), SewError);
6668
// split vertices & attributes from the old ID to the new ones
6769
let (new_lhs, new_rhs) = (
6870
self.vertex_id_tx(t, b2lhs_dart_id)?,
6971
self.vertex_id_tx(t, rhs_dart_id)?,
7072
);
71-
try_or_coerce!(self.vertices.split(t, new_lhs, new_rhs, vid_old), SewError);
7273
try_or_coerce!(
73-
self.attributes
74-
.split_attributes(t, OrbitPolicy::Vertex, new_lhs, new_rhs, vid_old),
74+
self.vertices
75+
.split(t, new_lhs, new_rhs, new_lhs.min(new_rhs)),
76+
SewError
77+
);
78+
try_or_coerce!(
79+
self.attributes.split_attributes(
80+
t,
81+
OrbitPolicy::Vertex,
82+
new_lhs,
83+
new_rhs,
84+
new_lhs.min(new_rhs),
85+
),
7586
SewError
7687
);
7788
}

honeycomb-core/src/cmap/dim2/sews/two.rs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ impl<T: CoordsFloat> CMap2<T> {
1414
lhs_dart_id: DartIdType,
1515
rhs_dart_id: DartIdType,
1616
) -> TransactionClosureResult<(), SewError> {
17-
let b1lhs_dart_id = self.betas[(1, lhs_dart_id)].read(t)?;
18-
let b1rhs_dart_id = self.betas[(1, rhs_dart_id)].read(t)?;
17+
let b1lhs_dart_id = self.beta_tx::<1>(t, lhs_dart_id)?;
18+
let b1rhs_dart_id = self.beta_tx::<1>(t, rhs_dart_id)?;
1919
// match (is lhs 1-free, is rhs 1-free)
2020
match (b1lhs_dart_id == NULL_DART_ID, b1rhs_dart_id == NULL_DART_ID) {
2121
// trivial case, no update needed
@@ -24,13 +24,12 @@ impl<T: CoordsFloat> CMap2<T> {
2424
self.betas.two_link_core(t, lhs_dart_id, rhs_dart_id),
2525
SewError
2626
);
27-
let eid_new = self.edge_id_tx(t, lhs_dart_id)?;
2827
try_or_coerce!(
2928
self.attributes.merge_attributes(
3029
t,
3130
OrbitPolicy::Edge,
32-
eid_new,
33-
lhs_dart_id as EdgeIdType, // valid in 2D
31+
lhs_dart_id.min(rhs_dart_id) as EdgeIdType,
32+
lhs_dart_id as EdgeIdType,
3433
rhs_dart_id as EdgeIdType,
3534
),
3635
SewError
@@ -49,18 +48,20 @@ impl<T: CoordsFloat> CMap2<T> {
4948
SewError
5049
);
5150
// merge vertices & attributes from the old IDs to the new one
52-
let lhs_vid_new = self.vertex_id_tx(t, lhs_dart_id)?;
53-
let eid_new = self.edge_id_tx(t, lhs_dart_id)?;
5451
try_or_coerce!(
55-
self.vertices
56-
.merge(t, lhs_vid_new, lhs_vid_old, b1rhs_vid_old),
52+
self.vertices.merge(
53+
t,
54+
lhs_vid_old.min(b1rhs_vid_old),
55+
lhs_vid_old,
56+
b1rhs_vid_old
57+
),
5758
SewError
5859
);
5960
try_or_coerce!(
6061
self.attributes.merge_attributes(
6162
t,
6263
OrbitPolicy::Vertex,
63-
lhs_vid_new,
64+
lhs_vid_old.min(b1rhs_vid_old),
6465
lhs_vid_old,
6566
b1rhs_vid_old,
6667
),
@@ -70,7 +71,7 @@ impl<T: CoordsFloat> CMap2<T> {
7071
self.attributes.merge_attributes(
7172
t,
7273
OrbitPolicy::Edge,
73-
eid_new,
74+
lhs_eid_old.min(rhs_eid_old),
7475
lhs_eid_old,
7576
rhs_eid_old,
7677
),
@@ -90,18 +91,20 @@ impl<T: CoordsFloat> CMap2<T> {
9091
SewError
9192
);
9293
// merge vertices & attributes from the old IDs to the new one
93-
let rhs_vid_new = self.vertex_id_tx(t, rhs_dart_id)?;
94-
let eid_new = self.edge_id_tx(t, lhs_dart_id)?;
9594
try_or_coerce!(
96-
self.vertices
97-
.merge(t, rhs_vid_new, b1lhs_vid_old, rhs_vid_old),
95+
self.vertices.merge(
96+
t,
97+
b1lhs_vid_old.min(rhs_vid_old),
98+
b1lhs_vid_old,
99+
rhs_vid_old
100+
),
98101
SewError
99102
);
100103
try_or_coerce!(
101104
self.attributes.merge_attributes(
102105
t,
103106
OrbitPolicy::Vertex,
104-
rhs_vid_new,
107+
b1lhs_vid_old.min(rhs_vid_old),
105108
b1lhs_vid_old,
106109
rhs_vid_old,
107110
),
@@ -111,7 +114,7 @@ impl<T: CoordsFloat> CMap2<T> {
111114
self.attributes.merge_attributes(
112115
t,
113116
OrbitPolicy::Edge,
114-
eid_new,
117+
lhs_eid_old.min(rhs_eid_old),
115118
lhs_eid_old,
116119
rhs_eid_old,
117120
),
@@ -158,24 +161,29 @@ impl<T: CoordsFloat> CMap2<T> {
158161
SewError
159162
);
160163
// merge vertices & attributes from the old IDs to the new one
161-
let lhs_vid_new = self.vertex_id_tx(t, lhs_dart_id)?;
162-
let rhs_vid_new = self.vertex_id_tx(t, rhs_dart_id)?;
163-
let eid_new = self.edge_id_tx(t, lhs_dart_id)?;
164164
try_or_coerce!(
165-
self.vertices
166-
.merge(t, lhs_vid_new, lhs_vid_old, b1rhs_vid_old),
165+
self.vertices.merge(
166+
t,
167+
lhs_vid_old.min(b1rhs_vid_old),
168+
lhs_vid_old,
169+
b1rhs_vid_old
170+
),
167171
SewError
168172
);
169173
try_or_coerce!(
170-
self.vertices
171-
.merge(t, rhs_vid_new, b1lhs_vid_old, rhs_vid_old),
174+
self.vertices.merge(
175+
t,
176+
b1lhs_vid_old.min(rhs_vid_old),
177+
b1lhs_vid_old,
178+
rhs_vid_old
179+
),
172180
SewError
173181
);
174182
try_or_coerce!(
175183
self.attributes.merge_attributes(
176184
t,
177185
OrbitPolicy::Vertex,
178-
lhs_vid_new,
186+
lhs_vid_old.min(b1rhs_vid_old),
179187
lhs_vid_old,
180188
b1rhs_vid_old,
181189
),
@@ -185,7 +193,7 @@ impl<T: CoordsFloat> CMap2<T> {
185193
self.attributes.merge_attributes(
186194
t,
187195
OrbitPolicy::Vertex,
188-
rhs_vid_new,
196+
b1lhs_vid_old.min(rhs_vid_old),
189197
b1lhs_vid_old,
190198
rhs_vid_old,
191199
),
@@ -195,7 +203,7 @@ impl<T: CoordsFloat> CMap2<T> {
195203
self.attributes.merge_attributes(
196204
t,
197205
OrbitPolicy::Edge,
198-
eid_new,
206+
lhs_eid_old.min(rhs_eid_old),
199207
lhs_eid_old,
200208
rhs_eid_old,
201209
),
@@ -213,9 +221,9 @@ impl<T: CoordsFloat> CMap2<T> {
213221
t: &mut Transaction,
214222
lhs_dart_id: DartIdType,
215223
) -> TransactionClosureResult<(), SewError> {
216-
let rhs_dart_id = self.betas[(2, lhs_dart_id)].read(t)?;
217-
let b1lhs_dart_id = self.betas[(1, lhs_dart_id)].read(t)?;
218-
let b1rhs_dart_id = self.betas[(1, rhs_dart_id)].read(t)?;
224+
let rhs_dart_id = self.beta_tx::<2>(t, lhs_dart_id)?;
225+
let b1lhs_dart_id = self.beta_tx::<1>(t, lhs_dart_id)?;
226+
let b1rhs_dart_id = self.beta_tx::<1>(t, rhs_dart_id)?;
219227
// match (is lhs 1-free, is rhs 1-free)
220228
match (b1lhs_dart_id == NULL_DART_ID, b1rhs_dart_id == NULL_DART_ID) {
221229
(true, true) => {

honeycomb-core/src/cmap/dim3/sews/one.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<T: CoordsFloat> CMap3<T> {
3434
try_or_coerce!(self.one_link(t, ld, rd), SewError);
3535

3636
if vid_l_old != NULL_VERTEX_ID {
37-
let new_vid = vid_r_old.min(vid_l_old); // is this correct?
37+
let new_vid = vid_r_old.min(vid_l_old);
3838
try_or_coerce!(
3939
self.vertices.merge(t, new_vid, vid_l_old, vid_r_old),
4040
SewError
@@ -60,7 +60,6 @@ impl<T: CoordsFloat> CMap3<T> {
6060
ld: DartIdType,
6161
) -> TransactionClosureResult<(), SewError> {
6262
let rd = self.beta_tx::<1>(t, ld)?;
63-
let vid_old = self.vertex_id_tx(t, rd)?;
6463

6564
try_or_coerce!(self.one_unlink(t, ld), SewError);
6665
let b2ld = self.beta_tx::<2>(t, ld)?;
@@ -81,7 +80,8 @@ impl<T: CoordsFloat> CMap3<T> {
8180
// perf: branch miss vs redundancy
8281
if vid_l_new != vid_r_new {
8382
try_or_coerce!(
84-
self.vertices.split(t, vid_l_new, vid_r_new, vid_old),
83+
self.vertices
84+
.split(t, vid_l_new, vid_r_new, vid_l_new.min(vid_r_new)),
8585
SewError
8686
);
8787
try_or_coerce!(
@@ -90,7 +90,7 @@ impl<T: CoordsFloat> CMap3<T> {
9090
OrbitPolicy::Vertex,
9191
vid_l_new,
9292
vid_r_new,
93-
vid_old
93+
vid_l_new.min(vid_r_new),
9494
),
9595
SewError
9696
);

0 commit comments

Comments
 (0)