BoundingBox

class BoundingBox(start_x, start_y, end_x, end_y)

A rectangular bounding box.

Checking if two BoundingBox instances are equal checks the equivalence of their coordinates.

Multiplying a BoundingBox by a scalar scales the bounding box and position. This can be helpful when scaling an image up or down.

Parameters
  • start_x (integer) – The starting x value.

  • start_y (integer) – The starting y value.

  • end_x (integer) – The ending x value.

  • end_y (integer) – The ending y value.

property start_x

The starting x value.

Type

integer

property start_y

The starting y value.

Type

integer

property end_x

The ending x value.

Type

integer

property end_y

The ending y value.

Type

integer

property width

The width of the bounding box.

Type

integer

property height

The height of the bounding box.

Type

integer

property area

The area of the bounding box.

Type

integer

property center

The center of the bounding box.

Type

float

compute_distance(other_box)

Compute the distance between the center of this and another bounding box.

Parameters

other_box (BoundingBox) – The second bounding box for the distance computation.

Returns

float – The Euclidean distance between bounding box centers.

get_intersection(other_box)

Get the intersection of this box and other_box represented as another bounding box.

Parameters

other_box (BoundingBox) – The overlapping box.

Returns

BoundingBox – The bounding box representing the intersection of this box and other_box.

compute_overlap(other_box)

Compute the fraction of this box which is overlapped by other_box.

Parameters

other_box (BoundingBox) – The overlapping box.

Returns

float – A value [0.0, 1.0] indicating the fraction of this box that is overlapped by other_box.