class ChunkyPNG::Vector

more information on how to construct vectors.
Vectors can be created quite flexibly. See the {ChunkyPNG.Vector} factory methods for
Class that represents a vector of points, i.e. a list of {ChunkyPNG::Point} instances.

def self.multiple_from_array(source)

Returns:
  • (Array) - The list of points interpreted from the input array.
def self.multiple_from_array(source)
  return [] if source.empty?
  if source.first.is_a?(Numeric) || source.first =~ /^\d+$/
    raise ArgumentError, "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)

Returns:
  • (Array) - The list of points parsed from the string.
def self.multiple_from_string(source_str)
  multiple_from_array(source_str.scan(/[\(\[\{]?(\d+)\s*[,x]?\s*(\d+)[\)\]\}]?/))
end

def [](index)

Returns:
  • (ChunkyPNG::Point) - The point instance.

Parameters:
  • index (Integer) -- The 0-based index of the point in this vector.
def [](index)
  points[index]
end

def dimension

Returns:
  • (ChunkyPNG::Dimension) - The dimension instance with the width and height
def dimension
  ChunkyPNG::Dimension.new(width, height)
end

def each(&block)

Returns:
  • (void) -

Other tags:
    Yield: - The points in the correct order.
def each(&block)
  points.each(&block)
end

def each_edge(close = true)

Other tags:
    See: #edges -

Raises:
  • (ChunkyPNG::ExpectationFailed) - if the vector contains less than two points.

Returns:
  • (void) -

Parameters:
  • close (true, false) -- Whether to close the path, i.e. return an edge that connects the last
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)

Other tags:
    See: #each_edge -

Raises:
  • (ChunkyPNG::ExpectationFailed) - if the vector contains less than two points.

Returns:
  • (Enumerator) - The enumerator that iterates over the edges.

Parameters:
  • () --
def edges(close = true)
  to_enum(:each_edge, close)
end

def eql?(other)

Returns:
  • (true, false) - true if the list of points are identical

Parameters:
  • other (ChunkyPNG::Vector) -- The vector to compare with.
def eql?(other)
  other.points == points
end

def height

Returns:
  • (Integer) - The y-distance between the points that are farthest from each other.
def height
  1 + (max_y - min_y)
end

def initialize(points = [])

Other tags:
    See: ChunkyPNG.Vector -

Parameters:
  • points (Array) --
def initialize(points = [])
  @points = points
end

def length

Returns:
  • (Integer) - The length of the points array.
def length
  points.length
end

def max_x

Returns:
  • (Integer) - The highest x-coordinate of all the points in the vector.
def max_x
  x_range.last
end

def max_y

Returns:
  • (Integer) - The highest y-coordinate of all the points in the vector.
def max_y
  y_range.last
end

def min_x

Returns:
  • (Integer) - The lowest x-coordinate of all the points in the vector.
def min_x
  x_range.first
end

def min_y

Returns:
  • (Integer) - The lowest y-coordinate of all the points in the vector.
def min_y
  y_range.first
end

def offset

Returns:
  • (ChunkyPNG::Point) - A point that describes the top left corner if a
def offset
  ChunkyPNG::Point.new(min_x, min_y)
end

def width

Returns:
  • (Integer) - The x-distance between the points that are farthest from each other.
def width
  1 + (max_x - min_x)
end

def x_range

Returns:
  • (Range) - The (inclusive) range of x-coordinates.
def x_range
  Range.new(*points.map { |p| p.x }.minmax)
end

def y_range

Returns:
  • (Range) - The (inclusive) range of y-coordinates.
def y_range
  Range.new(*points.map { |p| p.y }.minmax)
end