import SpatialError from './SpatialError'

export function addIsoNode (topo, coordinate) {
  const { nodes, nodesTree: tree, faces } = topo

  // TODO: determine true face
  const face = faces[0]

  const node = {
    id: nodes.length + 1,
    face,
    coordinate,
    equals (other) {
      return
    }
  }

  const bounds = {
    minX: coordinate[0],
    minY: coordinate[1],
    maxX: coordinate[0],
    maxY: coordinate[1],
    node
  }

  if (!tree.collides(bounds)) {
    tree.insert(bounds)
    nodes.push(node)
    return node
  } else {
    throw new SpatialError('coincident node')
  }
}

@@ -36,16 +36,374 @@
 Error'%0A%0A
+export function getNodeByPoint (topo, coordinate) %7B%0A  const result = topo.nodesTree.search(%7B%0A    minX: coordinate%5B0%5D,%0A    minY: coordinate%5B1%5D,%0A    maxX: coordinate%5B0%5D,%0A    maxY: coordinate%5B1%5D%0A  %7D)%0A  if (result.length === 0) %7B%0A    return 0%0A  %7D%0A  if (result.length === 1) %7B%0A    return result%5B0%5D%0A  %7D%0A  throw Error('getNodeByPoint: unexpected search result')%0A%7D%0A%0A
 export f
@@ -621,72 +621,8 @@
 te,%0A
-    equals (other) %7B%0A      return%0A    %7D%0A  %7D%0A%0A  const bounds = %7B%0A
     
@@ -719,18 +719,8 @@
 e%5B1%5D
-,%0A    node
 %0A  %7D
@@ -742,22 +742,20 @@
 ollides(
-bounds
+node
 )) %7B%0A   
@@ -771,14 +771,12 @@
 ert(
-bounds
+node
 )%0A  

Add getNodeByPoint