class Sangaku::Polygon
Public Class Methods
new(*points)
click to toggle source
# File lib/sangaku/polygon.rb, line 5 def initialize(*points) @points = Point::convert(points) @lines = nil @closed = false @aabb = nil end
Public Instance Methods
<<(p)
click to toggle source
# File lib/sangaku/polygon.rb, line 46 def <<(p) @lines = nil @points << Point.new(*p) end
aabb()
click to toggle source
# File lib/sangaku/polygon.rb, line 42 def aabb @aabb ||= AABB.new(*@points) end
clear!()
click to toggle source
# File lib/sangaku/polygon.rb, line 23 def clear! @points.clear @closed = false @lines = nil @aabb = nil end
close!()
click to toggle source
# File lib/sangaku/polygon.rb, line 16 def close! return if @closed @closed = true @lines = nil @aabb = nil end
closed?()
click to toggle source
# File lib/sangaku/polygon.rb, line 12 def closed? @closed end
length()
click to toggle source
# File lib/sangaku/polygon.rb, line 30 def length @points.length end
lines()
click to toggle source
# File lib/sangaku/polygon.rb, line 38 def lines @lines ||= _points_to_lines end
points()
click to toggle source
# File lib/sangaku/polygon.rb, line 34 def points @points end
select(x = nil, y = nil)
click to toggle source
# File lib/sangaku/polygon.rb, line 51 def select(x = nil, y = nil) lines.select { |line| line.contain?(x, y) } end
to_a()
click to toggle source
# File lib/sangaku/polygon.rb, line 55 def to_a @points.map { |p| p.to_a } end
to_s()
click to toggle source
# File lib/sangaku/polygon.rb, line 59 def to_s @points.join('->') end
Also aliased as: inspect
Private Instance Methods
_points_to_lines()
click to toggle source
# File lib/sangaku/polygon.rb, line 66 def _points_to_lines return [] if @points.length < 2 retval = @points.zip(@points.rotate).map { |p1, p2| Line.new(p1, p2) } retval = retval[0...-1] unless @closed retval end