Class: GeoTreeModule::NodeI

Inherits:
Node
  • Object
show all
Defined in:
lib/geotree/node.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#bounds, #leaf, #modified, #name, #next_node, #prev_node, #vertical

Instance Method Summary collapse

Methods inherited from Node

#splittable

Constructor Details

#initialize(name, vertical, bounds) ⇒ NodeI

Returns a new instance of NodeI.



150
151
152
153
154
155
# 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

Instance Attribute Details

#populationObject

Returns the value of attribute population.



149
150
151
# File 'lib/geotree/node.rb', line 149

def population
  @population
end

Instance Method Details

#adjust_population(amt) ⇒ Object



157
158
159
# File 'lib/geotree/node.rb', line 157

def adjust_population(amt)
  @population += amt
end

#inspectObject



246
247
248
# File 'lib/geotree/node.rb', line 246

def inspect
  to_s
end

#remove_child_named(name) ⇒ Object



223
224
225
226
227
# 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) ⇒ Object



165
166
167
# File 'lib/geotree/node.rb', line 165

def set_slot(slot, p)
  @p[slot] = p
end

#set_slot_child(slot, child_name) ⇒ Object



194
195
196
# File 'lib/geotree/node.rb', line 194

def set_slot_child(slot, child_name)
  @p[slot].child_name = child_name
end

#slot(slot_index) ⇒ Object



161
162
163
# File 'lib/geotree/node.rb', line 161

def slot(slot_index)
  @p[slot_index]
end

#slot_bounds(slot) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# 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) ⇒ Object



198
199
200
# File 'lib/geotree/node.rb', line 198

def slot_child(slot)
  @p[slot].child_name
end

#slot_containing_point(loc) ⇒ Object

Determine which slot contains a particular point (assumes point lies within the bounds of some slot)



189
190
191
192
# 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) ⇒ Object

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



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# 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_sObject



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# 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