66from ..graphics ._collection_base import GraphicCollection
77
88
9- def get_nearest_graphics (
9+ def get_nearest_graphics_indices (
1010 pos : tuple [float , float ] | tuple [float , float , float ],
1111 graphics : Sequence [Graphic ] | GraphicCollection ,
12- ) -> np .ndarray [Graphic ]:
12+ ) -> np .ndarray [int ]:
1313 """
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.
1617
1718 Parameters
1819 ----------
@@ -25,11 +26,10 @@ def get_nearest_graphics(
2526
2627 Returns
2728 -------
28- tuple[Graphic ]
29- nearest graphics to ``pos`` in order
29+ ndarray[int ]
30+ indices of the nearest nearest graphics to ``pos`` in order
3031
3132 """
32-
3333 if isinstance (graphics , GraphicCollection ):
3434 graphics = graphics .graphics
3535
@@ -50,4 +50,31 @@ def get_nearest_graphics(
5050 distances = np .linalg .norm (centers [:, : len (pos )] - pos , ord = 2 , axis = 1 )
5151
5252 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 )
5380 return np .asarray (graphics )[sort_indices ]
0 commit comments