system.utils module¶
Drawable geometry utilities (vectors, triangles, descriptors) for canvas visualization.
- class system.utils.Drawable[source]¶
Bases:
ABCAn 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:
DrawableA simple implementation of a two-dimensional vector.
- x: float¶
- y: float¶
- 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:
DrawableA 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.
- class system.utils.Triangle(A: Vector, AB: Vector, AC: Vector)[source]¶
Bases:
DescriptorA 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.