@@ -38,17 +38,18 @@ pub fn collect_poly_collisions_in_detector_custom(
3838 #[ cfg( feature = "simd" ) ]
3939 collector. poles_soa . load ( & shape. surrogate ( ) . poles ) ;
4040
41- // Start off by checking a few poles to detect obvious collisions quickly
41+
4242 {
43- //TODO: clean this up
43+ // We start off by checking a few poles in order to detect obvious collisions quickly and quickly raise the loss.
44+ // Potentially allows us to fail fast (early terminate) without checking all edges.
45+ // We check poles until the area of the poles checked exceeds 50% of the shape.
4446 let area_threshold = shape. area * 0.5 / PI ;
4547 let mut area_sum = 0.0 ;
4648 for pole in shape. surrogate ( ) . poles . iter ( ) {
4749 cde. quadtree . collect_collisions ( pole, collector) ;
4850 if collector. early_terminate ( shape) { return ; }
4951 area_sum += pole. radius * pole. radius ;
5052 if area_sum > area_threshold {
51- // If the area of the poles exceeds 80% of the shape's area, we can stop early.
5253 break ;
5354 }
5455 }
@@ -57,7 +58,7 @@ pub fn collect_poly_collisions_in_detector_custom(
5758 // Find the virtual root of the quadtree for the shape's bounding box. So we do not have to start from the root every time.
5859 let v_quadtree = cde. get_virtual_root ( shape. bbox ) ;
5960
60- // Collect collisions for all edges .
61+ // Collect collisions for each edge of the polygon .
6162 // Iterate over them in a bit-reversed order to maximize detecting new hazards early.
6263 let custom_edge_iter = BitReversalIterator :: new ( shape. n_vertices ( ) )
6364 . map ( |i| shape. edge ( i) ) ;
@@ -66,7 +67,7 @@ pub fn collect_poly_collisions_in_detector_custom(
6667 if collector. early_terminate ( shape) { return ; }
6768 }
6869
69- //Check if there are any other collisions due to containment
70+ // Check if there are any other collisions due to containment
7071 for qt_haz in v_quadtree. hazards . iter ( ) {
7172 match & qt_haz. presence {
7273 // No need to check these, guaranteed to be detected by edge intersection
@@ -188,7 +189,8 @@ impl<'a> HazardCollector for SpecializedHazardCollector<'a> {
188189 }
189190
190191 fn remove_by_key ( & mut self , hkey : HazKey ) {
191- let ( _, idx) = self . detected . remove ( hkey) . expect ( "key should be present in the collector" ) ;
192+ let ( _, idx) = self . detected . remove ( hkey)
193+ . expect ( "key should be present in the collector" ) ;
192194 if idx < self . loss_cache . 0 {
193195 //wipe the cache if a hazard was removed that was in it
194196 self . loss_cache = ( 0 , 0.0 ) ;
0 commit comments