@@ -1274,41 +1274,47 @@ def get_subpath_split_indices_from_points(
12741274 starts = points [::nppcc ]
12751275 ends = points [nppcc - 1 :: nppcc ]
12761276 # This ensures that there are no more starts than ends.
1277- # TODO: ends.shape[0] would be more efficient, but some test cases regarding
1278- # Flash and ShowPassing flash expect a Python list instead of an ndarray, so
1279- # ends.shape[0] breaks those test cases. Fix these inconsistencies.
1277+ # TODO: ends.shape[0] would be more efficient, but some test cases
1278+ # regarding Flash and ShowPassingFlash expect a Python list instead of
1279+ # an ndarray, so ends.shape[0] breaks those test cases.
1280+ # Fix these inconsistencies.
12801281 n_curves = len (ends )
12811282 starts = starts [:n_curves ]
12821283
1283- # DO NOT DELETE THIS! Or else, a [[0 0]] ndarray will be returned
1284- # for an empty list of points, when it should instead return [].
1284+ # Zero curves case: if nothing was done to handle this, the statement
1285+ # split_indices = np.empty((diff_indices.shape[0] + 1, 2), dtype=int)
1286+ # and later statements would incorrectly generate the ndarray [[0 0]],
1287+ # which WILL break other methods.
1288+ # Instead, an empty (0, 2)-shaped ndarray must be returned immediately.
12851289 if n_curves == 0 :
12861290 return np .empty ((0 , 2 ), dtype = int )
1291+ # Single curve case: are_points_different(starts[1:], ends[:-1]) will
1292+ # fail, so return immediately. The split indices are just [[0 nppcc]].
12871293 if n_curves == 1 :
12881294 return np .array ([[0 , nppcc ]])
12891295
12901296 if n_dims == 2 :
1291- is_equal = self .consider_points_equals_2d
1292- is_different = self .consider_points_different_2d
1297+ are_points_equal = self .consider_points_equals_2d
1298+ are_points_different = self .consider_points_different_2d
12931299 else :
1294- is_equal = self .consider_points_equals
1295- is_different = self .consider_points_different
1300+ are_points_equal = self .consider_points_equals
1301+ are_points_different = self .consider_points_different
12961302
1297- is_far = is_different (starts [1 :], ends [:- 1 ])
1298- aux = np .arange (1 , is_far .shape [0 ] + 1 )[is_far ]
1303+ diff_bools = are_points_different (starts [1 :], ends [:- 1 ])
1304+ diff_indices = np .arange (1 , diff_bools .shape [0 ] + 1 )[diff_bools ]
12991305
1300- split_indices = np .empty ((aux .shape [0 ] + 1 , 2 ), dtype = int )
1306+ split_indices = np .empty ((diff_indices .shape [0 ] + 1 , 2 ), dtype = int )
13011307 split_indices [0 , 0 ] = 0
1302- split_indices [1 :, 0 ] = aux
1303- split_indices [:- 1 , 1 ] = aux
1308+ split_indices [1 :, 0 ] = diff_indices
1309+ split_indices [:- 1 , 1 ] = diff_indices
13041310 split_indices [- 1 , 1 ] = n_curves
13051311
13061312 if strip_null_end_curves :
13071313 for i in range (split_indices .shape [0 ]):
13081314 start_i , end_i = split_indices [i ]
13091315 while (
13101316 end_i > start_i + 1
1311- and is_equal (
1317+ and are_points_equal (
13121318 points [nppcc * (end_i - 1 ) : nppcc * end_i ], ends [end_i - 2 ]
13131319 ).all ()
13141320 ):
0 commit comments