[ 
https://issues.apache.org/jira/browse/GEOMETRY-32?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16780046#comment-16780046
 ] 

Matt Juntunen commented on GEOMETRY-32:
---------------------------------------

Hi, guys. I've been working out the {{BSPTree}} API and I could use some 
feedback. So far I have a set of {{BSPTree}} interfaces and the beginnings of 
an {{AbstractBSPTree}} class that implements the primary BSP functionality but 
without the logic for merging nodes, which will vary depending on what the tree 
is being used for. The overall design is similar to the JDK's {{Map}}, 
{{Map.Entry}}, and {{AbstractMap}} types. Here are the highlights:

{code:java}
// P = Point implementation type
// T = Node attribute type

public interface BSPTreeTraversal<P extends Point<P>, T> {

    void visit(BSPTreeVisitor<P, T> visitor);

    Node<P, T> findNode(P pt);
}

public interface BSPTree<P extends Point<P>, T> extends BSPTreeTraversal<P, T> {

    Node<P, T> getRoot();

    public static interface Node<P extends Point<P>, T> extends 
BSPTreeTraversal<P, T> {

        BSPTree<P, T> getTree();

        Node<P, T> getParent();

        ConvexSubHyperplane<P> getCut();

        Node<P, T> getPlus();
        Node<P, T> getMinus();

        T getAttribute();
        void setAttribute(T attribute);

        boolean isLeaf();
        boolean isPlus();
        boolean isMinus();

        boolean insertCut(Hyperplane<P> cutter);

        // fluent API methods
        Node<P, T> cut(Hyperplane<P> cutter);
        Node<P, T> attr(T attribute);
    }
}
{code}

Here is some example usage from a unit test (using some concrete test classes):

{code:java}
       // arrange
       TestBSPTree tree = new TestBSPTree();

        Node<TestPoint2D, Integer> node = tree.getRoot()
            .cut(new TestLine(0, 0, 1, 0))
            .getMinus()
                .cut(new TestLine(0, 1, 0, 2))
                .getPlus()
                    .attr(1);

        // act
        boolean result = node.insertCut(new TestLine(0, 2, 2, 0));

        // assert
        Assert.assertTrue(result);

        TestLineSegment segment = (TestLineSegment) node.getCut();

        PartitionTestUtils.assertPointsEqual(new TestPoint2D(0, 2), 
segment.getStartPoint());
        PartitionTestUtils.assertPointsEqual(new TestPoint2D(2, 0), 
segment.getEndPoint());
{code}
Thoughts?

> BSPTree Updates
> ---------------
>
>                 Key: GEOMETRY-32
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-32
>             Project: Apache Commons Geometry
>          Issue Type: Improvement
>          Components: core
>            Reporter: Matt Juntunen
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The following updates should be made to the BSPTree class:
> - add an {{isLeaf()}} method to replace all of the {{node.getCut() == null}} 
> expressions
> - add unit tests
> _Edit [2019-02-17]:_
> Additional goals:
> - Refactor the API to split the idea of a general BSPTree and a BSPTree used 
> for defining in/out regions. This could result in a BSPTree interface and a 
> RegionBSPTree interface. The goal here is to allow end-users to create their 
> own extensions of these classes and specialize them for their own 
> applications (for example, to implement spatial sorting or other algorithms). 
> This will be one of the only planned extension points in the library.
> - Make the API easier to use and extend and reduce the necessity of casting 
> (especially unchecked casting) as much as possible.
> - Add the idea of convex subhyperplanes to allow for more efficient tree 
> construction.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to