Skip to content

Commit

Permalink
scaffold rstar edge set intersector
Browse files Browse the repository at this point in the history
Copied the "SimpleEdgeSetIntersector" into a new struct. I'll add the
actual RTree implementation in a follow up, and hopefully this way it'll
be easier to compare the two implementations.
  • Loading branch information
michaelkirk committed May 10, 2022
1 parent 4a5b457 commit 3ec60bf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
11 changes: 9 additions & 2 deletions geo/src/algorithm/relate/geomgraph/geometry_graph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::{
index::{EdgeSetIntersector, SegmentIntersector, SimpleEdgeSetIntersector},
index::{
EdgeSetIntersector, RstarEdgeSetIntersector, SegmentIntersector, SimpleEdgeSetIntersector,
},
CoordNode, CoordPos, Direction, Edge, Label, LineIntersector, PlanarGraph, TopologyPosition,
};

Expand Down Expand Up @@ -97,7 +99,12 @@ where
fn create_edge_set_intersector() -> Box<dyn EdgeSetIntersector<F>> {
// PERF: faster algorithms exist. This one was chosen for simplicity of implementation and
// debugging
Box::new(SimpleEdgeSetIntersector::new())
// Slow, but simple and good for debugging
// Box::new(SimpleEdgeSetIntersector::new())

// Should be much faster for sparse intersections, while not much slower than
// SimpleEdgeSetIntersector in the dense case
Box::new(RstarEdgeSetIntersector::new())
}

fn boundary_nodes(&self) -> impl Iterator<Item = &CoordNode<F>> {
Expand Down
2 changes: 2 additions & 0 deletions geo/src/algorithm/relate/geomgraph/index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod edge_set_intersector;
mod rstar_edge_set_intersector;
mod segment_intersector;
mod simple_edge_set_intersector;

pub(crate) use edge_set_intersector::EdgeSetIntersector;
pub(crate) use rstar_edge_set_intersector::RstarEdgeSetIntersector;
pub(crate) use segment_intersector::SegmentIntersector;
pub(crate) use simple_edge_set_intersector::SimpleEdgeSetIntersector;
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use super::super::Edge;
use super::{EdgeSetIntersector, SegmentIntersector};
use crate::GeoFloat;

use std::cell::RefCell;
use std::rc::Rc;

pub(crate) struct RstarEdgeSetIntersector;

impl RstarEdgeSetIntersector {
pub fn new() -> Self {
RstarEdgeSetIntersector
}

fn compute_intersects<F: GeoFloat>(
&mut self,
edge0: &Rc<RefCell<Edge<F>>>,
edge1: &Rc<RefCell<Edge<F>>>,
segment_intersector: &mut SegmentIntersector<F>,
) {
let edge0_coords_len = edge0.borrow().coords().len() - 1;
let edge1_coords_len = edge1.borrow().coords().len() - 1;
for i0 in 0..edge0_coords_len {
for i1 in 0..edge1_coords_len {
segment_intersector.add_intersections(edge0, i0, edge1, i1);
}
}
}
}

impl<F: GeoFloat> EdgeSetIntersector<F> for RstarEdgeSetIntersector {
fn compute_intersections_within_set(
&mut self,
edges: &[Rc<RefCell<Edge<F>>>],
check_for_self_intersecting_edges: bool,
segment_intersector: &mut SegmentIntersector<F>,
) {
for edge0 in edges.iter() {
for edge1 in edges.iter() {
if check_for_self_intersecting_edges || edge0.as_ptr() != edge1.as_ptr() {
self.compute_intersects(edge0, edge1, segment_intersector);
}
}
}
}

fn compute_intersections_between_sets(
&mut self,
edges0: &[Rc<RefCell<Edge<F>>>],
edges1: &[Rc<RefCell<Edge<F>>>],
segment_intersector: &mut SegmentIntersector<F>,
) {
for edge0 in edges0 {
for edge1 in edges1 {
self.compute_intersects(edge0, edge1, segment_intersector);
}
}
}
}

0 comments on commit 3ec60bf

Please sign in to comment.