protected DR first(Q query) {
		Comparator<NS> comparator =
			query != null ? query.getBoundsComparator() : getDefaultBoundsComparator();
		var visitor = new TreeRecordVisitor() {
			DR result;

			@Override
			protected VisitResult beginNode(NR parent, NR n, QueryInclusion inclusion) {
				if (result != null && comparator.compare(result.getBounds(), n.getShape()) <= 0) {
					// Assumes iteration is in same order as comparator
					return VisitResult.ASCEND;
				}
				if (inclusion == QueryInclusion.NONE) {
					return VisitResult.NEXT;
				}
				return VisitResult.DESCEND;
			}

			@Override
			protected VisitResult visitData(NR parent, DR d, boolean included) {
				if (result != null) {
					if (comparator.compare(result.getBounds(), d.getBounds()) <= 0) {
						// Assumes iteration is in same order as comparator
						return VisitResult.ASCEND;
					}
				}
				if (included) {
					result = d;
				}
				return VisitResult.NEXT;
			}
		};
		visit(query, visitor, true);
		return visitor.result;
	}
Called when a node is finished being visited.

This only applies to nodes into which the visitor descends. The visitor will finish a
node in one of three ways: 1) The node's children have all been visited. 2) The visitor
returned {@link VisitResult#TERMINATE} while visiting a descendant. 3) The visitor
returned {@link VisitResult#ASCEND} while visiting a child.

This method may return any result except {@link VisitResult#DESCEND}. If the visitor is
terminating, the return value of this method is ignored.

@param parent the parent of this node, or {@code null} when visiting the root
@param n the node currently being visited
@param inclusion the original inclusion of the query before descending
@return a directive for how the visitor should proceed
Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/spatial/AbstractConstraintsTree.java