Skip to content

Commit 9f43276

Browse files
Make code compatible with string annotation ids
1 parent 967622a commit 9f43276

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

retailtree/retailtree.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def add_annotation(self, annotation):
2828
self.annotations[annotation.id] = annotation
2929

3030
def get(self, id):
31-
# type:(int) -> Annotation
31+
# type:(int|str) -> Annotation
3232
"""
3333
Retrieve an annotation by its ID.
3434
3535
Args:
36-
id (int): The ID of the annotation to retrieve.
36+
id (int|str): The ID of the annotation to retrieve.
3737
3838
Returns:
3939
The annotation corresponding to the provided ID.
@@ -76,7 +76,7 @@ def __get_neighbors_radius(self):
7676
return radius
7777

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

118118
def neighbors_wa(self, id, radius=1, amin=None, amax=None):
119-
# type:(int, int, float, float) -> list[dict]
119+
# type:(int|str, int, float, float) -> list[dict]
120120
"""
121121
Retrieves neighboring elements within a specified angle range around a given element.
122122
123123
Args:
124-
id (int): The identifier of the central element.
124+
id (int|str): The identifier of the central element.
125125
radius (float, optional): The radius within which to search for neighbors. Defaults to 1.
126126
amin (min_angle) (float, optional): The minimum angle in degree. Defaults to None.
127127
amax (max_angle) (float, optional): The maximum angle in degree. Defaults to None.
@@ -150,14 +150,14 @@ def neighbors_wa(self, id, radius=1, amin=None, amax=None):
150150
return result_lst
151151

152152
def neighbors(self, id, radius=1):
153-
# type:(int, int) -> list[dict]
153+
# type:(int|str, int) -> list[dict]
154154
"""
155155
Finds neighboring annotations within a specified radius of a given annotation.(Radius specified is taken as a square rather than a circle)
156156
157157
Uses a Vantage Point Tree (VPTree) to efficiently find annotations within the specified radius.
158158
159159
Args:
160-
id (int): The ID of the annotation.
160+
id (int|str): The ID of the annotation.
161161
radius (float, optional): The relative radius within which to search. Defaults to 1.
162162
If a value less than 1 is provided, it's multiplied by an internal factor.
163163
@@ -189,14 +189,14 @@ def neighbors(self, id, radius=1):
189189
return result_lst
190190

191191
def TBLR(self, id, radius=1, overlap=0.5):
192-
# type:(int, int, float) -> (dict[str, int | bool] | str)
192+
# type:(int|str, int, float) -> (dict[str, int | bool] | str)
193193
"""
194194
Computes top, bottom, left, and right connections for a given annotation within a specified radius.
195195
196196
Finds neighboring annotations within the radius, calculates connections based on overlap percentage, and returns the connections as a dictionary.
197197
198198
Args:
199-
- id (int): The ID of the annotation.
199+
- id (int|str): The ID of the annotation.
200200
- radius (float, optional): The radius within which to search for neighboring annotations. Defaults to 1.
201201
- overlap (float, optional): The overlap percentage used to compute connections. Defaults to 0.5.
202202

retailtree/structs/annotation_struct.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Annotation:
99
Parameters
1010
----------
1111
- id:
12-
Int. Id of the Annotation.
12+
Int|Str. Id of the Annotation.
1313
- x_min:
1414
Float. Left-most coordinate of rectangular annotation.
1515
- x_max:
@@ -26,8 +26,8 @@ class Annotation:
2626
"""
2727

2828
def __init__(self, id, x_min, y_min, x_max, y_max, label=None, metadata=None):
29-
# type:(int, float, float, float, float, Any , dict[Any, Any]) -> None
30-
self.__id = int(id)
29+
# type:(int|str, float, float, float, float, Any , dict[Any, Any]) -> None
30+
self.__id = id if isinstance(id, str) else int(id)
3131
self.__x_min = float(x_min)
3232
self.__x_max = float(x_max)
3333
self.__y_min = float(y_min)

0 commit comments

Comments
 (0)