def draw_polygon(ctx: Context, polygon: Polygon): if hasattr(polygon.exterior, 'coords'): start = True ctx.new_path() for x, y in polygon.exterior.coords: if start: ctx.move_to(x, y) else: ctx.line_to(x, y) start = False for interior in polygon.interiors: ctx.new_sub_path() start = True for x, y in interior.coords: if start: ctx.move_to(x, y) else: ctx.line_to(x, y) start = False ctx.close_path() ctx.close_path()
def draw_rect(self, g: Graphics, area: Bounds, radius: float) -> None: (x, y, w, h) = area.tuple if w == 0 or h == 0: return degrees = pi / 180.0 g.new_sub_path() g.arc(x + w - radius, y + radius, radius, -90 * degrees, 0) g.arc(x + w - radius, y + h - radius, radius, 0, 90 * degrees) g.arc(x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees) g.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees) g.close_path()