Geometry Helpers

class BBox(x_min, y_min, x_max, y_max)

Contains exactly 4 coordinates.

Parameters:
  • x_min (float) –

  • y_min (float) –

  • x_max (float) –

  • y_max (float) –

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

property area: float

The area of the BBox.

property height: float

The height of the BBox.

property width: float

The width of the BBox.

x_max: float

Maximum X coordinate.

x_min: float

Minimum X coordinate.

y_max: float

Maximum Y coordinate.

y_min: float

Minimum Y coordinate.

class MinMax(min, max)

A set of minimum and maximum values.

Parameters:
  • min (float) –

  • max (float) –

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

max: float

Maximum

min: float

Minimum

class Point(x, y)

A relative set of coordinates (X, Y) on the document.

Parameters:
  • x (float) –

  • y (float) –

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

x: float

X coordinate

y: float

Y coordinate

class Polygon(iterable=(), /)

Contains any number of vertex coordinates (Points).

Inherits from base class list so is compatible with type Points.

append(object, /)

Append object to the end of the list.

clear()

Remove all items from list.

copy()

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

insert(index, object, /)

Insert object before index.

pop(index=-1, /)

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value, /)

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()

Reverse IN PLACE.

sort(*, key=None, reverse=False)

Sort the list in ascending order and return None.

The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).

If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.

The reverse flag can be set to sort in descending order.

property centroid: Point

The central point (centroid) of the polygon.

class Quadrilateral(top_left, top_right, bottom_right, bottom_left)

Contains exactly 4 relative vertices coordinates (Points).

Parameters:
count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

bottom_left: Point

Bottom left Point

bottom_right: Point

Bottom right Point

property centroid: Point

The central point (centroid) of the quadrilateral.

top_left: Point

Top left Point

top_right: Point

Top right Point

get_bbox(points)

Given a sequence of points, calculate a bbox that encompasses all points.

Parameters:

points (Sequence[Point]) – Polygon to process.

Return type:

BBox

Returns:

A bbox that encompasses all points

get_bounding_box(points)

Given a sequence of points, calculate a bounding box that encompasses all points.

Parameters:

points (Sequence[Point]) – Polygon to process.

Return type:

Quadrilateral

Returns:

A bounding box that encompasses all points.

get_centroid(points)

Get the central point (centroid) given a sequence of points.

Parameters:

points (Sequence[Point]) – Polygon to process.

Return type:

Point

Returns:

The centroid

get_min_max_x(points)

Get the maximum and minimum Y value given a sequence of points.

Parameters:

points (Sequence[Point]) – List of points

Return type:

MinMax

get_min_max_y(points)

Get the maximum and minimum Y value given a sequence of points.

Parameters:

points (Sequence[Point]) – List of points

Return type:

MinMax

is_point_in_polygon_x(point, polygon)

Determine if the Point is in the Polygon’s X-axis.

Parameters:
  • point (Point) – Point to compare

  • polygon (Polygon) – Polygon to look into

Return type:

bool

is_point_in_polygon_y(point, polygon)

Determine if the Point is in the Polygon’s Y-axis.

Parameters:
  • point (Point) – Point to compare

  • polygon (Polygon) – Polygon to look into

Return type:

bool

is_point_in_x(point, min_x, max_x)

Determine if the Point is within the X-axis interval.

Parameters:
  • point (Point) – Point to compare

  • min_x (float) – Minimum X-axis value

  • max_x (float) – Maximum X-axis value

Return type:

bool

is_point_in_y(point, min_y, max_y)

Determine if the Point is in the Polygon’s Y-axis.

Parameters:
  • point (Point) – Point to compare

  • min_y (float) – Minimum Y-axis value

  • max_y (float) – Maximum Y-axis value

Return type:

bool

merge_polygons(vertices)

Given a sequence of polygons, calculate a polygon box that encompasses all polygons.

Parameters:

vertices (Sequence[Polygon]) – List of polygons

Return type:

Polygon

Returns:

A bounding box that encompasses all polygons

polygon_from_prediction(prediction)

Transform a prediction into a Polygon.

Parameters:

prediction (Sequence[list]) – API prediction.

Return type:

Polygon

quadrilateral_from_prediction(prediction)

Transform a prediction into a Quadrilateral.

Parameters:

prediction (Sequence[list]) – API prediction.

Return type:

Quadrilateral