insert method

void insert(
  1. Envelope itemEnv,
  2. Object item
)

Insert an item into the quadtree this is the root of. /

Implementation

void insert(Envelope itemEnv, Object item) {
  int index = NodeBase.getSubnodeIndex(itemEnv, origin.x, origin.y);
  // if index is -1, itemEnv must cross the X or Y axis.
  if (index == -1) {
    add(item);
    return;
  }

  ///
  /// the item must be contained in one quadrant, so insert it into the
  /// tree for that quadrant (which may not yet exist)
  ////
  NodeNode? node = subnode[index];

  ///
  ///  If the subquad doesn't exist or this item is not contained in it,
  ///  have to expand the tree upward to contain the item.
  ////

  if (node == null || !node.getEnvelope()!.containsEnvelope(itemEnv)) {
    NodeNode? largerNode = NodeNode.createExpanded(node, itemEnv);
    subnode[index] = largerNode;
  }

  ///
  /// At this point we have a subquad which exists and must contain
  /// contains the env for the item.  Insert the item into the tree.
  ////
  insertContained(subnode[index]!, itemEnv, item);
  //System.out.println("depth = " + root.depth() + " size = " + root.size());
  //System.out.println(" size = " + size());
}