1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.core.partitioning.test;
18
19 import org.apache.commons.geometry.core.partitioning.BoundarySource;
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.HyperplaneSubset;
23 import org.apache.commons.geometry.core.partitioning.bsp.AbstractBSPTree;
24
25
26
27 public final class TestBSPTree extends AbstractBSPTree<TestPoint2D, TestBSPTree.TestNode> {
28
29
30 @Override
31 protected TestNode createNode() {
32 return new TestNode(this);
33 }
34
35 public void insert(final HyperplaneSubset<TestPoint2D> sub) {
36 insert(sub.toConvex());
37 }
38
39 public void insert(final HyperplaneConvexSubset<TestPoint2D> sub) {
40 insert(sub, root -> { });
41 }
42
43 public void insert(final Iterable<? extends HyperplaneConvexSubset<TestPoint2D>> subs) {
44 subs.forEach(this::insert);
45 }
46
47 public void insert(final BoundarySource<TestLineSegment> src) {
48 src.boundaryStream().forEach(this::insert);
49 }
50
51
52
53
54
55 @Override
56 public void splitIntoTrees(final Hyperplane<TestPoint2D> splitter,
57 final AbstractBSPTree<TestPoint2D, TestBSPTree.TestNode> minus,
58 final AbstractBSPTree<TestPoint2D, TestBSPTree.TestNode> plus) {
59
60 super.splitIntoTrees(splitter, minus, plus);
61 }
62
63 @Override
64 protected void copyNodeProperties(final TestNode src, final TestNode dst) {
65
66 }
67
68
69
70 public static class TestNode extends AbstractBSPTree.AbstractNode<TestPoint2D, TestNode> {
71 public TestNode(final AbstractBSPTree<TestPoint2D, TestNode> tree) {
72 super(tree);
73 }
74
75
76
77
78
79
80
81
82 public TestNode cut(final Hyperplane<TestPoint2D> cutter) {
83 insertCut(cutter);
84
85 return this;
86 }
87
88 public boolean insertCut(final Hyperplane<TestPoint2D> cutter) {
89 return ((TestBSPTree) getTree()).cutNode(getSelf(), cutter, root -> { });
90 }
91
92 public boolean clearCut() {
93 return ((TestBSPTree) getTree()).removeNodeCut(getSelf());
94 }
95
96
97 @Override
98 protected TestNode getSelf() {
99 return this;
100 }
101 }
102 }