Graphic Primitives¶
Graphic prmitives are the core of Gerbonara’s rendering interface. Individual graphic objects such as a Gerber
Region
as well as entire layers such as a GerberFile
can be rendered into a list of graphic
primitives. This rendering step resolves aperture definitions, calculates out aperture macros, converts units into a
given target unit, and maps complex shapes to a small number of subclasses of GraphicPrimitive
.
All graphic primitives have a polarity_dark
attribute. Its meaning is identical with
GraphicObject.polarity_dark
.
- class gerbonara.graphic_primitives.GraphicPrimitive¶
- bounding_box()¶
Return the axis-aligned bounding box of this feature.
- Returns:
((min_x, min_Y), (max_x, max_y))
- Return type:
tuple
- to_svg(fg='black', bg='white', tag=<class 'gerbonara.utils.Tag'>)¶
Render this primitive into its SVG representation.
- Parameters:
fg (str) – Foreground color. Must be an SVG color name.
bg (str) – Background color. Must be an SVG color name.
tag (function) – Tag constructor to use.
- Return type:
str
The five types of Graphic Primitives¶
Stroked lines¶
- class gerbonara.graphic_primitives.Line(x1: float, y1: float, x2: float, y2: float, width: float, polarity_dark: bool = True)¶
Straight line with round end caps.
- bounding_box()¶
Return the axis-aligned bounding box of this feature.
- Returns:
((min_x, min_Y), (max_x, max_y))
- Return type:
tuple
- classmethod from_obround(x: float, y: float, w: float, h: float, rotation: float = 0, polarity_dark: bool = True)¶
Convert a gerber obround into a
Line
.
- to_svg(fg='black', bg='white', tag=<class 'gerbonara.utils.Tag'>)¶
Render this primitive into its SVG representation.
- Parameters:
fg (str) – Foreground color. Must be an SVG color name.
bg (str) – Background color. Must be an SVG color name.
tag (function) – Tag constructor to use.
- Return type:
str
- width: float¶
Line width
- x1: float¶
Start X coordinate. As usual in modern graphics APIs, this is at the center of the half-circle capping off this line.
- x2: float¶
End X coordinate
- y1: float¶
Start Y coordinate
- y2: float¶
End Y coordinate
- class gerbonara.graphic_primitives.Arc(x1: float, y1: float, x2: float, y2: float, cx: float, cy: float, clockwise: bool, width: float, polarity_dark: bool = True)¶
Circular arc with line width
width
going from(x1, y1)
to(x2, y2)
around center at(cx, cy)
.- bounding_box()¶
Return the axis-aligned bounding box of this feature.
- Returns:
((min_x, min_Y), (max_x, max_y))
- Return type:
tuple
- to_svg(fg='black', bg='white', tag=<class 'gerbonara.utils.Tag'>)¶
Render this primitive into its SVG representation.
- Parameters:
fg (str) – Foreground color. Must be an SVG color name.
bg (str) – Background color. Must be an SVG color name.
tag (function) – Tag constructor to use.
- Return type:
str
- clockwise: bool¶
True
if this arc is clockwise from start to end. Selects between the large arc and the small arc given this start, end and center
- cx: float¶
Center X coordinate relative to
x1
- cy: float¶
Center Y coordinate relative to
y1
- width: float¶
Line width of this arc.
- x1: float¶
Start X coodinate
- x2: float¶
End X coodinate
- y1: float¶
Start Y coodinate
- y2: float¶
End Y coodinate
Filled shapes¶
- class gerbonara.graphic_primitives.Circle(x: float, y: float, r: float, polarity_dark: bool = True)¶
- bounding_box()¶
Return the axis-aligned bounding box of this feature.
- Returns:
((min_x, min_Y), (max_x, max_y))
- Return type:
tuple
- to_svg(fg='black', bg='white', tag=<class 'gerbonara.utils.Tag'>)¶
Render this primitive into its SVG representation.
- Parameters:
fg (str) – Foreground color. Must be an SVG color name.
bg (str) – Background color. Must be an SVG color name.
tag (function) – Tag constructor to use.
- Return type:
str
- r: float¶
Radius, not diameter like in
apertures.CircleAperture
- x: float¶
Center X coordinate
- y: float¶
Center y coordinate
- class gerbonara.graphic_primitives.Rectangle(x: float, y: float, w: float, h: float, rotation: float, polarity_dark: bool = True)¶
- bounding_box()¶
Return the axis-aligned bounding box of this feature.
- Returns:
((min_x, min_Y), (max_x, max_y))
- Return type:
tuple
- to_svg(fg='black', bg='white', tag=<class 'gerbonara.utils.Tag'>)¶
Render this primitive into its SVG representation.
- Parameters:
fg (str) – Foreground color. Must be an SVG color name.
bg (str) – Background color. Must be an SVG color name.
tag (function) – Tag constructor to use.
- Return type:
str
- h: float¶
height
- rotation: float¶
rotation around center in radians
- w: float¶
width
- x: float¶
Center X coordinate
- y: float¶
Center Y coordinate
- class gerbonara.graphic_primitives.ArcPoly(outline: list, arc_centers: list | None = None, polarity_dark: bool = True)¶
Polygon whose sides may be either straight lines or circular arcs.
- bounding_box()¶
Return the axis-aligned bounding box of this feature.
- Returns:
((min_x, min_Y), (max_x, max_y))
- Return type:
tuple
- classmethod from_regular_polygon(x: float, y: float, r: float, n: int, rotation: float = 0, polarity_dark: bool = True)¶
Convert an n-sided gerber polygon to a normal ArcPoly defined by outline
- to_svg(fg='black', bg='white', tag=<class 'gerbonara.utils.Tag'>)¶
Render this primitive into its SVG representation.
- Parameters:
fg (str) – Foreground color. Must be an SVG color name.
bg (str) – Background color. Must be an SVG color name.
tag (function) – Tag constructor to use.
- Return type:
str
- arc_centers: list = None¶
Must be either None (all segments are straight lines) or same length as outline. Straight line segments have None entry.
- outline: list¶
list of (x : float, y : float) tuples. Describes closed outline, i.e. the first and last point are considered connected.
- property segments¶
Return an iterator through all segments of this polygon. For each outline segment (line or arc), this iterator will yield a
(p1, p2, center)
tuple. If the segment is a straight line,center
will beNone
.