From 21dd6ffd395b38c7b98c049c8a5322cd18805454 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 17 Jul 2025 01:44:32 +0200 Subject: [PATCH] fix(geometry/with_rtree): Debug-assert instead of returning `Err(())` --- src/geometry/edit.rs | 1 + src/geometry/recording_with_rtree.rs | 2 +- src/geometry/with_rtree.rs | 17 ++++++----------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/geometry/edit.rs b/src/geometry/edit.rs index 8ad0718..a2fd6ac 100644 --- a/src/geometry/edit.rs +++ b/src/geometry/edit.rs @@ -71,6 +71,7 @@ impl< edit: &BTreeMap, Option)>, ) { for (index, (old, new)) in edit { + // TODO: Delete `(None, None)`s. match main.entry(*index) { Entry::Vacant(vac) => { vac.insert((old.clone(), new.clone())); diff --git a/src/geometry/recording_with_rtree.rs b/src/geometry/recording_with_rtree.rs index da7915f..8b82258 100644 --- a/src/geometry/recording_with_rtree.rs +++ b/src/geometry/recording_with_rtree.rs @@ -189,7 +189,7 @@ impl< dot: DI, ) -> Result<(), ()> { 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); Ok(()) } diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index b597553..a89f200 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -176,18 +176,12 @@ impl< self.rtree.insert(self.make_compound_bbox(compound)); } - pub fn remove_dot(&mut self, dot: DI) -> Result<(), ()> { - if self.geometry.joined_segs(dot).next().is_some() { - return Err(()); - } - - if self.geometry.joined_bends(dot).next().is_some() { - return Err(()); - } + pub fn remove_dot(&mut self, dot: DI) { + debug_assert!(self.geometry.joined_segs(dot).next().is_none()); + debug_assert!(self.geometry.joined_bends(dot).next().is_none()); Self::rtree_remove_must_be_successful(self.rtree.remove(&self.make_dot_bbox(dot))); self.geometry.remove_primitive(dot.into()); - Ok(()) } pub fn remove_seg(&mut self, seg: SI) { @@ -300,8 +294,9 @@ impl< debug_assert!( removed.is_some(), "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 - reinserted into the R-tree, making it impossible to find the node + There are two likely reasons for this. The node may have not + 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" ); }