@@ -1041,18 +1041,24 @@ impl<Upstream> Iterator for StrokePathIter<'_, Upstream> {
10411041 type Item = ( Vec < ManipulatorGroup < PointId > > , bool ) ;
10421042
10431043 fn next ( & mut self ) -> Option < Self :: Item > {
1044- let current_start = if let Some ( ( index, _) ) = self . points . iter ( ) . enumerate ( ) . skip ( self . skip ) . find ( |( _, val) | val. connected ( ) == 1 ) {
1045- index
1046- } else {
1047- if !self . done_one {
1048- self . done_one = true ;
1049- self . skip = 0 ;
1050- }
1051- self . points . iter ( ) . enumerate ( ) . skip ( self . skip ) . find ( |( _, val) | val. connected ( ) > 0 ) ?. 0
1052- } ;
1053- self . skip = current_start + 1 ;
1044+ let mut current_start = None ;
1045+ // First iterate over the single connected points
1046+ if !self . done_one {
1047+ current_start = self . points . iter ( ) . enumerate ( ) . skip ( self . skip ) . find ( |( _, val) | val. connected ( ) == 1 ) ;
1048+ self . done_one = current_start. is_none ( ) ;
1049+ self . skip = current_start. map_or ( 0 , |( index, _) | index + 1 ) ;
1050+ }
1051+
1052+ // If we've already done the single connected, then go through looking at multi connected
1053+ if current_start. is_none ( ) {
1054+ current_start = self . points . iter ( ) . enumerate ( ) . skip ( self . skip ) . find ( |( _, val) | val. connected ( ) > 0 ) ;
1055+ self . skip = current_start. map_or ( self . points . len ( ) , |( index, _) | index) ;
1056+ }
1057+
1058+ // If there is no starting point, exit
1059+ let current_start = current_start?. 0 ;
10541060
1055- // There will always be one (seeing as we checked above)
1061+ // There will always be at least one segment connected to this one
10561062 let mut point_index = current_start;
10571063 let mut manipulators_list = Vec :: new ( ) ;
10581064 let mut in_handle = None ;
0 commit comments