Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions retailtree/retailtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def add_annotation(self, annotation):
self.annotations[annotation.id] = annotation

def get(self, id):
# type:(int) -> Annotation
# type:(int|str) -> Annotation
"""
Retrieve an annotation by its ID.

Args:
id (int): The ID of the annotation to retrieve.
id (int|str): The ID of the annotation to retrieve.

Returns:
The annotation corresponding to the provided ID.
Expand Down Expand Up @@ -76,7 +76,7 @@ def __get_neighbors_radius(self):
return radius

def __fetch_neighbors(self, id, radius=1):
# type:(int, int) -> list[tuple[float, Annotation]]
# type:(int|str, int) -> list[tuple[float, Annotation]]
radius = radius*self.__get_neighbors_radius()
neighbors = self.tree.get_all_in_range(
(self.annotations[id].x_mid, self.annotations[id].y_mid), radius)
Expand Down Expand Up @@ -116,12 +116,12 @@ def __fetching_ann_in_range(self, result_dict, min_angle, max_angle, result_lst)
return result_lst

def neighbors_wa(self, id, radius=1, amin=None, amax=None):
# type:(int, int, float, float) -> list[dict]
# type:(int|str, int, float, float) -> list[dict]
"""
Retrieves neighboring elements within a specified angle range around a given element.

Args:
id (int): The identifier of the central element.
id (int|str): The identifier of the central element.
radius (float, optional): The radius within which to search for neighbors. Defaults to 1.
amin (min_angle) (float, optional): The minimum angle in degree. Defaults to None.
amax (max_angle) (float, optional): The maximum angle in degree. Defaults to None.
Expand Down Expand Up @@ -150,14 +150,14 @@ def neighbors_wa(self, id, radius=1, amin=None, amax=None):
return result_lst

def neighbors(self, id, radius=1):
# type:(int, int) -> list[dict]
# type:(int|str, int) -> list[dict]
"""
Finds neighboring annotations within a specified radius of a given annotation.(Radius specified is taken as a square rather than a circle)

Uses a Vantage Point Tree (VPTree) to efficiently find annotations within the specified radius.

Args:
id (int): The ID of the annotation.
id (int|str): The ID of the annotation.
radius (float, optional): The relative radius within which to search. Defaults to 1.
If a value less than 1 is provided, it's multiplied by an internal factor.

Expand Down Expand Up @@ -189,14 +189,14 @@ def neighbors(self, id, radius=1):
return result_lst

def TBLR(self, id, radius=1, overlap=0.5):
# type:(int, int, float) -> (dict[str, int | bool] | str)
# type:(int|str, int, float) -> (dict[str, int | bool] | str)
"""
Computes top, bottom, left, and right connections for a given annotation within a specified radius.

Finds neighboring annotations within the radius, calculates connections based on overlap percentage, and returns the connections as a dictionary.

Args:
- id (int): The ID of the annotation.
- id (int|str): The ID of the annotation.
- radius (float, optional): The radius within which to search for neighboring annotations. Defaults to 1.
- overlap (float, optional): The overlap percentage used to compute connections. Defaults to 0.5.

Expand Down
6 changes: 3 additions & 3 deletions retailtree/structs/annotation_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Annotation:
Parameters
----------
- id:
Int. Id of the Annotation.
Int|Str. Id of the Annotation.
- x_min:
Float. Left-most coordinate of rectangular annotation.
- x_max:
Expand All @@ -26,8 +26,8 @@ class Annotation:
"""

def __init__(self, id, x_min, y_min, x_max, y_max, label=None, metadata=None):
# type:(int, float, float, float, float, Any , dict[Any, Any]) -> None
self.__id = int(id)
# type:(int|str, float, float, float, float, Any , dict[Any, Any]) -> None
self.__id = id if isinstance(id, str) else int(id)
self.__x_min = float(x_min)
self.__x_max = float(x_max)
self.__y_min = float(y_min)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(fname):

setup(
name="retailtree",
version="1.3.2",
version="1.3.3",
long_description=read("README.md"),
long_description_content_type='text/markdown',
packages=find_packages(),
Expand Down