From f36f80537f7ae709d1994d654f2ba078eb56f565 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Tue, 19 Sep 2023 15:40:26 +0200 Subject: [PATCH] layout: Add invariant testing R-tree envelope invariance --- src/layout.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/layout.rs b/src/layout.rs index 33e7644..e12c67c 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -24,6 +24,7 @@ pub struct Layout { } #[debug_invariant(self.graph.node_count() == self.rtree.size())] +#[debug_invariant(self.test_envelopes())] impl Layout { pub fn new() -> Self { Layout { @@ -224,6 +225,7 @@ impl Layout { } } +#[debug_invariant(self.test_envelopes())] impl Layout { #[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))] #[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))] @@ -310,3 +312,14 @@ impl Layout { .is_some()); } } + +impl Layout { + fn test_envelopes(&self) -> bool { + !self.rtree.iter().any(|wrapper| { + !self + .rtree + .locate_in_envelope(&wrapper.geom().envelope()) + .any(|w| w == wrapper) + }) + } +}