class GeoTreeModule::NodeI
Attributes
population[RW]
Public Class Methods
new(name, vertical, bounds)
click to toggle source
Calls superclass method
GeoTreeModule::Node::new
# File lib/geotree/node.rb, line 150 def initialize(name, vertical, bounds) super(name,false,vertical,bounds) @population = 0 @p = [] NODEI_CHILDREN.times{ @p << Partition.new } end
Public Instance Methods
adjust_population(amt)
click to toggle source
# File lib/geotree/node.rb, line 157 def adjust_population(amt) @population += amt end
inspect()
click to toggle source
# File lib/geotree/node.rb, line 246 def inspect to_s end
remove_child_named(name)
click to toggle source
# File lib/geotree/node.rb, line 223 def remove_child_named(name) @p.each do |p| p.child_name = 0 if p.child_name == name end end
set_slot(slot, p)
click to toggle source
# File lib/geotree/node.rb, line 165 def set_slot(slot, p) @p[slot] = p end
set_slot_child(slot, child_name)
click to toggle source
# File lib/geotree/node.rb, line 194 def set_slot_child(slot, child_name) @p[slot].child_name = child_name end
slot(slot_index)
click to toggle source
# File lib/geotree/node.rb, line 161 def slot(slot_index) @p[slot_index] end
slot_bounds(slot)
click to toggle source
# File lib/geotree/node.rb, line 202 def slot_bounds(slot) nb = bounds if vertical nb = nb.flip end x = @p[slot].start_position x2 = nb.x2 if slot+1 < NODEI_CHILDREN x2 = @p[slot+1].start_position end b = Bounds.new(x,nb.y,x2-x,nb.h) if vertical b = b.flip end b end
slot_child(slot)
click to toggle source
# File lib/geotree/node.rb, line 198 def slot_child(slot) @p[slot].child_name end
slot_containing_point(loc)
click to toggle source
Determine which slot contains a particular point (assumes point lies within the bounds of some slot)
# File lib/geotree/node.rb, line 189 def slot_containing_point(loc) line_pos = vertical ? loc.y : loc.x slot_intersecting_line(line_pos) end
slot_intersecting_line(line_position)
click to toggle source
Determine which slot intersects a line perpendicular to the bounds > linePosition if node is horizontal, the x coordinate of the line; else, the y coordinate < slot index
# File lib/geotree/node.rb, line 172 def slot_intersecting_line(line_position) s0 = 0 s1 = NODEI_CHILDREN while s0 < s1 s = (s0 + s1) / 2 if @p[s].start_position > line_position s1 = s else s0 = s + 1 end end s0 - 1 end
to_s()
click to toggle source
# File lib/geotree/node.rb, line 229 def to_s s = "INTR=> ##{name} " s << (self.vertical ? "V" : "H") s << " pop=#{population}" s << " bnds #{bounds} " NODEI_CHILDREN.times do |i| pt = slot(i) b = slot_bounds(i) b = b.flip if vertical s << "#{b.x}/#{b.x2}--> #{pt.child_name} " end s end