class ChunkyPNG::Vector
Class that represents a vector of points, i.e. a list of {ChunkyPNG::Point} instances.
def self.multiple_from_array(source)
def self.multiple_from_array(source) return [] if source.empty? if source.first.kind_of?(Numeric) || source.first =~ /^\d+$/ raise ChunkyPNG::ExpectationFailed, "The points array is expected to have an even number of items!" if source.length % 2 != 0 points = [] source.each_slice(2) { |x, y| points << ChunkyPNG::Point.new(x, y) } return points else source.map { |p| ChunkyPNG::Point(p) } end end
def self.multiple_from_string(source_str)
def self.multiple_from_string(source_str) multiple_from_array(source_str.scan(/[\(\[\{]?(\d+)\s*[,x]?\s*(\d+)[\)\]\}]?/)) end
def each(&block)
def each(&block) points.each(&block) end
def each_edge(close = true)
def each_edge(close = true) raise ChunkyPNG::ExpectationFailed, "Not enough points in this path to draw an edge!" if length < 2 points.each_cons(2) { |a, b| yield(a, b) } yield(points.last, points.first) if close end
def edges(close = true)
def edges(close = true) Enumerator.new(self, :each_edge, close) end
def eql?(other)
def eql?(other) other.points == points end
def initialize(points = [])
def initialize(points = []) @points = points end
def length
def length points.length end
def to_a
def to_a edges end
def x_range
def x_range Range.new(*points.map { |p| p.x }.minmax) end
def y_range
def y_range Range.new(*points.map { |p| p.y }.minmax) end