Class: WindingPolygon::EventQueue
- Inherits:
-
Object
- Object
- WindingPolygon::EventQueue
- Defined in:
- lib/winding-polygon/event_queue.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#individual_vertices ⇒ Object
readonly
Returns the value of attribute individual_vertices.
-
#number_of_events ⇒ Object
readonly
Returns the value of attribute number_of_events.
Instance Method Summary collapse
- #exist(point) ⇒ Object
-
#initialize(polygon) ⇒ EventQueue
constructor
A new instance of EventQueue.
- #insert(point_hash) ⇒ Object
Constructor Details
#initialize(polygon) ⇒ EventQueue
Returns a new instance of EventQueue.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/winding-polygon/event_queue.rb', line 7 def initialize(polygon) #last vertex in geojson is equal to first vertex @individual_vertices = polygon.vertices.length - 1 #2 per edge - last event looping back to 0 is handled by +1 below @number_of_events = 2 * (@individual_vertices) @events = [] #build up 2 'events' per edge. One for left vertex, one for right. for i in 0..@individual_vertices-1 a = 2*i b = 2*i+1 @events[a] = {:edge=>i} @events[b] = {:edge=>i} @events[a][:vertex] = polygon.vertices[i] @events[b][:vertex] = polygon.vertices[i+1] if @events[a][:vertex].compare(@events[b][:vertex]) < 0 @events[a][:type] = 'left' @events[b][:type] = 'right' else @events[a][:type] = 'right' @events[b][:type] = 'left' end end # sort events lexicographically #@events.sort!{|a,b| [a[:vertex], b[:type], a[:other_endpoint]] <=> [b[:vertex], a[:type], b[:other_endpoint]] } @events.sort!{|a,b| [a[:vertex], b[:type]] <=> [b[:vertex], a[:type]] } end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
4 5 6 |
# File 'lib/winding-polygon/event_queue.rb', line 4 def events @events end |
#individual_vertices ⇒ Object (readonly)
Returns the value of attribute individual_vertices.
5 6 7 |
# File 'lib/winding-polygon/event_queue.rb', line 5 def individual_vertices @individual_vertices end |
#number_of_events ⇒ Object (readonly)
Returns the value of attribute number_of_events.
3 4 5 |
# File 'lib/winding-polygon/event_queue.rb', line 3 def number_of_events @number_of_events end |
Instance Method Details
#exist(point) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/winding-polygon/event_queue.rb', line 46 def exist(point) for i in 0..@events.size-1 return true if @events[i][:vertex] ==point end return false end |
#insert(point_hash) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/winding-polygon/event_queue.rb', line 37 def insert(point_hash) for i in 0..@events.size-1 next if @events[i][:vertex].x < point_hash[:point].x next if @events[i][:vertex].x == point_hash[:point].x && @events[i][:vertex].y<point_hash[:point].y @events.insert(i,{:type=>'intersection_point',:vertex=>point_hash[:point],:edge1=>point_hash[:edge1],:edge2=>point_hash[:edge2]}) break end end |