GreatCircleSubset.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.  *      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.spherical.twod;

  18. import java.util.List;

  19. import org.apache.commons.geometry.core.RegionEmbedding;
  20. import org.apache.commons.geometry.core.RegionLocation;
  21. import org.apache.commons.geometry.core.internal.HyperplaneSubsets;
  22. import org.apache.commons.geometry.core.partitioning.HyperplaneBoundedRegion;
  23. import org.apache.commons.geometry.core.partitioning.HyperplaneSubset;
  24. import org.apache.commons.geometry.spherical.oned.Point1S;
  25. import org.apache.commons.numbers.core.Precision;

  26. /** Class representing a subset of the points in a great circle.
  27.  * @see GreatCircles
  28.  */
  29. public abstract class GreatCircleSubset implements HyperplaneSubset<Point2S>, RegionEmbedding<Point2S, Point1S> {
  30.     /** The great circle defining this instance. */
  31.     private final GreatCircle circle;

  32.     /** Simple constructor.
  33.      * @param circle great circle defining this instance
  34.      */
  35.     GreatCircleSubset(final GreatCircle circle) {
  36.         this.circle = circle;
  37.     }

  38.     /** Get the great circle defining this instance.
  39.      * @return the great circle defining this instance
  40.      * @see #getHyperplane()
  41.      */
  42.     public GreatCircle getCircle() {
  43.         return circle;
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public GreatCircle getHyperplane() {
  48.         return getCircle();
  49.     }

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     public Point1S toSubspace(final Point2S pt) {
  53.         return circle.toSubspace(pt);
  54.     }

  55.     /** {@inheritDoc} */
  56.     @Override
  57.     public Point2S toSpace(final Point1S pt) {
  58.         return circle.toSpace(pt);
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public boolean isFull() {
  63.         return getSubspaceRegion().isFull();
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     public boolean isEmpty() {
  68.         return getSubspaceRegion().isEmpty();
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public double getSize() {
  73.         return getSubspaceRegion().getSize();
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public Point2S getCentroid() {
  78.         final Point1S subspaceCentroid = getSubspaceRegion().getCentroid();
  79.         if (subspaceCentroid != null) {
  80.             return getCircle().toSpace(subspaceCentroid);
  81.         }
  82.         return null;
  83.     }

  84.     /** {@inheritDoc} */
  85.     @Override
  86.     public RegionLocation classify(final Point2S pt) {
  87.         return HyperplaneSubsets.classifyAgainstEmbeddedRegion(pt, circle, getSubspaceRegion());
  88.     }

  89.     /** {@inheritDoc} */
  90.     @Override
  91.     public Point2S closest(final Point2S pt) {
  92.         return HyperplaneSubsets.closestToEmbeddedRegion(pt, circle, getSubspaceRegion());
  93.     }

  94.     /** {@inheritDoc} */
  95.     @Override
  96.     public abstract List<GreatArc> toConvex();

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public abstract HyperplaneBoundedRegion<Point1S> getSubspaceRegion();

  100.     /** Return the object used to perform floating point comparisons, which is the
  101.      * same object used by the underlying {@link GreatCircle}.
  102.      * @return precision object used to perform floating point comparisons.
  103.      */
  104.     public Precision.DoubleEquivalence getPrecision() {
  105.         return circle.getPrecision();
  106.     }
  107. }