Skip to content

Types

types

Types for locations on a figure.

Rectangles are described either by their corners, an Extent (x0, y0, x1, y1), or by their origin and size, a Bound (x, y, w, h). The ...CM, ...Inches and ...Fraction names are aliases that say which unit is meant. They are the same classes, so the unit is documentation only. For cm the origin is the upper left of the figure.

centimetres module-attribute

centimetres = float

A type alias for centimeters, used for positions and dimensions in figures.

inches module-attribute

inches = float

A type alias for inches, used for positions and dimensions in figures.

fraction module-attribute

fraction = float

A type alias for figure fraction, used for positions and dimensions in figures.

ExtentCM module-attribute

ExtentCM = Extent

Extent (x0, y0, x1, y1) in centimetres from the upper left of the figure.

BoundCM module-attribute

BoundCM = Bound

Bound (x, y, w, h) in centimetres from the upper left of the figure.

ExtentInches module-attribute

ExtentInches = Extent

Extent (x0, y0, x1, y1) in inches.

BoundInches module-attribute

BoundInches = Bound

Bound (x, y, w, h) in inches.

ExtentFraction module-attribute

ExtentFraction = Extent

Extent (x0, y0, x1, y1) in figure fraction.

BoundFraction module-attribute

BoundFraction = Bound

Bound (x, y, w, h) in figure fraction.

Extent

Bases: _ExtentFields

Extent of a rectangle given by its corners (x0, y0, x1, y1).

An immutable 4-tuple with named fields, checked on creation: all values must be real numbers, x0 <= x1 and y0 <= y1. Note that _replace does not repeat the checks.

Attributes:

Name Type Description
x0, y0 float

One corner (the upper left, for locations in cm).

x1, y1 float

The opposite corner.

Examples:

>>> extent = Extent(1, 2, 5, 6)
>>> extent.x1
5
>>> x0, y0, x1, y1 = extent
>>> Extent(5, 0, 1, 1)
Traceback (most recent call last):
    ...
ValueError: Coordinates must be in the order: (x0, y0, x1, y1).

Bound

Bases: NamedTuple

Rectangle given by its origin and size (x, y, w, h).

An immutable 4-tuple with named fields. Unlike Extent it is not checked on creation.

Attributes:

Name Type Description
x, y float

The origin (the upper left, for locations in cm).

w, h float

Width and height.

Examples:

>>> bound = Bound(1, 2, 4, 4)
>>> bound.w
4