001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.geometry.core.partitioning.bsp;
018
019import org.apache.commons.geometry.core.Point;
020
021/** Interface for types that form the root of BSP subtrees. This includes trees
022 * themselves as well as each node in a tree.
023 * @param <P> Point implementation type
024 * @param <N> Node implementation type
025 * @see BSPTree
026 */
027public interface BSPSubtree<P extends Point<P>, N extends BSPTree.Node<P, N>> {
028
029    /** Return the total number of nodes in the subtree.
030     * @return the total number of nodes in the subtree.
031     */
032    int count();
033
034    /** The height of the subtree, ie the length of the longest downward path from
035     * the subtree root to a leaf node. A leaf node has a height of 0.
036     * @return the height of the subtree.
037     */
038    int height();
039
040    /** Accept a visitor instance, calling it with each node from the subtree.
041     * @param visitor visitor called with each subtree node
042     */
043    void accept(BSPTreeVisitor<P, N> visitor);
044
045    /** Get an iterable for accessing the nodes in this subtree. This provides a simple
046     * alternative to {@link #accept(BSPTreeVisitor)} for accessing tree nodes but is not
047     * as powerful or flexible since the node iteration order is fixed.
048     * @return an iterable for accessing the nodes in this subtree
049     */
050    Iterable<N> nodes();
051}