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 agents.anac.y2019.harddealer.math3.geometry.partitioning;
|
---|
18 |
|
---|
19 | import agents.anac.y2019.harddealer.math3.geometry.Space;
|
---|
20 |
|
---|
21 | /** This interface represents the remaining parts of an hyperplane after
|
---|
22 | * other parts have been chopped off.
|
---|
23 |
|
---|
24 | * <p>sub-hyperplanes are obtained when parts of an {@link
|
---|
25 | * Hyperplane hyperplane} are chopped off by other hyperplanes that
|
---|
26 | * intersect it. The remaining part is a convex region. Such objects
|
---|
27 | * appear in {@link BSPTree BSP trees} as the intersection of a cut
|
---|
28 | * hyperplane with the convex region which it splits, the chopping
|
---|
29 | * hyperplanes are the cut hyperplanes closer to the tree root.</p>
|
---|
30 |
|
---|
31 | * <p>
|
---|
32 | * Note that this interface is <em>not</em> intended to be implemented
|
---|
33 | * by Apache Commons Math users, it is only intended to be implemented
|
---|
34 | * within the library itself. New methods may be added even for minor
|
---|
35 | * versions, which breaks compatibility for external implementations.
|
---|
36 | * </p>
|
---|
37 |
|
---|
38 | * @param <S> Type of the embedding space.
|
---|
39 |
|
---|
40 | * @since 3.0
|
---|
41 | */
|
---|
42 | public interface SubHyperplane<S extends Space> {
|
---|
43 |
|
---|
44 | /** Copy the instance.
|
---|
45 | * <p>The instance created is completely independent of the original
|
---|
46 | * one. A deep copy is used, none of the underlying objects are
|
---|
47 | * shared (except for the nodes attributes and immutable
|
---|
48 | * objects).</p>
|
---|
49 | * @return a new sub-hyperplane, copy of the instance
|
---|
50 | */
|
---|
51 | SubHyperplane<S> copySelf();
|
---|
52 |
|
---|
53 | /** Get the underlying hyperplane.
|
---|
54 | * @return underlying hyperplane
|
---|
55 | */
|
---|
56 | Hyperplane<S> getHyperplane();
|
---|
57 |
|
---|
58 | /** Check if the instance is empty.
|
---|
59 | * @return true if the instance is empty
|
---|
60 | */
|
---|
61 | boolean isEmpty();
|
---|
62 |
|
---|
63 | /** Get the size of the instance.
|
---|
64 | * @return the size of the instance (this is a length in 1D, an area
|
---|
65 | * in 2D, a volume in 3D ...)
|
---|
66 | */
|
---|
67 | double getSize();
|
---|
68 |
|
---|
69 | /** Compute the relative position of the instance with respect
|
---|
70 | * to an hyperplane.
|
---|
71 | * @param hyperplane hyperplane to check instance against
|
---|
72 | * @return one of {@link Side#PLUS}, {@link Side#MINUS}, {@link Side#BOTH},
|
---|
73 | * {@link Side#HYPER}
|
---|
74 | * @deprecated as of 3.6, replaced with {@link #split(Hyperplane)}.{@link SplitSubHyperplane#getSide()}
|
---|
75 | */
|
---|
76 | @Deprecated
|
---|
77 | Side side(Hyperplane<S> hyperplane);
|
---|
78 |
|
---|
79 | /** Split the instance in two parts by an hyperplane.
|
---|
80 | * @param hyperplane splitting hyperplane
|
---|
81 | * @return an object containing both the part of the instance
|
---|
82 | * on the plus side of the hyperplane and the part of the
|
---|
83 | * instance on the minus side of the hyperplane
|
---|
84 | */
|
---|
85 | SplitSubHyperplane<S> split(Hyperplane<S> hyperplane);
|
---|
86 |
|
---|
87 | /** Compute the union of the instance and another sub-hyperplane.
|
---|
88 | * @param other other sub-hyperplane to union (<em>must</em> be in the
|
---|
89 | * same hyperplane as the instance)
|
---|
90 | * @return a new sub-hyperplane, union of the instance and other
|
---|
91 | */
|
---|
92 | SubHyperplane<S> reunite(SubHyperplane<S> other);
|
---|
93 |
|
---|
94 | /** Class holding the results of the {@link #split split} method.
|
---|
95 | * @param <U> Type of the embedding space.
|
---|
96 | */
|
---|
97 | class SplitSubHyperplane<U extends Space> {
|
---|
98 |
|
---|
99 | /** Part of the sub-hyperplane on the plus side of the splitting hyperplane. */
|
---|
100 | private final SubHyperplane<U> plus;
|
---|
101 |
|
---|
102 | /** Part of the sub-hyperplane on the minus side of the splitting hyperplane. */
|
---|
103 | private final SubHyperplane<U> minus;
|
---|
104 |
|
---|
105 | /** Build a SplitSubHyperplane from its parts.
|
---|
106 | * @param plus part of the sub-hyperplane on the plus side of the
|
---|
107 | * splitting hyperplane
|
---|
108 | * @param minus part of the sub-hyperplane on the minus side of the
|
---|
109 | * splitting hyperplane
|
---|
110 | */
|
---|
111 | public SplitSubHyperplane(final SubHyperplane<U> plus,
|
---|
112 | final SubHyperplane<U> minus) {
|
---|
113 | this.plus = plus;
|
---|
114 | this.minus = minus;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** Get the part of the sub-hyperplane on the plus side of the splitting hyperplane.
|
---|
118 | * @return part of the sub-hyperplane on the plus side of the splitting hyperplane
|
---|
119 | */
|
---|
120 | public SubHyperplane<U> getPlus() {
|
---|
121 | return plus;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /** Get the part of the sub-hyperplane on the minus side of the splitting hyperplane.
|
---|
125 | * @return part of the sub-hyperplane on the minus side of the splitting hyperplane
|
---|
126 | */
|
---|
127 | public SubHyperplane<U> getMinus() {
|
---|
128 | return minus;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Get the side of the split sub-hyperplane with respect to its splitter.
|
---|
132 | * @return {@link Side#PLUS} if only {@link #getPlus()} is neither null nor empty,
|
---|
133 | * {@link Side#MINUS} if only {@link #getMinus()} is neither null nor empty,
|
---|
134 | * {@link Side#BOTH} if both {@link #getPlus()} and {@link #getMinus()}
|
---|
135 | * are neither null nor empty or {@link Side#HYPER} if both {@link #getPlus()} and
|
---|
136 | * {@link #getMinus()} are either null or empty
|
---|
137 | * @since 3.6
|
---|
138 | */
|
---|
139 | public Side getSide() {
|
---|
140 | if (plus != null && !plus.isEmpty()) {
|
---|
141 | if (minus != null && !minus.isEmpty()) {
|
---|
142 | return Side.BOTH;
|
---|
143 | } else {
|
---|
144 | return Side.PLUS;
|
---|
145 | }
|
---|
146 | } else if (minus != null && !minus.isEmpty()) {
|
---|
147 | return Side.MINUS;
|
---|
148 | } else {
|
---|
149 | return Side.HYPER;
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | }
|
---|
154 |
|
---|
155 | }
|
---|