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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/rvg/embellishable.rb', line 117

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
                raise 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 % 2 != 0
        raise ArgumentError, "insufficient/odd number of points specified: #{n}"
    end
    return Magick::RVG.convert_to_float(*points)
end