diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-08-09 15:11:13 -0400 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-08-09 15:11:13 -0400 |
commit | cb2fa34e881a389cf8a4bc98fd12be662ff687f8 (patch) | |
tree | 5b4a287ff27a8cfe5a3e93b180b7394c0514b403 /gerber/render/cairo_backend.py | |
parent | d4a870570855265b9b37f1609dd2bc9f49699bb6 (diff) | |
download | gerbonara-cb2fa34e881a389cf8a4bc98fd12be662ff687f8.tar.gz gerbonara-cb2fa34e881a389cf8a4bc98fd12be662ff687f8.tar.bz2 gerbonara-cb2fa34e881a389cf8a4bc98fd12be662ff687f8.zip |
Add support for arcs in regions.
This fixes the circular cutout issue described in #32. Regions were previously stored as a collection of points, now they are stored as a collection of line and arc primitives.
Diffstat (limited to 'gerber/render/cairo_backend.py')
-rw-r--r-- | gerber/render/cairo_backend.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py index 0ae5d40..a97e552 100644 --- a/gerber/render/cairo_backend.py +++ b/gerber/render/cairo_backend.py @@ -89,13 +89,25 @@ class GerberCairoContext(GerberContext): self.ctx.move_to(*end) # ...lame
def _render_region(self, region, color):
- points = [tuple(map(mul, point, self.scale)) for point in region.points]
self.ctx.set_source_rgba(*color, alpha=self.alpha)
- self.ctx.set_operator(cairo.OPERATOR_OVER if (region.level_polarity == "dark" and not self.invert) else cairo.OPERATOR_CLEAR)
+ self.ctx.set_operator(cairo.OPERATOR_OVER if (region.level_polarity == "dark" and not self.invert) else cairo.OPERATOR_CLEAR)
self.ctx.set_line_width(0)
- self.ctx.move_to(*points[0])
- for point in points[1:]:
- self.ctx.line_to(*point)
+ self.ctx.set_line_cap(cairo.LINE_CAP_ROUND)
+ self.ctx.move_to(*tuple(map(mul, region.primitives[0].start, self.scale)))
+ for p in region.primitives:
+ if isinstance(p, Line):
+ self.ctx.line_to(*tuple(map(mul, p.end, self.scale)))
+ else:
+ center = map(mul, p.center, self.scale)
+ start = map(mul, p.start, self.scale)
+ end = map(mul, p.end, self.scale)
+ radius = self.scale[0] * p.radius
+ angle1 = p.start_angle
+ angle2 = p.end_angle
+ if p.direction == 'counterclockwise':
+ self.ctx.arc(*center, radius=radius, angle1=angle1, angle2=angle2)
+ else:
+ self.ctx.arc_negative(*center, radius=radius, angle1=angle1, angle2=angle2)
self.ctx.fill()
def _render_circle(self, circle, color):
|