Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit ae891d8

Browse files
committed
boundaries to split lines Fix index out of range
1. **Empty List Check**: - At the start of the function, I added a condition to check if the `boundaries` list is empty. If it is, the function returns an empty list, preventing any further operations that would lead to index errors. 2. **Minimum Length Check**: - Although not strictly necessary after the empty check, I added a check to ensure that there is at least one tuple in the `boundaries`. This is more of a safeguard, as the first check already handles the empty case.
1 parent 20f578d commit ae891d8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

camelot/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,14 @@ def boundaries_to_split_lines(boundaries):
791791
List of coordinates representing the split points, each half way
792792
between boundaries
793793
"""
794+
# Check if boundaries list is empty
795+
if not boundaries:
796+
return []
797+
798+
# Check if boundaries have at least one tuple
799+
if len(boundaries) < 1:
800+
return []
801+
794802
# From the row boundaries, identify splits by getting the mid points
795803
# between the boundaries.
796804
anchors = list(
@@ -799,8 +807,13 @@ def boundaries_to_split_lines(boundaries):
799807
range(1, len(boundaries)),
800808
)
801809
)
810+
811+
# Insert the first boundary's left coordinate
802812
anchors.insert(0, boundaries[0][0])
813+
814+
# Append the last boundary's right coordinate
803815
anchors.append(boundaries[-1][1])
816+
804817
return anchors
805818

806819

0 commit comments

Comments
 (0)