From 1c9ef1b2019431145f324ff73f90573c6bef9caf Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Mon, 8 Jul 2024 08:00:39 +0200 Subject: [PATCH 01/17] geometry_graph: make Send (rm Rc + RefCell) --- geo/src/algorithm/relate/edge_end_builder.rs | 5 +++-- .../relate/geomgraph/geometry_graph.rs | 18 ++++++++-------- .../geomgraph/index/prepared_geometry.rs | 7 ++++--- .../geomgraph/index/segment_intersector.rs | 21 +++++++++---------- .../index/simple_edge_set_intersector.rs | 13 ++++++------ .../relate/geomgraph/planar_graph.rs | 15 ++++++------- geo/src/algorithm/relate/relate_operation.rs | 4 ++-- 7 files changed, 43 insertions(+), 40 deletions(-) diff --git a/geo/src/algorithm/relate/edge_end_builder.rs b/geo/src/algorithm/relate/edge_end_builder.rs index 4fcaf93c1d..fdaca8e8a7 100644 --- a/geo/src/algorithm/relate/edge_end_builder.rs +++ b/geo/src/algorithm/relate/edge_end_builder.rs @@ -2,7 +2,8 @@ use super::geomgraph::{Edge, EdgeEnd, EdgeIntersection}; use crate::GeoFloat; use std::cell::RefCell; -use std::rc::Rc; +// use std::rc::Rc; +use std::sync::Arc; /// Computes the [`EdgeEnd`]s which arise from an [`Edge`] who has had its `edge_intersections` /// populated with self and proper [`EdgeIntersection`]s. @@ -19,7 +20,7 @@ impl EdgeEndBuilder { } } - pub fn compute_ends_for_edges(&self, edges: &[Rc>>]) -> Vec> { + pub fn compute_ends_for_edges(&self, edges: &[Arc>>]) -> Vec> { let mut list = vec![]; for edge in edges { self.compute_ends_for_edge(&mut edge.borrow_mut(), &mut list); diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 6746dc8ac3..44f925cdf6 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -10,8 +10,9 @@ use crate::HasDimensions; use crate::{Coord, GeoFloat, GeometryCow, Line, LineString, Point, Polygon}; use rstar::{RTree, RTreeNum}; -use std::cell::RefCell; -use std::rc::Rc; +// use std::cell::RefCell; +// use std::rc::Rc; +use std::sync::Arc; /// The computation of the [`IntersectionMatrix`](crate::algorithm::relate::IntersectionMatrix) relies on the use of a /// structure called a "topology graph". The topology graph contains nodes (CoordNode) and @@ -35,7 +36,7 @@ where { arg_index: usize, parent_geometry: GeometryCow<'a, F>, - tree: Option>>>, + tree: Option>>>, use_boundary_determination_rule: bool, has_computed_self_nodes: bool, planar_graph: PlanarGraph, @@ -49,14 +50,14 @@ impl GeometryGraph<'_, F> where F: GeoFloat, { - pub(crate) fn set_tree(&mut self, tree: Rc>>) { + pub(crate) fn set_tree(&mut self, tree: Arc>>) { self.tree = Some(tree); } - pub(crate) fn get_or_build_tree(&self) -> Rc>> { + pub(crate) fn get_or_build_tree(&self) -> Arc>> { self.tree .clone() - .unwrap_or_else(|| Rc::new(self.build_tree())) + .unwrap_or_else(|| Arc::new(self.build_tree())) } pub(crate) fn build_tree(&self) -> RTree> { @@ -65,7 +66,7 @@ where .iter() .enumerate() .flat_map(|(edge_idx, edge)| { - let edge = RefCell::borrow(edge); + // let edge = RefCell::borrow(edge); let start_of_final_segment: usize = edge.coords().len() - 1; (0..start_of_final_segment).map(move |segment_idx| { let p1 = edge.coords()[segment_idx]; @@ -105,7 +106,7 @@ where } } - pub(crate) fn edges(&self) -> &[Rc>>] { + pub(crate) fn edges(&self) -> &[Edge] { self.planar_graph.edges() } @@ -404,7 +405,6 @@ where let positions_and_intersections: Vec<(CoordPos, Vec>)> = self .edges() .iter() - .map(|cell| cell.borrow()) .map(|edge| { let position = edge .label() diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index 2fbc199e21..e5e54841a7 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -5,7 +5,8 @@ use crate::GeometryCow; use crate::{GeoFloat, Relate}; use std::cell::RefCell; -use std::rc::Rc; +// use std::rc::Rc; +use std::sync::Arc; use rstar::{RTree, RTreeNum}; @@ -38,7 +39,7 @@ mod conversions { Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle, }; - use std::rc::Rc; + use std::sync::Arc; impl<'a, F: GeoFloat> From> for PreparedGeometry<'a, F> { fn from(point: Point) -> Self { @@ -156,7 +157,7 @@ mod conversions { impl<'a, F: GeoFloat> From> for PreparedGeometry<'a, F> { fn from(geometry: GeometryCow<'a, F>) -> Self { let mut geometry_graph = GeometryGraph::new(0, geometry); - geometry_graph.set_tree(Rc::new(geometry_graph.build_tree())); + geometry_graph.set_tree(Arc::new(geometry_graph.build_tree())); // TODO: don't pass in line intersector here - in theory we'll want pluggable line intersectors // and the type (Robust) shouldn't be hard coded here. diff --git a/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs index 933281d022..868b5915ab 100644 --- a/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs @@ -64,12 +64,12 @@ where fn is_trivial_intersection( &self, intersection: LineIntersection, - edge0: &RefCell>, + edge0: &Edge, segment_index_0: usize, - edge1: &RefCell>, + edge1: &Edge, segment_index_1: usize, ) -> bool { - if edge0.as_ptr() != edge1.as_ptr() { + if !std::ptr::eq(edge0, edge1) { return false; } @@ -81,7 +81,6 @@ where return true; } - let edge0 = edge0.borrow(); if edge0.is_closed() { // first and last coords in a ring are adjacent let max_segment_index = edge0.coords().len() - 1; @@ -97,23 +96,23 @@ where pub fn add_intersections( &mut self, - edge0: &RefCell>, + edge0: &Edge, segment_index_0: usize, - edge1: &RefCell>, + edge1: &Edge, segment_index_1: usize, ) { // avoid a segment spuriously "intersecting" with itself - if edge0.as_ptr() == edge1.as_ptr() && segment_index_0 == segment_index_1 { + if std::ptr::eq(edge0, edge1) && segment_index_0 == segment_index_1 { return; } let line_0 = Line::new( - edge0.borrow().coords()[segment_index_0], - edge0.borrow().coords()[segment_index_0 + 1], + edge0.coords()[segment_index_0], + edge0.coords()[segment_index_0 + 1], ); let line_1 = Line::new( - edge1.borrow().coords()[segment_index_1], - edge1.borrow().coords()[segment_index_1 + 1], + edge1.coords()[segment_index_1], + edge1.coords()[segment_index_1 + 1], ); let intersection = self.line_intersector.compute_intersection(line_0, line_1); diff --git a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs index a735934465..15beefd8ee 100644 --- a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs @@ -3,7 +3,8 @@ use super::{EdgeSetIntersector, SegmentIntersector}; use crate::GeoFloat; use std::cell::RefCell; -use std::rc::Rc; +// use std::rc::Rc; +use std::sync::Arc; pub(crate) struct SimpleEdgeSetIntersector; @@ -14,8 +15,8 @@ impl SimpleEdgeSetIntersector { fn compute_intersects( &self, - edge0: &Rc>>, - edge1: &Rc>>, + edge0: &Arc>>, + edge1: &Arc>>, segment_intersector: &mut SegmentIntersector, ) { let edge0_coords_len = edge0.borrow().coords().len() - 1; @@ -31,13 +32,13 @@ impl SimpleEdgeSetIntersector { impl EdgeSetIntersector for SimpleEdgeSetIntersector { fn compute_intersections_within_set( &self, - graph: &GeometryGraph, + graph: &mut GeometryGraph, check_for_self_intersecting_edges: bool, segment_intersector: &mut SegmentIntersector, ) { let edges = graph.edges(); - for edge0 in edges.iter() { - for edge1 in edges.iter() { + for edge0 in edges.iter_mut() { + for edge1 in edges.iter_mut() { if check_for_self_intersecting_edges || edge0.as_ptr() != edge1.as_ptr() { self.compute_intersects(edge0, edge1, segment_intersector); } diff --git a/geo/src/algorithm/relate/geomgraph/planar_graph.rs b/geo/src/algorithm/relate/geomgraph/planar_graph.rs index 454e410f19..7d1c18dd71 100644 --- a/geo/src/algorithm/relate/geomgraph/planar_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/planar_graph.rs @@ -4,8 +4,9 @@ use super::{ }; use crate::{Coord, GeoFloat}; -use std::cell::RefCell; -use std::rc::Rc; +// use std::cell::RefCell; +// use std::rc::Rc; +use std::sync::Arc; #[derive(Clone, PartialEq)] pub(crate) struct PlanarGraphNode; @@ -24,7 +25,7 @@ where #[derive(Clone, PartialEq)] pub(crate) struct PlanarGraph { pub(crate) nodes: NodeMap, - edges: Vec>>>, + edges: Vec>, } impl PlanarGraph { @@ -35,7 +36,7 @@ impl PlanarGraph { edges: self .edges .iter() - .map(|e| Rc::new(RefCell::new(e.borrow().clone()))) + .map(|e| e.clone()) .collect(), }; assert_eq!(from_arg_index, 0); @@ -50,7 +51,7 @@ impl PlanarGraph { node.swap_label_args(); } for edge in &mut self.edges { - edge.borrow_mut().swap_label_args(); + edge.swap_label_args(); } } @@ -59,7 +60,7 @@ impl PlanarGraph { assert_eq!(self.edges, other.edges); } - pub fn edges(&self) -> &[Rc>>] { + pub fn edges(&self) -> &[Edge] { &self.edges } @@ -79,7 +80,7 @@ impl PlanarGraph { } pub fn insert_edge(&mut self, edge: Edge) { - self.edges.push(Rc::new(RefCell::new(edge))); + self.edges.push(edge); } pub fn add_node_with_coordinate(&mut self, coord: Coord) -> &mut CoordNode { diff --git a/geo/src/algorithm/relate/relate_operation.rs b/geo/src/algorithm/relate/relate_operation.rs index 061bb29199..badce014ae 100644 --- a/geo/src/algorithm/relate/relate_operation.rs +++ b/geo/src/algorithm/relate/relate_operation.rs @@ -10,7 +10,7 @@ use crate::CoordinatePosition; use crate::{Coord, GeoFloat, GeometryCow}; use std::cell::RefCell; -use std::rc::Rc; +use std::sync::Arc; /// Computes an [`IntersectionMatrix`] describing the topological relationship between two /// Geometries. @@ -29,7 +29,7 @@ where graph_b: GeometryGraph<'a, F>, nodes: NodeMap, line_intersector: RobustLineIntersector, - isolated_edges: Vec>>>, + isolated_edges: Vec>>>, } #[derive(PartialEq)] From 40caee3487d877559152ef0401fd3acc1fb45298 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Mon, 8 Jul 2024 19:25:43 +0200 Subject: [PATCH 02/17] more &mut's rather than Rc. --- geo/src/algorithm/relate/edge_end_builder.rs | 4 +-- .../relate/geomgraph/geometry_graph.rs | 8 +++-- .../geomgraph/index/edge_set_intersector.rs | 6 ++-- .../index/rstar_edge_set_intersector.rs | 26 +++++++------- .../geomgraph/index/segment_intersector.rs | 16 ++++----- .../index/simple_edge_set_intersector.rs | 34 +++++++++++-------- .../relate/geomgraph/planar_graph.rs | 4 +++ geo/src/algorithm/relate/relate_operation.rs | 20 +++++------ 8 files changed, 63 insertions(+), 55 deletions(-) diff --git a/geo/src/algorithm/relate/edge_end_builder.rs b/geo/src/algorithm/relate/edge_end_builder.rs index fdaca8e8a7..4542639c69 100644 --- a/geo/src/algorithm/relate/edge_end_builder.rs +++ b/geo/src/algorithm/relate/edge_end_builder.rs @@ -20,10 +20,10 @@ impl EdgeEndBuilder { } } - pub fn compute_ends_for_edges(&self, edges: &[Arc>>]) -> Vec> { + pub fn compute_ends_for_edges(&self, edges: &mut [Edge]) -> Vec> { let mut list = vec![]; for edge in edges { - self.compute_ends_for_edge(&mut edge.borrow_mut(), &mut list); + self.compute_ends_for_edge(edge, &mut list); } list } diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 44f925cdf6..606b4880c1 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -110,6 +110,10 @@ where self.planar_graph.edges() } + pub(crate) fn edges_mut(&mut self) -> &mut [Edge] { + self.planar_graph.edges_mut() + } + pub(crate) fn insert_edge(&mut self, edge: Edge) { self.planar_graph.insert_edge(edge) } @@ -353,8 +357,8 @@ where } pub(crate) fn compute_edge_intersections( - &self, - other: &GeometryGraph, + &'a mut self, + other: &mut GeometryGraph<'a, F>, line_intersector: Box>, ) -> SegmentIntersector { let mut segment_intersector = SegmentIntersector::new(line_intersector, false); diff --git a/geo/src/algorithm/relate/geomgraph/index/edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/edge_set_intersector.rs index a1f81af66b..f5c89db6dc 100644 --- a/geo/src/algorithm/relate/geomgraph/index/edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/edge_set_intersector.rs @@ -14,7 +14,7 @@ pub(crate) trait EdgeSetIntersector { /// `segment_intersector`: the SegmentIntersector to use fn compute_intersections_within_set( &self, - graph: &GeometryGraph, + graph: &mut GeometryGraph, check_for_self_intersecting_edges: bool, segment_intersector: &mut SegmentIntersector, ); @@ -23,8 +23,8 @@ pub(crate) trait EdgeSetIntersector { /// the intersecting edges. fn compute_intersections_between_sets<'a>( &self, - graph_0: &GeometryGraph<'a, F>, - graph_1: &GeometryGraph<'a, F>, + graph_0: &mut GeometryGraph<'a, F>, + graph_1: &mut GeometryGraph<'a, F>, segment_intersector: &mut SegmentIntersector, ); } diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index 5c0190d33b..da8e3b062f 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -15,17 +15,19 @@ where { fn compute_intersections_within_set( &self, - graph: &GeometryGraph, + graph: &mut GeometryGraph, check_for_self_intersecting_edges: bool, segment_intersector: &mut SegmentIntersector, ) { - let edges = graph.edges(); - let tree = graph.get_or_build_tree(); + let mut edges = graph.edges_mut(); for (segment_0, segment_1) in tree.intersection_candidates_with_other_tree(&tree) { if check_for_self_intersecting_edges || segment_0.edge_idx != segment_1.edge_idx { - let edge_0 = &edges[segment_0.edge_idx]; - let edge_1 = &edges[segment_1.edge_idx]; + // use get_many_mut when available. + assert!(segment_1.edge_idx > segment_0.edge_idx); + let (e0, e1) = edges.split_at_mut(segment_0.edge_idx+1); + let edge_0 = &mut e0[segment_0.edge_idx]; + let edge_1 = &mut e1[segment_1.edge_idx-segment_0.edge_idx+1]; segment_intersector.add_intersections( edge_0, segment_0.segment_idx, @@ -38,19 +40,19 @@ where fn compute_intersections_between_sets<'a>( &self, - graph_0: &GeometryGraph<'a, F>, - graph_1: &GeometryGraph<'a, F>, + graph_0: &mut GeometryGraph<'a, F>, + graph_1: &mut GeometryGraph<'a, F>, segment_intersector: &mut SegmentIntersector, ) { - let edges_0 = graph_0.edges(); - let edges_1 = graph_1.edges(); - let tree_0 = graph_0.get_or_build_tree(); let tree_1 = graph_1.get_or_build_tree(); + let edges_0 = graph_0.edges_mut(); + let edges_1 = graph_1.edges_mut(); + for (segment_0, segment_1) in tree_0.intersection_candidates_with_other_tree(&tree_1) { - let edge_0 = &edges_0[segment_0.edge_idx]; - let edge_1 = &edges_1[segment_1.edge_idx]; + let edge_0 = &mut edges_0[segment_0.edge_idx]; + let edge_1 = &mut edges_1[segment_1.edge_idx]; segment_intersector.add_intersections( edge_0, segment_0.segment_idx, diff --git a/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs index 868b5915ab..2ce7d4d53b 100644 --- a/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs @@ -96,9 +96,9 @@ where pub fn add_intersections( &mut self, - edge0: &Edge, + edge0: &mut Edge, segment_index_0: usize, - edge1: &Edge, + edge1: &mut Edge, segment_index_1: usize, ) { // avoid a segment spuriously "intersecting" with itself @@ -123,8 +123,8 @@ where let intersection = intersection.unwrap(); if !self.edges_are_from_same_geometry { - edge0.borrow_mut().mark_as_unisolated(); - edge1.borrow_mut().mark_as_unisolated(); + edge0.mark_as_unisolated(); + edge1.mark_as_unisolated(); } if !self.is_trivial_intersection( intersection, @@ -136,13 +136,9 @@ where if self.edges_are_from_same_geometry || !intersection.is_proper() { // In the case of self-noding, `edge0` might alias `edge1`, so it's imperative that // the mutable borrows are short lived and do not overlap. - edge0 - .borrow_mut() - .add_intersections(intersection, line_0, segment_index_0); + edge0.add_intersections(intersection, line_0, segment_index_0); - edge1 - .borrow_mut() - .add_intersections(intersection, line_1, segment_index_1); + edge1.add_intersections(intersection, line_1, segment_index_1); } if let LineIntersection::SinglePoint { is_proper: true, diff --git a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs index 15beefd8ee..ca2867bdb1 100644 --- a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs @@ -15,12 +15,12 @@ impl SimpleEdgeSetIntersector { fn compute_intersects( &self, - edge0: &Arc>>, - edge1: &Arc>>, + edge0: &mut Edge, + edge1: &mut Edge, segment_intersector: &mut SegmentIntersector, ) { - let edge0_coords_len = edge0.borrow().coords().len() - 1; - let edge1_coords_len = edge1.borrow().coords().len() - 1; + let edge0_coords_len = edge0.coords().len() - 1; + let edge1_coords_len = edge1.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); @@ -36,24 +36,30 @@ impl EdgeSetIntersector for SimpleEdgeSetIntersector { check_for_self_intersecting_edges: bool, segment_intersector: &mut SegmentIntersector, ) { - let edges = graph.edges(); - for edge0 in edges.iter_mut() { - for edge1 in edges.iter_mut() { - if check_for_self_intersecting_edges || edge0.as_ptr() != edge1.as_ptr() { - self.compute_intersects(edge0, edge1, segment_intersector); - } + let edges = graph.edges_mut(); + for i in 0..edges.len() { + let (e0, e1) = edges.split_at_mut(i+1); + let (e0, edge0) = e0.split_at_mut(i); + let edge0 = &mut edge0[0]; + + if check_for_self_intersecting_edges { + self.compute_intersects(edge0, edge0, segment_intersector); + } + + for edge1 in e0.iter_mut().chain(e1) { + self.compute_intersects(edge0, edge1, segment_intersector); } } } fn compute_intersections_between_sets<'a>( &self, - graph_0: &GeometryGraph<'a, F>, - graph_1: &GeometryGraph<'a, F>, + graph_0: &mut GeometryGraph<'a, F>, + graph_1: &mut GeometryGraph<'a, F>, segment_intersector: &mut SegmentIntersector, ) { - let edges_0 = graph_0.edges(); - let edges_1 = graph_1.edges(); + let edges_0 = graph_0.edges_mut(); + let edges_1 = graph_1.edges_mut(); for edge0 in edges_0 { for edge1 in edges_1 { diff --git a/geo/src/algorithm/relate/geomgraph/planar_graph.rs b/geo/src/algorithm/relate/geomgraph/planar_graph.rs index 7d1c18dd71..1b4fc7ebc0 100644 --- a/geo/src/algorithm/relate/geomgraph/planar_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/planar_graph.rs @@ -64,6 +64,10 @@ impl PlanarGraph { &self.edges } + pub fn edges_mut(&mut self) -> &mut [Edge] { + &mut self.edges + } + pub fn new() -> Self { PlanarGraph { nodes: NodeMap::new(), diff --git a/geo/src/algorithm/relate/relate_operation.rs b/geo/src/algorithm/relate/relate_operation.rs index badce014ae..feecff92df 100644 --- a/geo/src/algorithm/relate/relate_operation.rs +++ b/geo/src/algorithm/relate/relate_operation.rs @@ -29,7 +29,7 @@ where graph_b: GeometryGraph<'a, F>, nodes: NodeMap, line_intersector: RobustLineIntersector, - isolated_edges: Vec>>>, + isolated_edges: Vec>, } #[derive(PartialEq)] @@ -87,7 +87,7 @@ where // compute intersections between edges of the two input geometries let segment_intersector = self .graph_a - .compute_edge_intersections(&self.graph_b, Box::new(self.line_intersector.clone())); + .compute_edge_intersections(&mut self.graph_b, Box::new(self.line_intersector.clone())); self.compute_intersection_nodes(0); self.compute_intersection_nodes(1); @@ -103,9 +103,9 @@ where // (eg where one or other of the geometries has a vertex at the intersection point) // We need to compute the edge graph at all nodes to determine the IM. let edge_end_builder = EdgeEndBuilder::new(); - let edge_ends_a: Vec<_> = edge_end_builder.compute_ends_for_edges(self.graph_a.edges()); + let edge_ends_a: Vec<_> = edge_end_builder.compute_ends_for_edges(self.graph_a.edges_mut()); self.insert_edge_ends(edge_ends_a); - let edge_ends_b: Vec<_> = edge_end_builder.compute_ends_for_edges(self.graph_b.edges()); + let edge_ends_b: Vec<_> = edge_end_builder.compute_ends_for_edges(self.graph_b.edges_mut()); self.insert_edge_ends(edge_ends_b); let mut nodes = NodeMap::new(); @@ -268,8 +268,6 @@ where }; for edge in graph.edges() { - let edge = edge.borrow(); - let edge_position = edge.label().on_position(geom_index); for edge_intersection in edge.edge_intersections() { let (new_node, _edges) = self @@ -294,8 +292,7 @@ where "before updated_intersection_matrix(isolated_edges): {:?}", intersection_matrix ); - for isolated_edge in &self.isolated_edges { - let edge = isolated_edge.borrow(); + for edge in &self.isolated_edges { Edge::::update_intersection_matrix(edge.label(), intersection_matrix); debug!( "after isolated_edge update_intersection_matrix: {:?}, (isolated_edge: {:?}, label: {:?})", @@ -324,10 +321,9 @@ where (&self.graph_b, &self.graph_a) }; - for edge in this_graph.edges() { - let mut mut_edge = edge.borrow_mut(); - if mut_edge.is_isolated() { - Self::label_isolated_edge(&mut mut_edge, target_index, target_graph.geometry()); + for edge in this_graph.edges_mut() { + if edge.is_isolated() { + Self::label_isolated_edge(&mut edge, target_index, target_graph.geometry()); self.isolated_edges.push(edge.clone()); } } From bb464fac3d772daa7e6f3d275d381917885d79ee Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Thu, 15 Aug 2024 16:30:23 +0200 Subject: [PATCH 03/17] it builds... --- .../relate/geomgraph/geometry_graph.rs | 2 +- .../index/rstar_edge_set_intersector.rs | 2 +- .../geomgraph/index/segment_intersector.rs | 60 +++++++++++++++++++ .../index/simple_edge_set_intersector.rs | 19 +++++- geo/src/algorithm/relate/relate_operation.rs | 35 ++++++++--- 5 files changed, 106 insertions(+), 12 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 606b4880c1..72482b8202 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -164,7 +164,7 @@ where } } - fn boundary_nodes(&self) -> impl Iterator> { + pub(crate) fn boundary_nodes(&self) -> impl Iterator> { self.planar_graph.boundary_nodes(self.arg_index) } diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index da8e3b062f..b79e08f61d 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -20,7 +20,7 @@ where segment_intersector: &mut SegmentIntersector, ) { let tree = graph.get_or_build_tree(); - let mut edges = graph.edges_mut(); + let edges = graph.edges_mut(); for (segment_0, segment_1) in tree.intersection_candidates_with_other_tree(&tree) { if check_for_self_intersecting_edges || segment_0.edge_idx != segment_1.edge_idx { // use get_many_mut when available. diff --git a/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs index 2ce7d4d53b..22fbc9b085 100644 --- a/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/segment_intersector.rs @@ -94,6 +94,66 @@ where false } + // Copy of `add_intersections` specialized for a single 'edge' against itself. + pub fn add_intersections_against_self( + &mut self, + edge0: &mut Edge, + segment_index_0: usize, + segment_index_1: usize, + ) { + // avoid a segment spuriously "intersecting" with itself + if segment_index_0 == segment_index_1 { + return; + } + + let line_0 = Line::new( + edge0.coords()[segment_index_0], + edge0.coords()[segment_index_0 + 1], + ); + let line_1 = Line::new( + edge0.coords()[segment_index_1], + edge0.coords()[segment_index_1 + 1], + ); + + let intersection = self.line_intersector.compute_intersection(line_0, line_1); + + if intersection.is_none() { + return; + } + let intersection = intersection.unwrap(); + + if !self.edges_are_from_same_geometry { + edge0.mark_as_unisolated(); + } + if !self.is_trivial_intersection( + intersection, + edge0, + segment_index_0, + edge0, + segment_index_1, + ) { + if self.edges_are_from_same_geometry || !intersection.is_proper() { + // In the case of self-noding, `edge0` might alias `edge1`, so it's imperative that + // the mutable borrows are short lived and do not overlap. + edge0.add_intersections(intersection, line_0, segment_index_0); + + // XXX: This may be a bug, but it matches the existing behavior. + edge0.add_intersections(intersection, line_1, segment_index_1); + } + if let LineIntersection::SinglePoint { + is_proper: true, + intersection: intersection_coord, + } = intersection + { + self.proper_intersection_point = Some(intersection_coord); + + if !self.is_boundary_point(&intersection_coord, &self.boundary_nodes) { + self.has_proper_interior_intersection = true + } + } + } + } + pub fn add_intersections( &mut self, edge0: &mut Edge, diff --git a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs index ca2867bdb1..19fa3556eb 100644 --- a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs @@ -27,6 +27,19 @@ impl SimpleEdgeSetIntersector { } } } + + fn compute_intersects_against_self( + &self, + edge0: &mut Edge, + segment_intersector: &mut SegmentIntersector, + ) { + let edge0_coords_len = edge0.coords().len() - 1; + for i0 in 0..edge0_coords_len { + for i1 in 0..edge0_coords_len { + segment_intersector.add_intersections_against_self(edge0, i0, i1); + } + } + } } impl EdgeSetIntersector for SimpleEdgeSetIntersector { @@ -38,12 +51,12 @@ impl EdgeSetIntersector for SimpleEdgeSetIntersector { ) { let edges = graph.edges_mut(); for i in 0..edges.len() { - let (e0, e1) = edges.split_at_mut(i+1); + let (e0, e1) = edges.split_at_mut(i + 1); let (e0, edge0) = e0.split_at_mut(i); let edge0 = &mut edge0[0]; if check_for_self_intersecting_edges { - self.compute_intersects(edge0, edge0, segment_intersector); + self.compute_intersects_against_self(edge0, segment_intersector); } for edge1 in e0.iter_mut().chain(e1) { @@ -62,7 +75,7 @@ impl EdgeSetIntersector for SimpleEdgeSetIntersector { let edges_1 = graph_1.edges_mut(); for edge0 in edges_0 { - for edge1 in edges_1 { + for edge1 in &mut *edges_1 { self.compute_intersects(edge0, edge1, segment_intersector); } } diff --git a/geo/src/algorithm/relate/relate_operation.rs b/geo/src/algorithm/relate/relate_operation.rs index feecff92df..78913a6851 100644 --- a/geo/src/algorithm/relate/relate_operation.rs +++ b/geo/src/algorithm/relate/relate_operation.rs @@ -58,7 +58,7 @@ where } } - pub(crate) fn compute_intersection_matrix(&mut self) -> IntersectionMatrix { + pub(crate) fn compute_intersection_matrix(&'a mut self) -> IntersectionMatrix { let mut intersection_matrix = IntersectionMatrix::empty_disjoint(); use crate::BoundingRect; @@ -85,18 +85,39 @@ where .compute_self_nodes(Box::new(self.line_intersector.clone())); // compute intersections between edges of the two input geometries - let segment_intersector = self - .graph_a - .compute_edge_intersections(&mut self.graph_b, Box::new(self.line_intersector.clone())); + // let segment_intersector = self + // .graph_a + // .compute_edge_intersections(&mut self.graph_b, Box::new(self.line_intersector.clone())); + + + // this is a copy of the above functionality to satisfy rust borrowing rules. + // from here [... + let mut segment_intersector = SegmentIntersector::new(Box::new(self.line_intersector.clone()), false); + segment_intersector.set_boundary_nodes( + self.graph_a.boundary_nodes().cloned().collect(), + self.graph_b.boundary_nodes().cloned().collect(), + ); + + use crate::relate::geomgraph::index::{EdgeSetIntersector, RStarEdgeSetIntersector}; + + let edge_set_intersector = RStarEdgeSetIntersector; + edge_set_intersector.compute_intersections_between_sets( + &mut self.graph_a, + &mut self.graph_b, + &mut segment_intersector, + ); + // to here ..] self.compute_intersection_nodes(0); self.compute_intersection_nodes(1); + // Copy the labelling for the nodes in the parent Geometries. These override any labels // determined by intersections between the geometries. self.copy_nodes_and_labels(0); self.copy_nodes_and_labels(1); // complete the labelling for any nodes which only have a label for a single geometry self.label_isolated_nodes(); + // If a proper intersection was found, we can set a lower bound on the IM. self.compute_proper_intersection_im(&segment_intersector, &mut intersection_matrix); // Now process improper intersections @@ -316,14 +337,14 @@ where /// not be isolated). fn label_isolated_edges(&mut self, this_index: usize, target_index: usize) { let (this_graph, target_graph) = if this_index == 0 { - (&self.graph_a, &self.graph_b) + (&mut self.graph_a, &self.graph_b) } else { - (&self.graph_b, &self.graph_a) + (&mut self.graph_b, &self.graph_a) }; for edge in this_graph.edges_mut() { if edge.is_isolated() { - Self::label_isolated_edge(&mut edge, target_index, target_graph.geometry()); + Self::label_isolated_edge(edge, target_index, target_graph.geometry()); self.isolated_edges.push(edge.clone()); } } From da14a970d486115954b43cbc971bd6a6158482aa Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Fri, 16 Aug 2024 10:07:03 +0200 Subject: [PATCH 04/17] rstar: handle check against same segment --- .../index/rstar_edge_set_intersector.rs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index b79e08f61d..84c3f1e9c5 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -23,17 +23,26 @@ where let edges = graph.edges_mut(); for (segment_0, segment_1) in tree.intersection_candidates_with_other_tree(&tree) { if check_for_self_intersecting_edges || segment_0.edge_idx != segment_1.edge_idx { - // use get_many_mut when available. - assert!(segment_1.edge_idx > segment_0.edge_idx); - let (e0, e1) = edges.split_at_mut(segment_0.edge_idx+1); - let edge_0 = &mut e0[segment_0.edge_idx]; - let edge_1 = &mut e1[segment_1.edge_idx-segment_0.edge_idx+1]; - segment_intersector.add_intersections( - edge_0, - segment_0.segment_idx, - edge_1, - segment_1.segment_idx, - ); + if segment_1.edge_idx == segment_0.edge_idx { + let edge_0 = &mut edges[segment_0.edge_idx]; + segment_intersector.add_intersections_against_self( + edge_0, + segment_0.edge_idx, + segment_1.edge_idx, + ); + } else { + // XXX: use get_many_mut when available. + let mi = segment_0.edge_idx.min(segment_1.edge_idx); + let mx = segment_0.edge_idx.max(segment_1.edge_idx); + + assert!(mx > mi); + + let (e0, e1) = edges.split_at_mut(mi + 1); + + let edge_0 = &mut e0[mi]; + let edge_1 = &mut e1[mx - (mi + 1)]; + segment_intersector.add_intersections(edge_0, mi, edge_1, mx); + } } } } From b26ba4c2ffbfa5400b140d02c1ffe34d5e2f5b08 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Fri, 16 Aug 2024 18:01:58 +0200 Subject: [PATCH 05/17] clone preparedgeom + flip add_intersections if necessary --- .../algorithm/relate/geomgraph/index/prepared_geometry.rs | 1 + .../relate/geomgraph/index/rstar_edge_set_intersector.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index e5e54841a7..8db6207339 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -27,6 +27,7 @@ use rstar::{RTree, RTreeNum}; /// assert!(prepared_polygon.relate(&contained_line).is_contains()); /// /// ``` +#[derive(Clone)] pub struct PreparedGeometry<'a, F: GeoFloat + RTreeNum = f64> { geometry_graph: GeometryGraph<'a, F>, } diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index 84c3f1e9c5..b53ad953a3 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -41,7 +41,12 @@ where let edge_0 = &mut e0[mi]; let edge_1 = &mut e1[mx - (mi + 1)]; - segment_intersector.add_intersections(edge_0, mi, edge_1, mx); + + if segment_0.edge_idx > segment_1.edge_idx { + segment_intersector.add_intersections(edge_1, mx, edge_0, mi); + } else { + segment_intersector.add_intersections(edge_0, mi, edge_1, mx); + } } } } From b141d5e82d89790dac67df21448ebf52802d4d60 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sat, 17 Aug 2024 09:10:36 +0200 Subject: [PATCH 06/17] geom graph: ensure the tree is always built --- .../relate/geomgraph/geometry_graph.rs | 26 ++++++++++++------- .../geomgraph/index/prepared_geometry.rs | 1 - .../index/rstar_edge_set_intersector.rs | 6 ++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 72482b8202..c2ecf513a2 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -50,17 +50,11 @@ impl GeometryGraph<'_, F> where F: GeoFloat, { - pub(crate) fn set_tree(&mut self, tree: Arc>>) { - self.tree = Some(tree); + pub(crate) fn get_tree(&self) -> Arc>> { + self.tree.as_ref().map(|t| Arc::clone(t)).unwrap() } - pub(crate) fn get_or_build_tree(&self) -> Arc>> { - self.tree - .clone() - .unwrap_or_else(|| Arc::new(self.build_tree())) - } - - pub(crate) fn build_tree(&self) -> RTree> { + fn build_tree(&self) -> RTree> { let segments: Vec> = self .edges() .iter() @@ -145,6 +139,20 @@ where planar_graph: PlanarGraph::new(), }; graph.add_geometry(&graph.parent_geometry.clone()); + graph.tree = Some(Arc::new(graph.build_tree())); + graph + } + + pub(crate) fn new_with_tree(arg_index: usize, parent_geometry: GeometryCow<'a, F>, tree: Arc>>) -> Self { + let mut graph = GeometryGraph { + arg_index, + parent_geometry, + use_boundary_determination_rule: true, + tree: Some(tree), + has_computed_self_nodes: false, + planar_graph: PlanarGraph::new(), + }; + graph.add_geometry(&graph.parent_geometry.clone()); graph } diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index 8db6207339..a6b1270869 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -158,7 +158,6 @@ mod conversions { impl<'a, F: GeoFloat> From> for PreparedGeometry<'a, F> { fn from(geometry: GeometryCow<'a, F>) -> Self { let mut geometry_graph = GeometryGraph::new(0, geometry); - geometry_graph.set_tree(Arc::new(geometry_graph.build_tree())); // TODO: don't pass in line intersector here - in theory we'll want pluggable line intersectors // and the type (Robust) shouldn't be hard coded here. diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index b53ad953a3..dd65fdb03a 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -19,7 +19,7 @@ where check_for_self_intersecting_edges: bool, segment_intersector: &mut SegmentIntersector, ) { - let tree = graph.get_or_build_tree(); + let tree = graph.get_tree(); let edges = graph.edges_mut(); for (segment_0, segment_1) in tree.intersection_candidates_with_other_tree(&tree) { if check_for_self_intersecting_edges || segment_0.edge_idx != segment_1.edge_idx { @@ -58,8 +58,8 @@ where graph_1: &mut GeometryGraph<'a, F>, segment_intersector: &mut SegmentIntersector, ) { - let tree_0 = graph_0.get_or_build_tree(); - let tree_1 = graph_1.get_or_build_tree(); + let tree_0 = graph_0.get_tree(); + let tree_1 = graph_1.get_tree(); let edges_0 = graph_0.edges_mut(); let edges_1 = graph_1.edges_mut(); From bda1008c96415d9b0a337553972f74a3f74bea53 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sat, 17 Aug 2024 09:58:42 +0200 Subject: [PATCH 07/17] invalidate and rebuild tree if necessary --- .../relate/geomgraph/geometry_graph.rs | 52 +++++++++++++------ .../index/rstar_edge_set_intersector.rs | 10 ++-- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index c2ecf513a2..cde2186d6f 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -36,7 +36,7 @@ where { arg_index: usize, parent_geometry: GeometryCow<'a, F>, - tree: Option>>>, + tree: Option>>, use_boundary_determination_rule: bool, has_computed_self_nodes: bool, planar_graph: PlanarGraph, @@ -50,11 +50,29 @@ impl GeometryGraph<'_, F> where F: GeoFloat, { - pub(crate) fn get_tree(&self) -> Arc>> { - self.tree.as_ref().map(|t| Arc::clone(t)).unwrap() + pub(crate) fn get_tree(&mut self) -> &RTree> { + self.update_tree(); + self.tree.as_ref().unwrap() + } + + pub(crate) fn tree_and_edges_mut(&mut self) -> (&RTree>, &mut [Edge]) { + self.update_tree(); + let edges = self.planar_graph.edges_mut(); + (self.tree.as_ref().unwrap(), edges) + } + + fn update_tree(&mut self) { + if self.tree.is_none() { + self.tree = Some(self.build_tree()); + } + } + + fn invalidate_tree(&mut self) { + self.tree = None; } fn build_tree(&self) -> RTree> { + println!("build tree"); let segments: Vec> = self .edges() .iter() @@ -109,6 +127,7 @@ where } pub(crate) fn insert_edge(&mut self, edge: Edge) { + self.invalidate_tree(); self.planar_graph.insert_edge(edge) } @@ -117,6 +136,7 @@ where } pub(crate) fn add_node_with_coordinate(&mut self, coord: Coord) -> &mut CoordNode { + self.invalidate_tree(); self.planar_graph.add_node_with_coordinate(coord) } @@ -139,20 +159,6 @@ where planar_graph: PlanarGraph::new(), }; graph.add_geometry(&graph.parent_geometry.clone()); - graph.tree = Some(Arc::new(graph.build_tree())); - graph - } - - pub(crate) fn new_with_tree(arg_index: usize, parent_geometry: GeometryCow<'a, F>, tree: Arc>>) -> Self { - let mut graph = GeometryGraph { - arg_index, - parent_geometry, - use_boundary_determination_rule: true, - tree: Some(tree), - has_computed_self_nodes: false, - planar_graph: PlanarGraph::new(), - }; - graph.add_geometry(&graph.parent_geometry.clone()); graph } @@ -269,6 +275,8 @@ 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) { @@ -279,9 +287,11 @@ 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) { + self.invalidate_tree(); if line_string.is_empty() { return; } @@ -325,12 +335,14 @@ 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) { 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 @@ -362,6 +374,7 @@ where &mut segment_intersector, ); self.add_self_intersection_nodes(); + self.invalidate_tree(); } pub(crate) fn compute_edge_intersections( @@ -369,6 +382,7 @@ where other: &mut GeometryGraph<'a, F>, line_intersector: Box>, ) -> SegmentIntersector { + self.invalidate_tree(); let mut segment_intersector = SegmentIntersector::new(line_intersector, false); segment_intersector.set_boundary_nodes( self.boundary_nodes().cloned().collect(), @@ -388,6 +402,7 @@ where fn insert_point(&mut self, arg_index: usize, coord: Coord, position: CoordPos) { let node: &mut CoordNode = 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. @@ -411,6 +426,7 @@ 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) { @@ -436,6 +452,7 @@ where self.add_self_intersection_node(coordinate, position) } } + self.invalidate_tree(); } /// Add a node for a self-intersection. @@ -453,5 +470,6 @@ where } else { self.insert_point(self.arg_index, coord, position) } + self.invalidate_tree(); } } diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index dd65fdb03a..eed9986b5c 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -19,8 +19,7 @@ where check_for_self_intersecting_edges: bool, segment_intersector: &mut SegmentIntersector, ) { - let tree = graph.get_tree(); - let edges = graph.edges_mut(); + let (tree, edges) = graph.tree_and_edges_mut(); for (segment_0, segment_1) in tree.intersection_candidates_with_other_tree(&tree) { if check_for_self_intersecting_edges || segment_0.edge_idx != segment_1.edge_idx { if segment_1.edge_idx == segment_0.edge_idx { @@ -58,11 +57,8 @@ where graph_1: &mut GeometryGraph<'a, F>, segment_intersector: &mut SegmentIntersector, ) { - let tree_0 = graph_0.get_tree(); - let tree_1 = graph_1.get_tree(); - - let edges_0 = graph_0.edges_mut(); - let edges_1 = graph_1.edges_mut(); + let (tree_0, edges_0) = graph_0.tree_and_edges_mut(); + let (tree_1, edges_1) = graph_1.tree_and_edges_mut(); for (segment_0, segment_1) in tree_0.intersection_candidates_with_other_tree(&tree_1) { let edge_0 = &mut edges_0[segment_0.edge_idx]; From 067fa06357dc41497223894a57d7a1eaa888c59e Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sat, 17 Aug 2024 10:15:06 +0200 Subject: [PATCH 08/17] some checks on self interctin --- geo/src/algorithm/relate/geomgraph/geometry_graph.rs | 2 +- .../algorithm/relate/geomgraph/index/prepared_geometry.rs | 1 + .../relate/geomgraph/index/simple_edge_set_intersector.rs | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index cde2186d6f..53845da951 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -61,7 +61,7 @@ where (self.tree.as_ref().unwrap(), edges) } - fn update_tree(&mut self) { + pub(crate) fn update_tree(&mut self) { if self.tree.is_none() { self.tree = Some(self.build_tree()); } diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index a6b1270869..6b33b3af92 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -158,6 +158,7 @@ mod conversions { impl<'a, F: GeoFloat> From> for PreparedGeometry<'a, F> { fn from(geometry: GeometryCow<'a, F>) -> Self { let mut geometry_graph = GeometryGraph::new(0, geometry); + geometry_graph.update_tree(); // TODO: maybe unecessary // TODO: don't pass in line intersector here - in theory we'll want pluggable line intersectors // and the type (Robust) shouldn't be hard coded here. diff --git a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs index 19fa3556eb..c8524c0d32 100644 --- a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs @@ -50,9 +50,11 @@ impl EdgeSetIntersector for SimpleEdgeSetIntersector { segment_intersector: &mut SegmentIntersector, ) { let edges = graph.edges_mut(); + let mut checks = 0; for i in 0..edges.len() { let (e0, e1) = edges.split_at_mut(i + 1); let (e0, edge0) = e0.split_at_mut(i); + assert_eq!(edge0.len(), 1); let edge0 = &mut edge0[0]; if check_for_self_intersecting_edges { @@ -61,8 +63,12 @@ impl EdgeSetIntersector for SimpleEdgeSetIntersector { for edge1 in e0.iter_mut().chain(e1) { self.compute_intersects(edge0, edge1, segment_intersector); + checks += 1; } } + + println!("checks: {}", checks); + assert_eq!(checks, edges.len()*edges.len()); } fn compute_intersections_between_sets<'a>( From eeff4764c7645f793bdc8f17c763285c76c1e6f5 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sat, 17 Aug 2024 13:14:40 +0200 Subject: [PATCH 09/17] fix idx confusion --- .../relate/geomgraph/geometry_graph.rs | 1 - .../index/rstar_edge_set_intersector.rs | 18 ++++++++++++++---- .../index/simple_edge_set_intersector.rs | 7 +------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 53845da951..35bbf40768 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -72,7 +72,6 @@ where } fn build_tree(&self) -> RTree> { - println!("build tree"); let segments: Vec> = self .edges() .iter() diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index eed9986b5c..8c767849ae 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -26,8 +26,8 @@ where let edge_0 = &mut edges[segment_0.edge_idx]; segment_intersector.add_intersections_against_self( edge_0, - segment_0.edge_idx, - segment_1.edge_idx, + segment_0.segment_idx, + segment_1.segment_idx, ); } else { // XXX: use get_many_mut when available. @@ -42,9 +42,19 @@ where let edge_1 = &mut e1[mx - (mi + 1)]; if segment_0.edge_idx > segment_1.edge_idx { - segment_intersector.add_intersections(edge_1, mx, edge_0, mi); + segment_intersector.add_intersections( + edge_1, + segment_0.segment_idx, + edge_0, + segment_1.segment_idx, + ); } else { - segment_intersector.add_intersections(edge_0, mi, edge_1, mx); + segment_intersector.add_intersections( + edge_0, + segment_0.segment_idx, + edge_1, + segment_1.segment_idx, + ); } } } diff --git a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs index c8524c0d32..c7ce3da466 100644 --- a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs @@ -50,11 +50,10 @@ impl EdgeSetIntersector for SimpleEdgeSetIntersector { segment_intersector: &mut SegmentIntersector, ) { let edges = graph.edges_mut(); - let mut checks = 0; for i in 0..edges.len() { let (e0, e1) = edges.split_at_mut(i + 1); let (e0, edge0) = e0.split_at_mut(i); - assert_eq!(edge0.len(), 1); + debug_assert_eq!(edge0.len(), 1); let edge0 = &mut edge0[0]; if check_for_self_intersecting_edges { @@ -63,12 +62,8 @@ impl EdgeSetIntersector for SimpleEdgeSetIntersector { for edge1 in e0.iter_mut().chain(e1) { self.compute_intersects(edge0, edge1, segment_intersector); - checks += 1; } } - - println!("checks: {}", checks); - assert_eq!(checks, edges.len()*edges.len()); } fn compute_intersections_between_sets<'a>( From 3a281f0f684d5dd521cc6fcaea5055c26187c337 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sat, 17 Aug 2024 15:36:48 +0200 Subject: [PATCH 10/17] dbg + remove a bunch of (hopefully) unnecessary invalidates --- .../relate/geomgraph/geometry_graph.rs | 18 +++++------------- .../geomgraph/index/prepared_geometry.rs | 1 + 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 35bbf40768..d5fc0a8b35 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -68,10 +68,12 @@ where } fn invalidate_tree(&mut self) { + println!("invalidate tree"); self.tree = None; } fn build_tree(&self) -> RTree> { + println!("build tree: {}", self.edges().len()); let segments: Vec> = self .edges() .iter() @@ -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); @@ -135,7 +139,6 @@ where } pub(crate) fn add_node_with_coordinate(&mut self, coord: Coord) -> &mut CoordNode { - self.invalidate_tree(); self.planar_graph.add_node_with_coordinate(coord) } @@ -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, @@ -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) { @@ -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) { - self.invalidate_tree(); if line_string.is_empty() { return; } @@ -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) { 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 @@ -373,7 +371,6 @@ where &mut segment_intersector, ); self.add_self_intersection_nodes(); - self.invalidate_tree(); } pub(crate) fn compute_edge_intersections( @@ -381,7 +378,6 @@ where other: &mut GeometryGraph<'a, F>, line_intersector: Box>, ) -> SegmentIntersector { - self.invalidate_tree(); let mut segment_intersector = SegmentIntersector::new(line_intersector, false); segment_intersector.set_boundary_nodes( self.boundary_nodes().cloned().collect(), @@ -401,7 +397,6 @@ where fn insert_point(&mut self, arg_index: usize, coord: Coord, position: CoordPos) { let node: &mut CoordNode = 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. @@ -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) { @@ -451,7 +445,6 @@ where self.add_self_intersection_node(coordinate, position) } } - self.invalidate_tree(); } /// Add a node for a self-intersection. @@ -469,6 +462,5 @@ where } else { self.insert_point(self.arg_index, coord, position) } - self.invalidate_tree(); } } diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index 6b33b3af92..68d0650925 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -157,6 +157,7 @@ mod conversions { impl<'a, F: GeoFloat> From> 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 From f65e815a6448ec4d8741300762d2785cae67a2bf Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sun, 18 Aug 2024 08:33:23 +0200 Subject: [PATCH 11/17] remove printlns --- geo/src/algorithm/relate/geomgraph/geometry_graph.rs | 4 ---- geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs | 1 - 2 files changed, 5 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index d5fc0a8b35..3bf3e8e57f 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -68,12 +68,10 @@ where } fn invalidate_tree(&mut self) { - println!("invalidate tree"); self.tree = None; } fn build_tree(&self) -> RTree> { - println!("build tree: {}", self.edges().len()); let segments: Vec> = self .edges() .iter() @@ -102,7 +100,6 @@ 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" @@ -152,7 +149,6 @@ 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, diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index 68d0650925..6b33b3af92 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -157,7 +157,6 @@ mod conversions { impl<'a, F: GeoFloat> From> 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 From 8f47d5bb991f8ba4c9aada9611214ea4195555e4 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sun, 18 Aug 2024 08:58:45 +0200 Subject: [PATCH 12/17] fmt --- geo/src/algorithm/relate/geomgraph/planar_graph.rs | 6 +----- geo/src/algorithm/relate/relate_operation.rs | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/planar_graph.rs b/geo/src/algorithm/relate/geomgraph/planar_graph.rs index 1b4fc7ebc0..26e18d745f 100644 --- a/geo/src/algorithm/relate/geomgraph/planar_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/planar_graph.rs @@ -33,11 +33,7 @@ impl PlanarGraph { let mut graph = Self { nodes: self.nodes.clone(), // deep copy edges - edges: self - .edges - .iter() - .map(|e| e.clone()) - .collect(), + edges: self.edges.iter().map(|e| e.clone()).collect(), }; assert_eq!(from_arg_index, 0); if from_arg_index != to_arg_index { diff --git a/geo/src/algorithm/relate/relate_operation.rs b/geo/src/algorithm/relate/relate_operation.rs index 78913a6851..76881ffb1b 100644 --- a/geo/src/algorithm/relate/relate_operation.rs +++ b/geo/src/algorithm/relate/relate_operation.rs @@ -89,10 +89,10 @@ where // .graph_a // .compute_edge_intersections(&mut self.graph_b, Box::new(self.line_intersector.clone())); - // this is a copy of the above functionality to satisfy rust borrowing rules. // from here [... - let mut segment_intersector = SegmentIntersector::new(Box::new(self.line_intersector.clone()), false); + let mut segment_intersector = + SegmentIntersector::new(Box::new(self.line_intersector.clone()), false); segment_intersector.set_boundary_nodes( self.graph_a.boundary_nodes().cloned().collect(), self.graph_b.boundary_nodes().cloned().collect(), From d6023dfd98fc640491479370cd6cbcc012807d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Mon, 28 Oct 2024 21:00:00 +0000 Subject: [PATCH 13/17] Remove unused imports --- geo/src/algorithm/relate/edge_end_builder.rs | 4 ---- geo/src/algorithm/relate/relate_operation.rs | 3 --- 2 files changed, 7 deletions(-) diff --git a/geo/src/algorithm/relate/edge_end_builder.rs b/geo/src/algorithm/relate/edge_end_builder.rs index 4542639c69..597dbd5b47 100644 --- a/geo/src/algorithm/relate/edge_end_builder.rs +++ b/geo/src/algorithm/relate/edge_end_builder.rs @@ -1,10 +1,6 @@ use super::geomgraph::{Edge, EdgeEnd, EdgeIntersection}; use crate::GeoFloat; -use std::cell::RefCell; -// use std::rc::Rc; -use std::sync::Arc; - /// Computes the [`EdgeEnd`]s which arise from an [`Edge`] who has had its `edge_intersections` /// populated with self and proper [`EdgeIntersection`]s. /// diff --git a/geo/src/algorithm/relate/relate_operation.rs b/geo/src/algorithm/relate/relate_operation.rs index 76881ffb1b..285a7cd4cb 100644 --- a/geo/src/algorithm/relate/relate_operation.rs +++ b/geo/src/algorithm/relate/relate_operation.rs @@ -9,9 +9,6 @@ use crate::relate::geomgraph::{ use crate::CoordinatePosition; use crate::{Coord, GeoFloat, GeometryCow}; -use std::cell::RefCell; -use std::sync::Arc; - /// Computes an [`IntersectionMatrix`] describing the topological relationship between two /// Geometries. /// From 7494ea3a49a22b201cd205a492df346ea042c625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Mon, 28 Oct 2024 21:05:14 +0000 Subject: [PATCH 14/17] Remove unused imports and apply a nicer TODO --- geo/src/algorithm/relate/geomgraph/geometry_graph.rs | 2 -- geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs | 1 - .../relate/geomgraph/index/rstar_edge_set_intersector.rs | 2 +- .../relate/geomgraph/index/simple_edge_set_intersector.rs | 1 - geo/src/algorithm/relate/geomgraph/planar_graph.rs | 2 -- 5 files changed, 1 insertion(+), 7 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 3bf3e8e57f..e0f5065077 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -10,8 +10,6 @@ use crate::HasDimensions; use crate::{Coord, GeoFloat, GeometryCow, Line, LineString, Point, Polygon}; use rstar::{RTree, RTreeNum}; -// use std::cell::RefCell; -// use std::rc::Rc; use std::sync::Arc; /// The computation of the [`IntersectionMatrix`](crate::algorithm::relate::IntersectionMatrix) relies on the use of a diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index 6b33b3af92..422cc832b5 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -5,7 +5,6 @@ use crate::GeometryCow; use crate::{GeoFloat, Relate}; use std::cell::RefCell; -// use std::rc::Rc; use std::sync::Arc; use rstar::{RTree, RTreeNum}; diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index 8c767849ae..0a0498ba5f 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -30,7 +30,7 @@ where segment_1.segment_idx, ); } else { - // XXX: use get_many_mut when available. + // TODO: use get_many_mut when available. let mi = segment_0.edge_idx.min(segment_1.edge_idx); let mx = segment_0.edge_idx.max(segment_1.edge_idx); diff --git a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs index c7ce3da466..5bb9cb19f2 100644 --- a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs @@ -3,7 +3,6 @@ use super::{EdgeSetIntersector, SegmentIntersector}; use crate::GeoFloat; use std::cell::RefCell; -// use std::rc::Rc; use std::sync::Arc; pub(crate) struct SimpleEdgeSetIntersector; diff --git a/geo/src/algorithm/relate/geomgraph/planar_graph.rs b/geo/src/algorithm/relate/geomgraph/planar_graph.rs index 26e18d745f..5ce9baefdc 100644 --- a/geo/src/algorithm/relate/geomgraph/planar_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/planar_graph.rs @@ -4,8 +4,6 @@ use super::{ }; use crate::{Coord, GeoFloat}; -// use std::cell::RefCell; -// use std::rc::Rc; use std::sync::Arc; #[derive(Clone, PartialEq)] From 4ffeef553fa6dc464889cdfe21a7a7e4bb6cc618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Mon, 28 Oct 2024 21:10:33 +0000 Subject: [PATCH 15/17] Appease clippy --- .../relate/geomgraph/index/rstar_edge_set_intersector.rs | 4 ++-- geo/src/algorithm/relate/geomgraph/planar_graph.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs index 0a0498ba5f..92f0c6028d 100644 --- a/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/rstar_edge_set_intersector.rs @@ -20,7 +20,7 @@ where segment_intersector: &mut SegmentIntersector, ) { let (tree, edges) = graph.tree_and_edges_mut(); - for (segment_0, segment_1) in tree.intersection_candidates_with_other_tree(&tree) { + for (segment_0, segment_1) in tree.intersection_candidates_with_other_tree(tree) { if check_for_self_intersecting_edges || segment_0.edge_idx != segment_1.edge_idx { if segment_1.edge_idx == segment_0.edge_idx { let edge_0 = &mut edges[segment_0.edge_idx]; @@ -70,7 +70,7 @@ where let (tree_0, edges_0) = graph_0.tree_and_edges_mut(); let (tree_1, edges_1) = graph_1.tree_and_edges_mut(); - for (segment_0, segment_1) in tree_0.intersection_candidates_with_other_tree(&tree_1) { + for (segment_0, segment_1) in tree_0.intersection_candidates_with_other_tree(tree_1) { let edge_0 = &mut edges_0[segment_0.edge_idx]; let edge_1 = &mut edges_1[segment_1.edge_idx]; segment_intersector.add_intersections( diff --git a/geo/src/algorithm/relate/geomgraph/planar_graph.rs b/geo/src/algorithm/relate/geomgraph/planar_graph.rs index 5ce9baefdc..780c0f64fb 100644 --- a/geo/src/algorithm/relate/geomgraph/planar_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/planar_graph.rs @@ -31,7 +31,7 @@ impl PlanarGraph { let mut graph = Self { nodes: self.nodes.clone(), // deep copy edges - edges: self.edges.iter().map(|e| e.clone()).collect(), + edges: self.edges.to_vec(), }; assert_eq!(from_arg_index, 0); if from_arg_index != to_arg_index { From bdf9e510323ac11de6659ffc0fdcf36ee73de59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Mon, 28 Oct 2024 21:12:50 +0000 Subject: [PATCH 16/17] Remove another unneeded line --- geo/src/algorithm/relate/geomgraph/geometry_graph.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index e0f5065077..71b40e6f75 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -75,7 +75,6 @@ where .iter() .enumerate() .flat_map(|(edge_idx, edge)| { - // let edge = RefCell::borrow(edge); let start_of_final_segment: usize = edge.coords().len() - 1; (0..start_of_final_segment).map(move |segment_idx| { let p1 = edge.coords()[segment_idx]; From 87d3ff00854b9cc554809a90661c8797953fb218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Mon, 28 Oct 2024 22:03:40 +0000 Subject: [PATCH 17/17] More unneeded Arc removals --- geo/src/algorithm/relate/geomgraph/geometry_graph.rs | 1 - geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs | 1 - .../relate/geomgraph/index/simple_edge_set_intersector.rs | 1 - geo/src/algorithm/relate/geomgraph/planar_graph.rs | 2 -- 4 files changed, 5 deletions(-) diff --git a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs index 71b40e6f75..03250b48e6 100644 --- a/geo/src/algorithm/relate/geomgraph/geometry_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/geometry_graph.rs @@ -10,7 +10,6 @@ use crate::HasDimensions; use crate::{Coord, GeoFloat, GeometryCow, Line, LineString, Point, Polygon}; use rstar::{RTree, RTreeNum}; -use std::sync::Arc; /// The computation of the [`IntersectionMatrix`](crate::algorithm::relate::IntersectionMatrix) relies on the use of a /// structure called a "topology graph". The topology graph contains nodes (CoordNode) and diff --git a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs index 422cc832b5..d03d6b7003 100644 --- a/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs +++ b/geo/src/algorithm/relate/geomgraph/index/prepared_geometry.rs @@ -5,7 +5,6 @@ use crate::GeometryCow; use crate::{GeoFloat, Relate}; use std::cell::RefCell; -use std::sync::Arc; use rstar::{RTree, RTreeNum}; diff --git a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs index 5bb9cb19f2..9acf745f6e 100644 --- a/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs +++ b/geo/src/algorithm/relate/geomgraph/index/simple_edge_set_intersector.rs @@ -3,7 +3,6 @@ use super::{EdgeSetIntersector, SegmentIntersector}; use crate::GeoFloat; use std::cell::RefCell; -use std::sync::Arc; pub(crate) struct SimpleEdgeSetIntersector; diff --git a/geo/src/algorithm/relate/geomgraph/planar_graph.rs b/geo/src/algorithm/relate/geomgraph/planar_graph.rs index 780c0f64fb..f9b04ce475 100644 --- a/geo/src/algorithm/relate/geomgraph/planar_graph.rs +++ b/geo/src/algorithm/relate/geomgraph/planar_graph.rs @@ -4,8 +4,6 @@ use super::{ }; use crate::{Coord, GeoFloat}; -use std::sync::Arc; - #[derive(Clone, PartialEq)] pub(crate) struct PlanarGraphNode;