6
6
from ..graphics ._collection_base import GraphicCollection
7
7
8
8
9
- def get_nearest_graphics (
9
+ def get_nearest_graphics_indices (
10
10
pos : tuple [float , float ] | tuple [float , float , float ],
11
11
graphics : Sequence [Graphic ] | GraphicCollection ,
12
- ) -> np .ndarray [Graphic ]:
12
+ ) -> np .ndarray [int ]:
13
13
"""
14
- Returns the nearest ``graphics`` to the passed position ``pos`` in world space.
15
- Uses the distance between ``pos`` and the center of the bounding sphere for each graphic.
14
+ Returns indices of the nearest ``graphics`` to the passed position ``pos`` in world space
15
+ in order of closest to furtherst. Uses the distance between ``pos`` and the center of the
16
+ bounding sphere for each graphic.
16
17
17
18
Parameters
18
19
----------
@@ -25,11 +26,10 @@ def get_nearest_graphics(
25
26
26
27
Returns
27
28
-------
28
- tuple[Graphic ]
29
- nearest graphics to ``pos`` in order
29
+ ndarray[int ]
30
+ indices of the nearest nearest graphics to ``pos`` in order
30
31
31
32
"""
32
-
33
33
if isinstance (graphics , GraphicCollection ):
34
34
graphics = graphics .graphics
35
35
@@ -50,4 +50,31 @@ def get_nearest_graphics(
50
50
distances = np .linalg .norm (centers [:, : len (pos )] - pos , ord = 2 , axis = 1 )
51
51
52
52
sort_indices = np .argsort (distances )
53
+ return sort_indices
54
+
55
+
56
+ def get_nearest_graphics (
57
+ pos : tuple [float , float ] | tuple [float , float , float ],
58
+ graphics : Sequence [Graphic ] | GraphicCollection ,
59
+ ) -> np .ndarray [Graphic ]:
60
+ """
61
+ Returns the nearest ``graphics`` to the passed position ``pos`` in world space.
62
+ Uses the distance between ``pos`` and the center of the bounding sphere for each graphic.
63
+
64
+ Parameters
65
+ ----------
66
+ pos: (x, y) | (x, y, z)
67
+ position in world space, z-axis is ignored when calculating L2 norms if ``pos`` is 2D
68
+
69
+ graphics: Sequence, i.e. array, list, tuple, etc. of Graphic | GraphicCollection
70
+ the graphics from which to return a sorted array of graphics in order of closest
71
+ to furthest graphic
72
+
73
+ Returns
74
+ -------
75
+ ndarray[Graphic]
76
+ nearest graphics to ``pos`` in order
77
+
78
+ """
79
+ sort_indices = get_nearest_graphics_indices (pos , graphics )
53
80
return np .asarray (graphics )[sort_indices ]
0 commit comments