@@ -395,29 +395,50 @@ def index_from_nearest_path_with_pt_in_bbox(
395
395
cdef DTYPE_ui i_start_c, i_end_c, i_elt_c, i_start_pt, i_end_pt, i_elt_pt
396
396
cdef DTYPE_ui i_ref, nb_contour, find_contour
397
397
cdef DTYPE_coord dist_ref, dist
398
- find_contour = 0
399
- i_start_c = l_i[level_index]
398
+ # Nb contour in level
400
399
nb_contour = nb_c_per_l[level_index]
401
400
if nb_contour == 0 :
402
401
return None
402
+ # First contour in level
403
+ i_start_c = l_i[level_index]
404
+ # First contour of the next level
403
405
i_end_c = i_start_c + nb_c_per_l[level_index]
404
406
407
+ # Flag to check if we iterate
408
+ find_contour = 0
409
+ # We select the first pt of the first contour in the level
410
+ # to initialize dist
405
411
i_ref = i_start_c
406
412
i_start_pt = indices_of_first_pts[i_start_c]
407
413
dist_ref = (x_value[i_start_pt] - xpt) ** 2 + (y_value[i_start_pt] - ypt) ** 2
408
414
415
+ # We iterate over contour in the same level
409
416
for i_elt_c from i_start_c <= i_elt_c < i_end_c:
410
- if x_min_per_c[i_elt_c] > xpt or x_max_per_c[i_elt_c] < xpt or y_min_per_c[i_elt_c] > ypt or y_max_per_c[i_elt_c] < ypt:
417
+ # if bbox of contour doesn't contain pt, we skip this contour
418
+ if x_min_per_c[i_elt_c] > xpt:
419
+ continue
420
+ if x_max_per_c[i_elt_c] < xpt:
421
+ continue
422
+ if y_min_per_c[i_elt_c] > ypt:
423
+ continue
424
+ if y_max_per_c[i_elt_c] < ypt:
411
425
continue
426
+ # Indice of first pt of contour
412
427
i_start_pt = indices_of_first_pts[i_elt_c]
428
+ # Indice of first pt of the next contour
413
429
i_end_pt = i_start_pt + nb_pt_per_c[i_elt_c]
430
+ # We set flag to true, because we check contour
414
431
find_contour = 1
415
432
433
+ # We do iteration on pt to check dist, if it's inferior we store
434
+ # index of contour
416
435
for i_elt_pt from i_start_pt <= i_elt_pt < i_end_pt:
417
436
dist = (x_value[i_elt_pt] - xpt) ** 2 + (y_value[i_elt_pt] - ypt) ** 2
418
437
if dist < dist_ref:
419
438
dist_ref = dist
420
439
i_ref = i_elt_c
440
+ # No iteration on contour, we return no index of contour
421
441
if find_contour == 0 :
422
442
return None
443
+ # We return index of contour, for the specific level
423
444
return i_ref - i_start_c
0 commit comments