fix(geometry/with_rtree): Debug-assert instead of returning `Err(())`

This commit is contained in:
Mikolaj Wielgus 2025-07-17 01:44:32 +02:00
parent a9c4456a54
commit 21dd6ffd39
3 changed files with 8 additions and 12 deletions

View File

@ -71,6 +71,7 @@ impl<
edit: &BTreeMap<I, (Option<D>, Option<D>)>, edit: &BTreeMap<I, (Option<D>, Option<D>)>,
) { ) {
for (index, (old, new)) in edit { for (index, (old, new)) in edit {
// TODO: Delete `(None, None)`s.
match main.entry(*index) { match main.entry(*index) {
Entry::Vacant(vac) => { Entry::Vacant(vac) => {
vac.insert((old.clone(), new.clone())); vac.insert((old.clone(), new.clone()));

View File

@ -189,7 +189,7 @@ impl<
dot: DI, dot: DI,
) -> Result<(), ()> { ) -> Result<(), ()> {
let weight = self.geometry_with_rtree.geometry().dot_weight(dot); let weight = self.geometry_with_rtree.geometry().dot_weight(dot);
self.geometry_with_rtree.remove_dot(dot)?; self.geometry_with_rtree.remove_dot(dot);
edit_remove_from_map(&mut recorder.dots, dot, weight); edit_remove_from_map(&mut recorder.dots, dot, weight);
Ok(()) Ok(())
} }

View File

@ -176,18 +176,12 @@ impl<
self.rtree.insert(self.make_compound_bbox(compound)); self.rtree.insert(self.make_compound_bbox(compound));
} }
pub fn remove_dot(&mut self, dot: DI) -> Result<(), ()> { pub fn remove_dot(&mut self, dot: DI) {
if self.geometry.joined_segs(dot).next().is_some() { debug_assert!(self.geometry.joined_segs(dot).next().is_none());
return Err(()); debug_assert!(self.geometry.joined_bends(dot).next().is_none());
}
if self.geometry.joined_bends(dot).next().is_some() {
return Err(());
}
Self::rtree_remove_must_be_successful(self.rtree.remove(&self.make_dot_bbox(dot))); Self::rtree_remove_must_be_successful(self.rtree.remove(&self.make_dot_bbox(dot)));
self.geometry.remove_primitive(dot.into()); self.geometry.remove_primitive(dot.into());
Ok(())
} }
pub fn remove_seg(&mut self, seg: SI) { pub fn remove_seg(&mut self, seg: SI) {
@ -300,8 +294,9 @@ impl<
debug_assert!( debug_assert!(
removed.is_some(), removed.is_some(),
"removed node's bbox did not match any of the R-tree's envelopes. "removed node's bbox did not match any of the R-tree's envelopes.
This is most likely because node's bbox changed without being There are two likely reasons for this. The node may have not
reinserted into the R-tree, making it impossible to find the node existed already. Or the node's bbox may have changed without being
reinserted in the R-tree, making it impossible to find the node
using an R-tree query, which is inevitably fatal" using an R-tree query, which is inevitably fatal"
); );
} }