insertContained method

void insertContained(
  1. NodeNode tree,
  2. Envelope itemEnv,
  3. Object item
)

insert an item which is known to be contained in the tree rooted at the given QuadNode root. Lower levels of the tree will be created if necessary to hold the item.

Implementation

void insertContained(NodeNode tree, Envelope itemEnv, Object item) {
  ///
  /// Do NOT create a new quad for zero-area envelopes - this would lead
  /// to infinite recursion. Instead, use a heuristic of simply returning
  /// the smallest existing quad containing the query
  ///
  bool isZeroX =
      IntervalSize.isZeroWidth(itemEnv.getMinX(), itemEnv.getMaxX());
  bool isZeroY =
      IntervalSize.isZeroWidth(itemEnv.getMinY(), itemEnv.getMaxY());
  NodeBase? node;
  if (isZeroX || isZeroY) {
    node = tree.find(itemEnv);
  } else {
    node = tree.getNode(itemEnv);
  }
  node.add(item);
}