Class: KdTree::Tree

Inherits:
Object
  • Object
show all
Includes:
DataConversion, Dimensions, Finders
Defined in:
lib/ffi-kdtree/tree.rb

Constant Summary

Constants included from Dimensions

Dimensions::DIMENSIONAL_ARRAY_CLASSES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Finders

#find_nearest, #find_nearest_range

Methods included from Dimensions

#build_position, #dimensions, #distance, #distance_sq, #new_position

Constructor Details

#initialize(size, type = :object) ⇒ Tree

Returns a new instance of Tree.



14
15
16
17
18
19
20
# File 'lib/ffi-kdtree/tree.rb', line 14

def initialize(size, type = :object)
  tree_ptr = FFI::AutoPointer.new(
    LibKdTree::kd_create(size), 
    PointerHelpers::TreePointerHelper.method(:release))
  @tree = LibKdTree::Tree.new(tree_ptr)
  @type = type
end

Instance Attribute Details

#treeObject (readonly)

Returns the value of attribute tree.



8
9
10
# File 'lib/ffi-kdtree/tree.rb', line 8

def tree
  @tree
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/ffi-kdtree/tree.rb', line 8

def type
  @type
end

Instance Method Details

#add(position, value) ⇒ Object



22
23
24
25
# File 'lib/ffi-kdtree/tree.rb', line 22

def add(position, value)
  position = build_position(position) unless FFI::Struct === position
  0 == LibKdTree::kd_insert(self.tree, position, data_from_value(value))
end