layout: Add invariant testing R-tree envelope invariance

This commit is contained in:
Mikolaj Wielgus 2023-09-19 15:40:26 +02:00
parent efea917cb1
commit f36f80537f
1 changed files with 13 additions and 0 deletions

View File

@ -24,6 +24,7 @@ pub struct Layout {
} }
#[debug_invariant(self.graph.node_count() == self.rtree.size())] #[debug_invariant(self.graph.node_count() == self.rtree.size())]
#[debug_invariant(self.test_envelopes())]
impl Layout { impl Layout {
pub fn new() -> Self { pub fn new() -> Self {
Layout { Layout {
@ -224,6 +225,7 @@ impl Layout {
} }
} }
#[debug_invariant(self.test_envelopes())]
impl Layout { impl Layout {
#[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))] #[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))]
#[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))] #[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))]
@ -310,3 +312,14 @@ impl Layout {
.is_some()); .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)
})
}
}