Skip to content

Commit 344ea40

Browse files
author
adelepoulle
committed
Comment
1 parent 70ac81e commit 344ea40

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/py_eddy_tracker/tools.pyx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,29 +395,50 @@ def index_from_nearest_path_with_pt_in_bbox(
395395
cdef DTYPE_ui i_start_c, i_end_c, i_elt_c, i_start_pt, i_end_pt, i_elt_pt
396396
cdef DTYPE_ui i_ref, nb_contour, find_contour
397397
cdef DTYPE_coord dist_ref, dist
398-
find_contour = 0
399-
i_start_c = l_i[level_index]
398+
# Nb contour in level
400399
nb_contour = nb_c_per_l[level_index]
401400
if nb_contour == 0:
402401
return None
402+
# First contour in level
403+
i_start_c = l_i[level_index]
404+
# First contour of the next level
403405
i_end_c = i_start_c + nb_c_per_l[level_index]
404406

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
405411
i_ref = i_start_c
406412
i_start_pt = indices_of_first_pts[i_start_c]
407413
dist_ref = (x_value[i_start_pt] - xpt) ** 2 + (y_value[i_start_pt] - ypt) ** 2
408414

415+
# We iterate over contour in the same level
409416
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:
411425
continue
426+
# Indice of first pt of contour
412427
i_start_pt = indices_of_first_pts[i_elt_c]
428+
# Indice of first pt of the next contour
413429
i_end_pt = i_start_pt + nb_pt_per_c[i_elt_c]
430+
# We set flag to true, because we check contour
414431
find_contour = 1
415432

433+
# We do iteration on pt to check dist, if it's inferior we store
434+
# index of contour
416435
for i_elt_pt from i_start_pt <= i_elt_pt < i_end_pt:
417436
dist = (x_value[i_elt_pt] - xpt) ** 2 + (y_value[i_elt_pt] - ypt) ** 2
418437
if dist < dist_ref:
419438
dist_ref = dist
420439
i_ref = i_elt_c
440+
# No iteration on contour, we return no index of contour
421441
if find_contour == 0:
422442
return None
443+
# We return index of contour, for the specific level
423444
return i_ref - i_start_c

0 commit comments

Comments
 (0)