pythagoras.pobject module

class pythagoras.pobject.POProperty[source]

Bases: ABC

Abstract base class for a property of a PObject.

abstractmethod svg() str[source]

Compiles the property into SVG syntax.

Returns:

The corresponding SVG property.

abstractmethod tikz() str[source]

Compiles the property into TikZ syntax.

Returns:

The corresponding TikZ property.

class pythagoras.pobject.PObject[source]

Bases: ABC

Abstract base class for renderable objects.

abstractmethod extrema() list[tuple[float, float]][source]

Computes the furthermost points of the figure.

Returns:

A list with the bounding points of the object.

set_rendering_priority(order: int) None[source]

Modify the _zord attribute after the instantiation. The higher the order, the later it will be rendered.

Parameters:

order – Rendering priority.

abstractmethod svg(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into SVG commands.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The corresponding SVG code.

abstractmethod tikz(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into a sequence of TikZ instructions.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The resulting TikZ code.

class pythagoras.pobject.RenderingContext(scale: float, xmin: float, xmax: float, ymin: float, ymax: float)[source]

Bases: object

Container class for the properties of a Canvas object. Its main purpose is to be passed as an argument when calling PObject.svg() or PObject.tikz().

Variables:
  • scale (float) – The scaling factor by which the canvas is stretched. When exporting to TikZ, this is compiled exactly into [scale={scale}], and when using SVG, every distance is muliplied by its value.

  • xmin (float) – Minimum \(x\)-coordinate across all the entities (without scaling).

  • xmax (float) – Maximum \(x\)-coordinate across all the entities (without scaling).

  • ymin (float) – Minimum \(y\)-coordinate across all the entities (without scaling).

  • xmax – Maximum \(y\)-coordinate across all the entities (without scaling).

classmethod from_dimensions(scale: float, width: float, height: float, origin: tuple[float, float] = (0, 0)) Self[source]

Construct a rendering context from its dimensions and its position in space.

Returns:

An instance of RenderingContext.

property height: float

Height of the canvas (after scaling).

property origin: tuple[float, float]

Center of the canvas in the Cartesian plane (before scaling).

scale: float
property width: float

Width of the canvas (after scaling).

xmax: float
xmin: float
ymax: float
ymin: float