LineIndex#

class LineIndex(lines: Iterable[ndarray], reverse: bool = False)#

Wrapper to scipy.spatial.KDTree to facilitate systematic processing of a line collection.

Implementation note: we use the available bool array because deleting stuff from the index is costly.

Methods

_find_nearest_in_index

Check the N nearest lines, hopefully find one that is active.

_find_nearest_within_in_index

Find nearest in specific index.

_make_index

_reindex

find_nearest

find_nearest_within

Find the closest line, assuming a maximum admissible distance.

pop

pop_front

Parameters:
  • lines (Iterable[np.ndarray]) --

  • reverse (bool) --

Methods#

LineIndex._find_nearest_in_index(p: complex, index: KDTree) tuple[int | None, float]#

Check the N nearest lines, hopefully find one that is active.

Parameters:
Return type:

tuple[int | None, float]

LineIndex._find_nearest_within_in_index(p: complex, max_dist: float, index: KDTree) tuple[bool, int | None, float | None]#

Find nearest in specific index. Return (reindex, idx, dist) tuple, where reindex indicates if a reindex is needed.

Parameters:
Return type:

tuple[bool, int | None, float | None]

LineIndex._make_index() None#
Return type:

None

LineIndex._reindex() None#
Return type:

None

LineIndex.find_nearest(p: complex) tuple[int, bool]#
Parameters:

p (complex) --

Return type:

tuple[int, bool]

LineIndex.find_nearest_within(p: complex, max_dist: float) tuple[int | None, bool]#

Find the closest line, assuming a maximum admissible distance. Returns a tuple of (idx, reverse), where idx may be None if nothing is found. reverse indicates whether or not a line ending has been matched instead of a start. False is always returned if index was created with reverse=False.

Parameters:
Return type:

tuple[int | None, bool]

LineIndex.pop(idx: int) numpy.ndarray | None#
Parameters:

idx (int) --

Return type:

numpy.ndarray | None

LineIndex.pop_front() ndarray#
Return type:

ndarray