Class: Sangaku::Polygon
- Inherits:
-
Object
- Object
- Sangaku::Polygon
- Defined in:
- lib/sangaku/polygon.rb
Instance Method Summary collapse
- #<<(p) ⇒ Object
- #aabb ⇒ Object
- #clear! ⇒ Object
- #close! ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(*points) ⇒ Polygon
constructor
A new instance of Polygon.
- #length ⇒ Object
- #lines ⇒ Object
- #points ⇒ Object
- #select(x = nil, y = nil) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
Instance Method Details
#<<(p) ⇒ Object
46 47 48 49 |
# File 'lib/sangaku/polygon.rb', line 46 def <<(p) @lines = nil @points << Point.new(*p) end |
#aabb ⇒ Object
42 43 44 |
# File 'lib/sangaku/polygon.rb', line 42 def aabb @aabb ||= AABB.new(*@points) end |
#clear! ⇒ Object
23 24 25 26 27 28 |
# File 'lib/sangaku/polygon.rb', line 23 def clear! @points.clear @closed = false @lines = nil @aabb = nil end |
#close! ⇒ Object
16 17 18 19 20 21 |
# File 'lib/sangaku/polygon.rb', line 16 def close! return if @closed @closed = true @lines = nil @aabb = nil end |
#closed? ⇒ Boolean
12 13 14 |
# File 'lib/sangaku/polygon.rb', line 12 def closed? @closed end |
#length ⇒ Object
30 31 32 |
# File 'lib/sangaku/polygon.rb', line 30 def length @points.length end |
#lines ⇒ Object
38 39 40 |
# File 'lib/sangaku/polygon.rb', line 38 def lines @lines ||= _points_to_lines end |
#points ⇒ Object
34 35 36 |
# File 'lib/sangaku/polygon.rb', line 34 def points @points end |
#select(x = nil, y = nil) ⇒ Object
51 52 53 |
# File 'lib/sangaku/polygon.rb', line 51 def select(x = nil, y = nil) lines.select { |line| line.contain?(x, y) } end |
#to_a ⇒ Object
55 56 57 |
# File 'lib/sangaku/polygon.rb', line 55 def to_a @points.map { |p| p.to_a } end |
#to_s ⇒ Object Also known as: inspect
59 60 61 |
# File 'lib/sangaku/polygon.rb', line 59 def to_s @points.join('->') end |