lib/chunky_png/vector.rb in chunky_png-1.0.1 vs lib/chunky_png/vector.rb in chunky_png-1.1.0
- old
+ new
@@ -38,11 +38,11 @@
# @return [Array<ChunkyPNG::Point>] The array that holds all the points in this vector.
attr_reader :points
# Initializes a vector based on a list of Point instances.
#
- # You usually do not want to use this method directy, but call {ChunkyPNG.Vector} instead.
+ # You usually do not want to use this method directly, but call {ChunkyPNG.Vector} instead.
#
# @param [Array<ChunkyPNG::Point>] points
# @see ChunkyPNG.Vector
def initialize(points = [])
@points = points
@@ -60,9 +60,16 @@
# @see #edges
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
+
+ # Returns the point with the given indexof this vector.
+ # @param [Integer] index The 0-based index of the point in this vector.
+ # @param [ChunkyPNG::Point] The point instance.
+ def [](index)
+ points[index]
end
# Returns an enumerator that will iterate over all the edges in this vector.
# @param (see #each_edge)
# @return [Enumerator] The enumerator that iterates over the edges.