lib/rays/polygon.rb in rays-0.1.47 vs lib/rays/polygon.rb in rays-0.1.48
- old
+ new
@@ -6,77 +6,86 @@
class Polygon
include Enumerable
+ include Comparable
- def initialize(*args, loop: true)
- setup args, loop
+ def initialize(*args, loop: true, colors: nil, texcoords: nil)
+ setup args, loop, colors, texcoords
end
- def transform(matrix = nil, &block)
- lines = to_a
- lines = lines.map {|line| line.transform matrix} if matrix
- lines = block.call lines if block
- self.class.new(*lines)
+ def transform(&block)
+ polylines = block.call to_a
+ self.class.new(*polylines)
end
def intersects(obj)
!(self & obj).empty?
end
- def self.points(*args)
- points! args
+ def <=>(o)
+ (size <=> o.size).then {|cmp| return cmp if cmp != 0}
+ to_a.zip(o.to_a).each {|a, b| cmp = a <=> b; return cmp if cmp != 0}
+ 0
end
- def self.lines(*args)
- lines! args
+ def inspect()
+ "#<Rays::Polygon [#{map {|polyline| polyline.inspect}.join ', '}]>"
end
- def self.line_strip(*args, loop: false)
- line_strip! args, loop
+ def self.points(*points)
+ points! points
end
- def self.rect(
- *args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil,
- nsegment: nil)
+ def self.line(*points, loop: false)
+ line! points, loop
+ end
- rect! args, round, lt, rt, lb, rb, nsegment
+ def self.lines(*points)
+ lines! points
end
- def self.ellipse(
- *args, center: nil, radius: nil, hole: nil, from: nil, to: nil,
- nsegment: nil)
+ def self.triangles(*points, loop: true, colors: nil, texcoords: nil)
+ triangles! points, loop, colors, texcoords
+ end
- ellipse! args, center, radius, hole, from, to, nsegment
+ def self.triangle_strip(*points, colors: nil, texcoords: nil)
+ triangle_strip! points, colors, texcoords
end
- def self.triangles(*args, loop: true)
- triangles! args, loop
+ def self.triangle_fan(*points, colors: nil, texcoords: nil)
+ triangle_fan! points, colors, texcoords
end
- def self.triangle_strip(*args)
- triangle_strip! args
+ def self.rect(
+ *args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil,
+ nsegment: nil)
+
+ rect! args, round, lt, rt, lb, rb, nsegment
end
- def self.triangle_fan(*args)
- triangle_fan! args
+ def self.quads(*points, loop: true, colors: nil, texcoords: nil)
+ quads! points, loop, colors, texcoords
end
- def self.quads(*args, loop: true)
- quads! args, loop
+ def self.quad_strip(*points, colors: nil, texcoords: nil)
+ quad_strip! points, colors, texcoords
end
- def self.quad_strip(*args)
- quad_strip! args
+ def self.ellipse(
+ *args, center: nil, radius: nil, hole: nil, from: nil, to: nil,
+ nsegment: nil)
+
+ ellipse! args, center, radius, hole, from, to, nsegment
end
- def self.curve(*args, loop: false)
- curve! args, loop
+ def self.curve(*points, loop: false)
+ curve! points, loop
end
- def self.bezier(*args, loop: false)
- bezier! args, loop
+ def self.bezier(*points, loop: false)
+ bezier! points, loop
end
end# Polygon