system.utils module

Drawable geometry utilities (vectors, triangles, descriptors) for canvas visualization.

class system.utils.Drawable[source]

Bases: ABC

An interface for objects that can render themselves onto an ipycanvas canvas.

abstractmethod draw(canvas: Canvas, canvas_height: int = 0, x_offset: int = 0, y_offset: int = 0)[source]

Draw this instance on the given canvas.

Parameters:
  • canvas – The canvas to draw on.

  • canvas_height – The height of the canvas (used to invert y-coordinates which are top down in canvas).

  • x_offset – The x-offset to apply to the drawing.

  • y_offset – The y-offset to apply to the drawing.

class system.utils.Vector(x: float, y: float)[source]

Bases: Drawable

A simple implementation of a two-dimensional vector.

x: float
y: float
my_hash() → int[source]

Return a hash value for this vector.

draw(canvas: Canvas, canvas_height: int = 0, x_offset: int = 0, y_offset: int = 0)[source]

See Drawable.draw().

Draws the vector as a small white dot at its (x, y) position.

class system.utils.Descriptor[source]

Bases: Drawable

A simple interface for descriptors. Descriptors define a subset of a domain. For instance, given a two-dimensional space, a descriptor might define a rectangle or triangle or any other geometric structure in that space. This abstraction is very useful for indexing and querying data in a multidimensional domain.

abstractmethod split_into_sub_descriptors() → Iterator[Descriptor][source]

Split this Descriptor into four sub-descriptors. Each must be contained in self, i.e. if you call self.contains() with any child descriptor, it must return True.

abstractmethod contains(key: Key) → bool[source]

Return whether the given key is contained in this Descriptor.

abstractmethod center() → T[source]

Return the center of this Descriptor.

class system.utils.Triangle(A: Vector, AB: Vector, AC: Vector)[source]

Bases: Descriptor

A simple implementation of a triangle data structure.

center() → Vector[source]

See Descriptor.center().

Returns the centroid of the triangle.

split_into_sub_descriptors() → Iterator[Triangle][source]

See Descriptor.split_into_sub_descriptors().

Splits this triangle into four sub-triangles of equal size (lower-left, top, lower-right, and a central inverted triangle).

draw(canvas: Canvas, canvas_height: int = 0, x_offset: int = 0, y_offset: int = 0)[source]

See Drawable.draw().

Draws the triangle as a semi-transparent green filled polygon with a black outline.

contains(point: Vector) → bool[source]

See Descriptor.contains().

Point-in-triangle test: the point is contained iff it lies on the same side of all three edges, which is checked via the sign of the cross products.