Box dataclass

class mops.mixins.objects.box.Box(left: Union[int, float, None] = None, top: Union[int, float, None] = None, right: Union[int, float, None] = None, bottom: Union[int, float, None] = None, is_percents: InitVar[bool] = False)[source]

Represents a rectangular region defined by its edges: left, top, right, and bottom.

The class allows specifying these edges as absolute values or percentages of an image’s dimensions. It includes methods to fill missing values and calculate the coordinates of the cut box based on an image’s size.

left: Union[int, float, None] = None
top: Union[int, float, None] = None
right: Union[int, float, None] = None
bottom: Union[int, float, None] = None
is_percents: InitVar[bool] = False
fill_values() None[source]

Replaces None values for the cut box edges with 0.

This method ensures that all edges (left, top, right, bottom) have valid numerical values, defaulting to zero where no value is provided.

Returns:

None

get_image_cut_box(size: Size) Box[source]

Calculates the cut box coordinates based on the provided image dimensions.

This method computes the values of the left, top, right, and bottom edges, adjusting for whether the values are absolute or percentages of the image’s size.

Parameters:

size (Size) – Size object containing the width and height of the image size.

Returns:

New Box object representing the coordinates of the cut box (left, top, right, bottom).