Method: HexaPDF::Content::Canvas#polygon

Defined in:
lib/hexapdf/content/canvas.rb

#polygon(*points, radius: 0) ⇒ Object

:call-seq:

canvas.polygon(x0, y0, x1, y1, x2, y2, ..., radius: 0)          => canvas

Appends a polygon consisting of the given points to the path as a complete subpath and returns self. The point (x0, y0 + radius) becomes the new current point.

If radius is greater than 0, the corners are rounded with the given radius.

If there is no current path when the method is invoked, a new path is automatically begun.

Examples:

#>pdf
canvas.polygon(10, 10, 90, 10, 70, 90, 20, 100).stroke
canvas.stroke_color("hp-blue").
  polygon(130, 130, 150, 100, 170, 150, 130, 190, radius: 10).stroke

See: #polyline



1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
# File 'lib/hexapdf/content/canvas.rb', line 1253

def polygon(*points, radius: 0)
  if radius == 0
    polyline(*points)
  else
    check_poly_points(points)
    move_to(*point_on_line(points[0], points[1], points[2], points[3], distance: radius))
    points.concat(points[0, 4])
    0.step(points.length - 6, 2) do |i|
      line_with_rounded_corner(*points[i, 6], in_radius: radius)
    end
  end
  close_subpath
end