Class AbstractBBox
from raimad.bbox
class AbstractBBox
def __init__(self, poly: 'rai.typing.Poly | None' = None):
"""
Create a new BBox.
Parameters
----------
poly: np.ndarray | None
A N x 2 numpy array containing points to initialize the bbox with.
This is optional.
proxy: rai.Proxy | None
The proxy that this bbox should be bound to.
This is optional.
"""
def as_list(self) -> list[float]:
"""
Return as list of [min_x, min_y, max_x, max_y].
"""
def __iter__(self) -> Iterator[float]:
"""
Return as iter of [min_x, min_y, max_x, max_y].
"""
def is_empty(self) -> bool:
"""
Check if bbox is empty.
An empoty bbox has no paints.
BBoxes created with no `poly` argument are empty
until you manually add points to them with
`add_poly` or `add_point`.
Returns
-------
bool
Whether or not the bbox is empty.
See Also
--------
.5 -------
BBox.assert_nonempty()
"""
def assert_nonempty(self, message: str | None = None) -> None:
"""
Throw EmptyBBoxError is the bbox is empty, do nothing otherwise.
Parameters
----------
message : str
Message to pass to EmptyBBoxError
Raises
------
EmptyBBoxError
See Also
--------
BBox.is_empty()
"""
def copy(self) -> Self:
"""
Copy bbox.
"""
def add_poly(self, poly: 'rai.typing.Poly') -> None:
"""
Add new points to the bounding box.
Parameters
----------
poly: np.ndarray
A N x 2 numpy array containing points to add to the bbox.
"""
def add_point(self, point: 'rai.typing.PointLike') -> None:
"""
Add a new point to the bounding box.
Parameters
----------
point
the point to add
"""
def interpolate(self, x_ratio: float, y_ratio: float) -> ~T:
"""
Find a point inside (or outside) the bbox given X and Y ratios.
So, for example, 0,0 is top left,
1,1 is bottom right, 0.5,0.5 is center,
and 0.5,1 is bottom middle.
The ratios may be negative or higher than 1,
but doing so would probably make your code difficult to understand.
Parameters
----------
x_ratio: float
A number, such that 0 represents all the way to the left
of the bbox, and 1 represents all the way to the right.
y_ratio: float
A number, such that 0 represents all the way to the bottom
of the bbox, and 1 represents all the way to the top.
Raises
------
EmptyBBoxError
if the bbox is empty
"""
def pad(self, x: float = 0, y: float | None = None, /, *, left: float = 0, top: float = 0, right: float = 0, bottom: float = 0) -> Self:
"""
Create a copy of this bbox with extra padding.
Bound bboxes will be turned into unbound ones (Or will they O_O ).
Examples
--------
bbox.pad(5) # Pad evenly on every side
bbox.pad(5, 10) # Pad 5 units horizontally and 10 units vertically
bbox.pad(left=10) # Pad 10 units on the left side only
bbox.pad(left=10, bottom=5) # Pad 10 on th left, 5 on the bottom
bbox.pad(5, left=10) # Pad 15 units on the left, 5 everywhere else.
Parameters
----------
x: float
Base padding (is y in not specified) or horizontal padding
(if y IS specified)
y: float
Vertical padding.
left: float
Additional left padding
right: float
Additional right padding
top: float
Additional top padding
bottom: float
Additional bottom padding
Raises
------
EmptyBBoxError
if the bbox is empty
Returns
-------
Self
A new bbox with the corresponding padding.
"""