primitive module#

The primitive shape set provides the basis for all shapes in JITX. If a library is used to create geometry, a ShapeGeometry interface should be implemented in order provide a mapping of the library geometry to one of these primitive shapes. Notably, a shapely ShapeGeometry interface has already been provided, to seamlessly use the shapely library to generate geometry for your design.

class Primitive[source]#

Bases: ShapeGeometry

to_primitive()[source]#

Convert the given shape into a Primitive shape.

Return type:

Primitive

Returns:

A Primitive shape with all of the points of the geometry transformed by the transform project of this shape.

class Empty[source]#

Bases: Primitive

An empty shape.

Used to represent the absence of geometry.

>>> empty = Empty()
class Arc(start: Point, mid: Point, end: Point, /)[source]#
class Arc(start: Point, end: Point, radius: float, /, *, clockwise: bool, large: bool = False)
class Arc(center: Point, radius: float, start: float, arc: float, /)

An Arc is represented using a 2D center point, a radius, a start angle between 0 and 360 degrees, and and arc sweep between -360 and 360 where positive values indicate counter-clockwise sweep and negative values indicate a clockwise sweep.

Note that arc angles are in degrees, and not in radians, to avoid numerical issues with precise 90-degree angles.

There are two overloaded constructors in addition to the native center, radius, start, and sweep. The first takes three points, start, mid, and end, and computes the arc from the three points. The second takes a start and end point and a radius, and computes the arc from these values.

>>> # Arc from center, radius, start angle, and sweep
>>> arc1 = Arc((0, 0), 5, 0, 90)
>>> # Arc through three points
>>> arc2 = Arc((0, 0), (1, 1), (2, 0))
>>> # Arc from start/end points, radius, cw orientation, and whether to draw the larger of two possible arcs.
>>> arc3 = Arc((0, 0), (10, 0), 5, clockwise=True, large=False)
Parameters:
center: TypeAliasType#

The center coordinates of the arc.

start: float#

The start angle in degrees. Must be between 0 and 360.

radius: float#

The radius of the arc.

arc: float#

The arc sweep angle in degrees. Positive values are counter clockwise. Must be between -360 and 360.

class ArcPolygon(elements)[source]#

Bases: Primitive

A polygon consisting of arcs instead of points in the corners.

The ends of arcs will be connected with line segments to form a closed shape. Points are allowed as a “degenerate” arc where a sharp corner is desired, but are not required. For example, a rounded rectangle would consist of four arcs, but no points.

Note that self-intersecting arc polygons are not supported.

>>> # Rounded rectangle using four arcs
>>> corner_radius = 2.0
>>> arcs = [
...     Arc((8, 2), corner_radius, 270, 90),
...     Arc((8, 8), corner_radius, 0, 90),
...     Arc((2, 8), corner_radius, 90, 90),
...     Arc((2, 2), corner_radius, 180, 90),
... ]
>>> rounded_rect = ArcPolygon(arcs)
>>> # Mixed arcs and sharp corners
>>> mixed = ArcPolygon([
...     Arc((0, 0), 5, 0, 90),
...     (10, 5),
...     Arc((5, 10), 3, 90, 180),
... ])
Parameters:

elements (Sequence[Arc | Point])

elements: Sequence[Arc | Point]#

Each “corner” of the rounded polygon represented by an Arc, the last element will be connected to the first automatically, there’s no need to close the polygon. If there are holes in the polygon, this represents the outside boundary.

class Polygon(elements, holes=())[source]#

Bases: Primitive

A polygon consisting of 2d points.

Line segments will connect the points to form a closed shape. Note that self-intersecting polygons are not supported.

Polygons may be given holes, making it a polygon with holes.

>>> # Triangle polygon
>>> triangle = Polygon([(0, 0), (5, 0), (2.5, 4.33)])
>>> # Rectangle polygon
>>> rect = Polygon([(0, 0), (10, 0), (10, 5), (0, 5)])
>>> # Polygon with a hole
>>> outer = [(0, 0), (10, 0), (10, 10), (0, 10)]
>>> hole = [(3, 3), (7, 3), (7, 7), (3, 7)]
>>> donut = Polygon(outer, holes=[hole])
Parameters:
elements: Sequence[Point]#

Each corner of the polygon, the last element will be connected to the first automatically, there’s no need to close the polygon. If there are holes in the polygon, this represents the outside boundary.

holes: Sequence[Sequence[Point]] = ()#

Optional set of holes. Each hole is a sequence of point representing an inner boundary. The holes must be disjoint, that is they may not intersect each other or the outside boundary.

class PolygonSet(polygons)[source]#

Bases: Primitive

A set of disjoint polygons.

>>> rect1 = Polygon([(0, 0), (5, 0), (5, 3), (0, 3)])
>>> rect2 = Polygon([(10, 0), (15, 0), (15, 3), (10, 3)])
>>> triangle = Polygon([(7, 5), (10, 5), (8.5, 8)])
>>> multi_shapes = PolygonSet([rect1, rect2, triangle])
Parameters:

polygons (Sequence[Polygon])

polygons: Sequence[Polygon]#
class ArcPolyline(width, elements)[source]#

Bases: Primitive

A polyline consisting of arcs instead of points in the corners.

Points are allowed as a “degenerate” arc where a sharp corner is desired, but are not required.

The width specifies the thickness of the polyline.

>>> trace = ArcPolyline(0.2, [
...     (0, 0),
...     Arc((5, 0), 2, 0, 90),
...     (5, 10),
...     Arc((10, 10), 3, 90, -180),
... ])
Parameters:
width: float#
elements: Sequence[Arc | Point]#
class Polyline(width, elements)[source]#

Bases: Primitive

A polyline consisting of 2d points.

The width specifies the thickness of the polyline.

>>> trace = Polyline(0.15, [
...     (0, 0), (5, 0), (5, 5), (10, 5)
... ])
Parameters:
width: float#
elements: Sequence[Point]#
class Circle(*, radius: float)[source]#
class Circle(*, diameter: float)

Bases: Primitive

Create a circle primitive. Context will dictate whether the circle is a filled disk or a circle outline.

Parameters:
  • radius (float | None) – Specify the radius of the disk, or, alternatively

  • diameter (float | None) – Specify the diameter of the disk.

>>> # Circle by radius
>>> small_circle = Circle(radius=5.0)
>>> # Circle by diameter
>>> large_circle = Circle(diameter=5.0)
property diameter#
radius: float#

Radius of the circle

class Text(string, size, anchor=Anchor.C)[source]#

Bases: Primitive

A text shape.

>>> ref_text = Text("U1", 1.0)
>>> title = Text("Main Board Rev 2.1", 2.0, Anchor.N)
Parameters:
string: str#
size: float#
anchor: Anchor = 'C'#