lib/ray/polygon.rb in ray-0.1.1 vs lib/ray/polygon.rb in ray-0.2.0

- old
+ new

@@ -2,10 +2,12 @@ class Polygon < Drawable include Enumerable # One of the points contained in a polygon. class Point + include Ray::PP + def initialize(polygon, id) @polygon, @id = polygon, id end # @return [Ray::Vector2] Position of the point. @@ -41,10 +43,14 @@ def inspect "#<#{self.class} polygon=#{polygon} id=#{id} pos=#{pos} color=#{color} \ outline=#{outline}>" end + def pretty_print(q) + pretty_print_attributes q, ["pos", "color", "outline"] + end + attr_reader :polygon, :id end # @param [Integer, nil] size Size of the polygon. If non nil, size points # will be added to the polygon and then yielded. @@ -66,12 +72,23 @@ # @yieldparam [Ray::Polygon::Point] point Each point of the polygon def each 0.upto(size - 1) { |n| yield self[n] } end + alias points to_a + # @return [Ray::Polygon::Point] idth point of the polygon (id should be less # than size) def [](id) Point.new(self, id) + end + + def pretty_print(q, other_attr = []) + attr = [ + "filled?", "outlined?", "outline_width", + "points" + ] + + super q, attr + other_attr end end end