@@ -108,14 +108,15 @@ where
108108 }
109109
110110 /// Returns a set of all components that match the given predicate, starting
111- /// from the component with the given `component_id`.
111+ /// from the component with the given `component_id`, in the given direction .
112112 ///
113113 /// If `follow_after_match` is `true`, the search continues deeper beyond
114114 /// the matching components.
115115 pub ( crate ) fn find_all (
116116 & self ,
117117 from : u64 ,
118118 mut pred : impl FnMut ( & N ) -> bool ,
119+ direction : petgraph:: Direction ,
119120 follow_after_match : bool ,
120121 ) -> Result < BTreeSet < u64 > , Error > {
121122 let index = self . node_indices . get ( & from) . ok_or_else ( || {
@@ -133,9 +134,7 @@ where
133134 }
134135 }
135136
136- let neighbors = self
137- . graph
138- . neighbors_directed ( index, petgraph:: Direction :: Outgoing ) ;
137+ let neighbors = self . graph . neighbors_directed ( index, direction) ;
139138 stack. extend ( neighbors) ;
140139 }
141140
@@ -353,37 +352,55 @@ mod tests {
353352 let ( components, connections) = nodes_and_edges ( ) ;
354353 let graph = ComponentGraph :: try_new ( components. clone ( ) , connections. clone ( ) ) ?;
355354
356- let found = graph. find_all ( graph. root_id , |x| x. is_meter ( ) , false ) ?;
355+ let found = graph. find_all (
356+ graph. root_id ,
357+ |x| x. is_meter ( ) ,
358+ petgraph:: Direction :: Outgoing ,
359+ false ,
360+ ) ?;
357361 assert_eq ! ( found, [ 2 ] . iter( ) . cloned( ) . collect( ) ) ;
358362
359- let found = graph. find_all ( graph. root_id , |x| x. is_meter ( ) , true ) ?;
363+ let found = graph. find_all (
364+ graph. root_id ,
365+ |x| x. is_meter ( ) ,
366+ petgraph:: Direction :: Outgoing ,
367+ true ,
368+ ) ?;
360369 assert_eq ! ( found, [ 2 , 3 , 6 ] . iter( ) . cloned( ) . collect( ) ) ;
361370
362371 let found = graph. find_all (
363372 graph. root_id ,
364373 |x| !x. is_grid ( ) && !graph. is_component_meter ( x. component_id ( ) ) . unwrap_or ( false ) ,
374+ petgraph:: Direction :: Outgoing ,
365375 true ,
366376 ) ?;
367377 assert_eq ! ( found, [ 2 , 4 , 5 , 7 , 8 ] . iter( ) . cloned( ) . collect( ) ) ;
368378
369379 let found = graph. find_all (
370380 6 ,
371381 |x| !x. is_grid ( ) && !graph. is_component_meter ( x. component_id ( ) ) . unwrap_or ( false ) ,
382+ petgraph:: Direction :: Outgoing ,
372383 true ,
373384 ) ?;
374385 assert_eq ! ( found, [ 7 , 8 ] . iter( ) . cloned( ) . collect( ) ) ;
375386
376387 let found = graph. find_all (
377388 graph. root_id ,
378389 |x| !x. is_grid ( ) && !graph. is_component_meter ( x. component_id ( ) ) . unwrap_or ( false ) ,
390+ petgraph:: Direction :: Outgoing ,
379391 false ,
380392 ) ?;
381393 assert_eq ! ( found, [ 2 ] . iter( ) . cloned( ) . collect( ) ) ;
382394
383- let found = graph. find_all ( graph. root_id , |_| true , false ) ?;
395+ let found = graph. find_all (
396+ graph. root_id ,
397+ |_| true ,
398+ petgraph:: Direction :: Outgoing ,
399+ false ,
400+ ) ?;
384401 assert_eq ! ( found, [ 1 ] . iter( ) . cloned( ) . collect( ) ) ;
385402
386- let found = graph. find_all ( 3 , |_| true , true ) ?;
403+ let found = graph. find_all ( 3 , |_| true , petgraph :: Direction :: Outgoing , true ) ?;
387404 assert_eq ! ( found, [ 3 , 4 , 5 ] . iter( ) . cloned( ) . collect( ) ) ;
388405
389406 Ok ( ( ) )
0 commit comments