SubHyperplane.java

  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.  *      https://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. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */
  21. package org.hipparchus.geometry.partitioning;

  22. import org.hipparchus.geometry.Point;
  23. import org.hipparchus.geometry.Space;

  24. /** This interface represents the remaining parts of an hyperplane after
  25.  * other parts have been chopped off.

  26.  * <p>sub-hyperplanes are obtained when parts of an {@link
  27.  * Hyperplane hyperplane} are chopped off by other hyperplanes that
  28.  * intersect it. The remaining part is a convex region. Such objects
  29.  * appear in {@link BSPTree BSP trees} as the intersection of a cut
  30.  * hyperplane with the convex region which it splits, the chopping
  31.  * hyperplanes are the cut hyperplanes closer to the tree root.</p>

  32.  * <p>
  33.  * Note that this interface is <em>not</em> intended to be implemented
  34.  * by Hipparchus users, it is only intended to be implemented
  35.  * within the library itself. New methods may be added even for minor
  36.  * versions, which breaks compatibility for external implementations.
  37.  * </p>

  38.  * @param <S> Type of the space.
  39.  * @param <P> Type of the points in space.
  40.  * @param <H> Type of the hyperplane.
  41.  * @param <I> Type of the sub-hyperplane.

  42.  */
  43. public interface SubHyperplane<S extends Space,
  44.                                P extends Point<S, P>,
  45.                                H extends Hyperplane<S, P, H, I>,
  46.                                I extends SubHyperplane<S, P, H, I>> {

  47.     /** Copy the instance.
  48.      * <p>The instance created is completely independent from the original
  49.      * one. A deep copy is used, none of the underlying objects are
  50.      * shared (except for the nodes attributes and immutable
  51.      * objects).</p>
  52.      * @return a new sub-hyperplane, copy of the instance
  53.      */
  54.     I copySelf();

  55.     /** Get the underlying hyperplane.
  56.      * @return underlying hyperplane
  57.      */
  58.     H getHyperplane();

  59.     /** Check if the instance is empty.
  60.      * @return true if the instance is empty
  61.      */
  62.     boolean isEmpty();

  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.     /** Split the instance in two parts by an hyperplane.
  69.      * @param hyperplane splitting hyperplane
  70.      * @return an object containing both the part of the instance
  71.      * on the plus side of the hyperplane and the part of the
  72.      * instance on the minus side of the hyperplane
  73.      */
  74.     SplitSubHyperplane<S, P, H, I> split(H hyperplane);

  75.     /** Compute the union of the instance and another sub-hyperplane.
  76.      * @param other other sub-hyperplane to union (<em>must</em> be in the
  77.      * same hyperplane as the instance)
  78.      * @return a new sub-hyperplane, union of the instance and other
  79.      */
  80.     I reunite(I other);

  81.     /** Get an interior point.
  82.      * @return an arbitrary interior point, or null if sub-hyperplane is empty
  83.      * @since 4.0
  84.      */
  85.     P getInteriorPoint();

  86.     /** Class holding the results of the {@link #split split} method.
  87.      * @param <U> Type of the embedding space.
  88.      * @param <R> Type of the points in the embedding space.
  89.      * @param <F> Type of the hyperplane.
  90.      * @param <J> Type of the sub-hyperplane.
  91.      */
  92.     class SplitSubHyperplane<U extends Space, R extends Point<U, R>, F extends Hyperplane<U, R, F, J>, J extends SubHyperplane<U, R, F, J>> {

  93.         /** Part of the sub-hyperplane on the plus side of the splitting hyperplane. */
  94.         private final J plus;

  95.         /** Part of the sub-hyperplane on the minus side of the splitting hyperplane. */
  96.         private final J minus;

  97.         /** Build a SplitSubHyperplane from its parts.
  98.          * @param plus part of the sub-hyperplane on the plus side of the
  99.          * splitting hyperplane
  100.          * @param minus part of the sub-hyperplane on the minus side of the
  101.          * splitting hyperplane
  102.          */
  103.         public SplitSubHyperplane(final J plus, final J minus) {
  104.             this.plus  = plus;
  105.             this.minus = minus;
  106.         }

  107.         /** Get the part of the sub-hyperplane on the plus side of the splitting hyperplane.
  108.          * @return part of the sub-hyperplane on the plus side of the splitting hyperplane
  109.          */
  110.         public J getPlus() {
  111.             return plus;
  112.         }

  113.         /** Get the part of the sub-hyperplane on the minus side of the splitting hyperplane.
  114.          * @return part of the sub-hyperplane on the minus side of the splitting hyperplane
  115.          */
  116.         public J getMinus() {
  117.             return minus;
  118.         }

  119.         /** Get the side of the split sub-hyperplane with respect to its splitter.
  120.          * @return {@link Side#PLUS} if only {@link #getPlus()} is neither null nor empty,
  121.          * {@link Side#MINUS} if only {@link #getMinus()} is neither null nor empty,
  122.          * {@link Side#BOTH} if both {@link #getPlus()} and {@link #getMinus()}
  123.          * are neither null nor empty or {@link Side#HYPER} if both {@link #getPlus()} and
  124.          * {@link #getMinus()} are either null or empty
  125.          */
  126.         public Side getSide() {
  127.             if (plus != null && !plus.isEmpty()) {
  128.                 if (minus != null && !minus.isEmpty()) {
  129.                     return Side.BOTH;
  130.                 } else {
  131.                     return Side.PLUS;
  132.                 }
  133.             } else if (minus != null && !minus.isEmpty()) {
  134.                 return Side.MINUS;
  135.             } else {
  136.                 return Side.HYPER;
  137.             }
  138.         }

  139.     }

  140. }