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.spherical.twod;
18  
19  import java.util.List;
20  
21  import org.apache.commons.geometry.core.RegionEmbedding;
22  import org.apache.commons.geometry.core.RegionLocation;
23  import org.apache.commons.geometry.core.internal.HyperplaneSubsets;
24  import org.apache.commons.geometry.core.partitioning.HyperplaneBoundedRegion;
25  import org.apache.commons.geometry.core.partitioning.HyperplaneSubset;
26  import org.apache.commons.geometry.spherical.oned.Point1S;
27  import org.apache.commons.numbers.core.Precision;
28  
29  /** Class representing a subset of the points in a great circle.
30   * @see GreatCircles
31   */
32  public abstract class GreatCircleSubset implements HyperplaneSubset<Point2S>, RegionEmbedding<Point2S, Point1S> {
33      /** The great circle defining this instance. */
34      private final GreatCircle circle;
35  
36      /** Simple constructor.
37       * @param circle great circle defining this instance
38       */
39      GreatCircleSubset(final GreatCircle circle) {
40          this.circle = circle;
41      }
42  
43      /** Get the great circle defining this instance.
44       * @return the great circle defining this instance
45       * @see #getHyperplane()
46       */
47      public GreatCircle getCircle() {
48          return circle;
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public GreatCircle getHyperplane() {
54          return getCircle();
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public Point1S toSubspace(final Point2S pt) {
60          return circle.toSubspace(pt);
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public Point2S toSpace(final Point1S pt) {
66          return circle.toSpace(pt);
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public boolean isFull() {
72          return getSubspaceRegion().isFull();
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public boolean isEmpty() {
78          return getSubspaceRegion().isEmpty();
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public double getSize() {
84          return getSubspaceRegion().getSize();
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public Point2S getCentroid() {
90          final Point1S subspaceCentroid = getSubspaceRegion().getCentroid();
91          if (subspaceCentroid != null) {
92              return getCircle().toSpace(subspaceCentroid);
93          }
94          return null;
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public RegionLocation classify(final Point2S pt) {
100         return HyperplaneSubsets.classifyAgainstEmbeddedRegion(pt, circle, getSubspaceRegion());
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public Point2S closest(final Point2S pt) {
106         return HyperplaneSubsets.closestToEmbeddedRegion(pt, circle, getSubspaceRegion());
107     }
108 
109     /** {@inheritDoc} */
110     @Override
111     public abstract List<GreatArc> toConvex();
112 
113     /** {@inheritDoc} */
114     @Override
115     public abstract HyperplaneBoundedRegion<Point1S> getSubspaceRegion();
116 
117     /** Return the object used to perform floating point comparisons, which is the
118      * same object used by the underlying {@link GreatCircle}.
119      * @return precision object used to perform floating point comparisons.
120      */
121     public Precision.DoubleEquivalence getPrecision() {
122         return circle.getPrecision();
123     }
124 }