class WindingPolygon::EventQueue
Attributes
events[R]
individual_vertices[R]
number_of_events[R]
Public Class Methods
new(polygon)
click to toggle source
# 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
Public Instance Methods
exist(point)
click to toggle source
# 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)
click to toggle source
# 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