class KTree::KTree::Node

A node containing other nodes, 2^tuple

Attributes

center[R]

Coordinates of this node

depth[R]

Coordinates of this node

lower[R]

Coordinates of this node

refob[RW]

Reference object for this node

tuple[R]

Coordinates of this node

upper[R]

Coordinates of this node

Public Class Methods

new(vupper, vlower, depth) click to toggle source
# File lib/k-tree/k-tree.rb, line 32
def initialize(vupper, vlower, depth)
  @upper = vupper
  @lower = vlower
  @depth = depth
  @center = (vupper + vlower) / 2.0
  @tuple = vupper.size
end

Public Instance Methods

children() click to toggle source
# File lib/k-tree/k-tree.rb, line 40
def children; @children ||= []; end
create_children(&block) click to toggle source

recursive function to create child nodes.

# File lib/k-tree/k-tree.rb, line 54
def create_children(&block)
  if block.(self, cv = ntants)
    unless @depth == 0
      @children = cv.map{|vupper, vlower| Node.new(vupper, vlower, @depth - 1)}
      @children.each{|child| child.create_children &block}
    end
  end
end
each(&block) click to toggle source
# File lib/k-tree/k-tree.rb, line 63
def each(&block)
  block.(self)
  children.each{|child| child.each &block }
end
ntants() { |*k| ... } click to toggle source

iterate through all the upper, lower vectors of the possible children

# File lib/k-tree/k-tree.rb, line 44
def ntants
  d = @upper - @center
  (0...(2**@tuple)).map do |bits|
    k = [Vector[*(0...@tuple).map{|i| (bits & (1 << 1)) == 0 ? @center[i]+d[i] : @center[i]-d[i]}], @center]
    yield *k if block_given?
    k
  end
end