@@ -36,9 +36,8 @@ fn offset_prune_invalid_spatial(
3636 . filter ( |arc| arc. is_valid ( PRUNE_EPSILON ) )
3737 . collect ( ) ;
3838
39- // Build spatial index containing both polyarcs and offsets
40- let polyarc_count = polyarcs. len ( ) ;
41- let mut spatial_index = HilbertRTree :: with_capacity ( polyarc_count + offsets. len ( ) ) ;
39+ // Build spatial index containing only polyarcs (with expansion for search radius)
40+ let mut spatial_index = HilbertRTree :: with_capacity ( polyarcs. len ( ) ) ;
4241
4342 // Add polyarcs to index with offset + epsilon expansion (done once)
4443 let search_radius = off + PRUNE_EPSILON ;
@@ -47,19 +46,13 @@ fn offset_prune_invalid_spatial(
4746 spatial_index. add ( min_x, max_x, min_y, max_y) ;
4847 }
4948
50- // Add offsets to index
51- for arc in offsets. iter ( ) {
52- let ( min_x, max_x, min_y, max_y) = arc_bounds ( arc) ;
53- spatial_index. add ( min_x, max_x, min_y, max_y) ;
54- }
55-
5649 spatial_index. build ( ) ;
5750
5851 while offsets. len ( ) > 0 {
5952 let offset = offsets. pop ( ) . unwrap ( ) ;
6053 valid. push ( offset. clone ( ) ) ;
6154
62- // Query nearby arcs using spatial index
55+ // Query nearby polyarcs using spatial index
6356 let ( offset_min_x, offset_max_x, offset_min_y, offset_max_y) =
6457 arc_bounds ( & offset) ;
6558 let mut nearby_indices = Vec :: new ( ) ;
@@ -73,16 +66,14 @@ fn offset_prune_invalid_spatial(
7366
7467 // Check only nearby polyarcs for actual distance
7568 for idx in nearby_indices {
76- if idx < polyarc_count {
77- let p = & polyarcs[ idx] ;
78- if p. id == offset. id {
79- continue ; // skip self offsets
80- }
81- let dist = distance_element_element ( p, & offset) ;
82- if dist < off - PRUNE_EPSILON {
83- valid. pop ( ) ;
84- break ;
85- }
69+ let p = & polyarcs[ idx] ;
70+ if p. id == offset. id {
71+ continue ; // skip self offsets
72+ }
73+ let dist = distance_element_element ( p, & offset) ;
74+ if dist < off - PRUNE_EPSILON {
75+ valid. pop ( ) ;
76+ break ;
8677 }
8778 }
8879 }
0 commit comments