Method: BiDimensionalTree#search_node
- Defined in:
- lib/bi-dimensional-access.rb
#search_node(x, y, node = @root) ⇒ Object
Locate a branch, if it exists
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bi-dimensional-access.rb', line 81 def search_node(x, y, node = @root) return nil if node.nil? if x == node.x if y == node.y return node elsif y < node.y and !node.south.nil? search_node(x, y, node.south) elsif y > node.y and !node.north.nil? search_node(x, y, node.north) else return nil end elsif x < node.x and !node.west.nil? search_node(x, y, node.west) elsif x > node.x and !node.east.nil? search_node(x, y, node.east) else return nil end end |