View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.geometry.core.partitioning.test;
18  
19  import org.apache.commons.geometry.core.RegionLocation;
20  import org.apache.commons.geometry.core.partitioning.Hyperplane;
21  import org.apache.commons.geometry.core.partitioning.HyperplaneConvexSubset;
22  import org.apache.commons.geometry.core.partitioning.Split;
23  import org.apache.commons.geometry.core.partitioning.bsp.AbstractBSPTree;
24  import org.apache.commons.geometry.core.partitioning.bsp.AbstractRegionBSPTree;
25  import org.apache.commons.geometry.core.partitioning.bsp.RegionCutRule;
26  
27  /**  Region BSP Tree implementation class for testing purposes.
28   */
29  public final class TestRegionBSPTree extends AbstractRegionBSPTree<TestPoint2D, TestRegionBSPTree.TestRegionNode> {
30  
31      public TestRegionBSPTree() {
32          this(true);
33      }
34  
35      public TestRegionBSPTree(final boolean full) {
36          super(full);
37      }
38  
39      /**
40       * Expose the direct node cut method for easier creation of test tree structures.
41       */
42      public void cutNode(final TestRegionNode node, final HyperplaneConvexSubset<TestPoint2D> cut) {
43          super.setNodeCut(node, cut, getSubtreeInitializer(RegionCutRule.MINUS_INSIDE));
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      protected TestRegionNode createNode() {
49          return new TestRegionNode(this);
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      protected RegionSizeProperties<TestPoint2D> computeRegionSizeProperties() {
55          // return a set of stub values
56          return new RegionSizeProperties<>(1234, new TestPoint2D(12, 34));
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public boolean contains(final TestPoint2D pt) {
62          return classify(pt) != RegionLocation.OUTSIDE;
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public Split<TestRegionBSPTree> split(final Hyperplane<TestPoint2D> splitter) {
68          return split(splitter, new TestRegionBSPTree(), new TestRegionBSPTree());
69      }
70  
71      /** BSP Tree node class for {@link TestRegionBSPTree}.
72       */
73      public static final class TestRegionNode
74          extends AbstractRegionBSPTree.AbstractRegionNode<TestPoint2D, TestRegionNode> {
75  
76          TestRegionNode(final AbstractBSPTree<TestPoint2D, TestRegionNode> tree) {
77              super(tree);
78          }
79  
80          /** {@inheritDoc} */
81          @Override
82          protected TestRegionNode getSelf() {
83              return this;
84          }
85      }
86  }