Class: Magick::RVG::PolyShape

Inherits:
Shape
  • Object
show all
Defined in:
lib/rvg/embellishable.rb

Overview

class Rect

Direct Known Subclasses

Polygon, Polyline

Instance Method Summary collapse

Methods inherited from Shape

#add_primitives

Methods included from Duplicatable

#deep_copy

Methods included from Transformable

#matrix, #rotate, #scale, #skewX, #skewY, #translate

Methods included from Stylable

#styles

Instance Method Details

#polypoints(points) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rvg/embellishable.rb', line 103

def polypoints(points)
  case points.length
    when 1
      points = Array(points[0])
    when 2
      x_coords = Array(points[0])
      y_coords = Array(points[1])
      unless x_coords.length > 0 && y_coords.length > 0
        fail ArgumentError, 'array arguments must contain at least one point'
      end
      n = x_coords.length - y_coords.length
      short = n > 0 ? y_coords : x_coords
      olen = short.length
      n.abs.times {|x| short << short[x % olen]}
      points = x_coords.zip(y_coords).flatten
  end
  n = points.length
  if n < 4 || n.odd?
    fail ArgumentError, "insufficient/odd number of points specified: #{n}"
  end
  Magick::RVG.convert_to_float(*points)
end