RAIMAD

raimad.AbstractBBox

class AbstractBBox( typing.Generic, ):
Abstract bounding box. This is a base class for BoundBBox and BBox.

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.

def assert_nonempty(self, message: str | None = None) -> None:

Throw EmptyBBoxError is the bbox is empty, do nothing otherwise.
Parameters
messagestr
Message to pass to EmptyBBoxError
Raises
EmptyBBoxError

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 ).
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
Returns
Self
A new bbox with the corresponding padding.
Raises
EmptyBBoxError
if the bbox is empty

Property length

Get length of the bbox.
Returns
float
length of the bbox
Raises
EmptyBBoxError
if the bbox is empty

Property width

Get width of the bbox.
Returns
float
width of the bbox
Raises
EmptyBBoxError
if the bbox is empty

Property left

Get the X coordinate of the left wall of the bbox.
Returns
float
left X ccordinate of the bbox
Raises
EmptyBBoxError
if the bbox is empty

Property top

Get the Y coordinate of the top wall of the bbox.
Returns
float
top Y coordinate of the bbox
Raises
EmptyBBoxError
if the bbox is empty

Property right

Get the X coorinate of the right wall of the bbox.
Returns
float
right X coordinate of the bbox
Raises
EmptyBBoxError
if the bbox is empty

Property bottom

Get the Y coordinate of the bottom of the bbox.
Returns
float
bottom Y of the bbox
Raises
EmptyBBoxError
if the bbox is empty

Property mid

Get the point in the MIDDLE of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property top_mid

Get the point in the TOP MIDDLE of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property bot_mid

Get the point in the BOTTOM MIDDLE of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property mid_left

Get the point in the MIDDLE LEFT of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property mid_right

Get the point in the MIDDLE RIGHT of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property top_left

Get the point in the TOP LEFT of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property top_right

Get the point in the TOP RIGHT of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property bot_left

Get the point in the BOTTOM LEFT of the bbox.
Raises
EmptyBBoxError
if the bbox is empty

Property bot_right

Get the point in the middle of the bbox.
Raises
EmptyBBoxError
if the bbox is empty