Skip to content

Commit

Permalink
dbg + remove a bunch of (hopefully) unnecessary invalidates
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Aug 17, 2024
1 parent 5499af0 commit e56f5d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
18 changes: 5 additions & 13 deletions geo/src/algorithm/relate/geomgraph/geometry_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ where
}

fn invalidate_tree(&mut self) {
println!("invalidate tree");
self.tree = None;
}

fn build_tree(&self) -> RTree<Segment<F>> {
println!("build tree: {}", self.edges().len());
let segments: Vec<Segment<F>> = self
.edges()
.iter()
Expand Down Expand Up @@ -100,10 +102,12 @@ where
}

pub(crate) fn clone_for_arg_index(&self, arg_index: usize) -> Self {
println!("clone for arg");
debug_assert!(
self.has_computed_self_nodes,
"should only be called after computing self nodes"
);
debug_assert!(self.tree.is_some());
let planar_graph = self
.planar_graph
.clone_for_arg_index(self.arg_index, arg_index);
Expand Down Expand Up @@ -135,7 +139,6 @@ where
}

pub(crate) fn add_node_with_coordinate(&mut self, coord: Coord<F>) -> &mut CoordNode<F> {
self.invalidate_tree();
self.planar_graph.add_node_with_coordinate(coord)
}

Expand All @@ -149,6 +152,7 @@ where
F: GeoFloat + RTreeNum,
{
pub(crate) fn new(arg_index: usize, parent_geometry: GeometryCow<'a, F>) -> Self {
println!("new geom graph");
let mut graph = GeometryGraph {
arg_index,
parent_geometry,
Expand Down Expand Up @@ -274,8 +278,6 @@ where

// insert the endpoint as a node, to mark that it is on the boundary
self.insert_point(self.arg_index, first_point, CoordPos::OnBoundary);

self.invalidate_tree();
}

fn add_polygon(&mut self, polygon: &Polygon<F>) {
Expand All @@ -286,11 +288,9 @@ where
for hole in polygon.interiors() {
self.add_polygon_ring(hole, CoordPos::Inside, CoordPos::Outside)
}
self.invalidate_tree();
}

fn add_line_string(&mut self, line_string: &LineString<F>) {
self.invalidate_tree();
if line_string.is_empty() {
return;
}
Expand Down Expand Up @@ -334,14 +334,12 @@ where
);

self.insert_edge(edge);
self.invalidate_tree();
}

/// Add a point computed externally. The point is assumed to be a
/// Point Geometry part, which has a location of INTERIOR.
fn add_point(&mut self, point: &Point<F>) {
self.insert_point(self.arg_index, (*point).into(), CoordPos::Inside);
self.invalidate_tree();
}

/// Compute self-nodes, taking advantage of the Geometry type to minimize the number of
Expand Down Expand Up @@ -373,15 +371,13 @@ where
&mut segment_intersector,
);
self.add_self_intersection_nodes();
self.invalidate_tree();
}

pub(crate) fn compute_edge_intersections(
&'a mut self,
other: &mut GeometryGraph<'a, F>,
line_intersector: Box<dyn LineIntersector<F>>,
) -> SegmentIntersector<F> {
self.invalidate_tree();
let mut segment_intersector = SegmentIntersector::new(line_intersector, false);
segment_intersector.set_boundary_nodes(
self.boundary_nodes().cloned().collect(),
Expand All @@ -401,7 +397,6 @@ where
fn insert_point(&mut self, arg_index: usize, coord: Coord<F>, position: CoordPos) {
let node: &mut CoordNode<F> = self.add_node_with_coordinate(coord);
node.label_mut().set_on_position(arg_index, position);
self.invalidate_tree();
}

/// Add the boundary points of 1-dim (line) geometries.
Expand All @@ -425,7 +420,6 @@ where

let new_position = Self::determine_boundary(boundary_count);
label.set_on_position(arg_index, new_position);
self.invalidate_tree();
}

fn add_self_intersection_nodes(&mut self) {
Expand All @@ -451,7 +445,6 @@ where
self.add_self_intersection_node(coordinate, position)
}
}
self.invalidate_tree();
}

/// Add a node for a self-intersection.
Expand All @@ -469,6 +462,5 @@ where
} else {
self.insert_point(self.arg_index, coord, position)
}
self.invalidate_tree();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ mod conversions {

impl<'a, F: GeoFloat> From<GeometryCow<'a, F>> for PreparedGeometry<'a, F> {
fn from(geometry: GeometryCow<'a, F>) -> Self {
println!("new prepared geom");
let mut geometry_graph = GeometryGraph::new(0, geometry);
geometry_graph.update_tree(); // TODO: maybe unecessary

Expand Down

0 comments on commit e56f5d3

Please sign in to comment.