Skip to content

Commit

Permalink
Fix case where write_annotations might clear lines not entirely withi…
Browse files Browse the repository at this point in the history
…n the bounds.
  • Loading branch information
JoeStrout committed Jan 29, 2025
1 parent 7b5f74a commit c951ae6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions zetta_utils/db_annotations/precomp_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ def read(in_stream: IO[bytes]):
struct.unpack("<3f", in_stream.read(12)),
)

def in_bounds(self, bounds: VolumetricIndex):
def in_bounds(self, bounds: VolumetricIndex, strict=False):
"""
Return whether either end of this line is in the given bounds.
(Assumes our coordinates match that of the given VolumetricIndex.)
Check whether this line at all crosses (when strict=False), or
is entirely within (when strict=True), the given VolumetricIndex.
(Assumes our coordinates match that of the index.)
"""
if strict:
return bounds.contains(self.start) and bounds.contains(self.end)
return bounds.line_intersects(self.start, self.end)

def convert_coordinates(self, from_res: Vec3D, to_res: Vec3D):
Expand Down Expand Up @@ -672,7 +675,9 @@ def write_annotations(
old_data = read_lines(anno_file_path)
if clearing_idx:
old_data = list(
filter(lambda d: not d.in_bounds(clearing_idx), old_data)
filter(
lambda d: not d.in_bounds(clearing_idx, strict=True), old_data
)
)
chunk_data += old_data
limit = max(limit, len(chunk_data))
Expand Down

0 comments on commit c951ae6

Please sign in to comment.