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    *      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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.geometry.spherical.oned;
23  
24  import org.hipparchus.exception.MathIllegalArgumentException;
25  import org.hipparchus.geometry.Point;
26  import org.hipparchus.geometry.partitioning.Hyperplane;
27  
28  /** This class represents a 1D oriented hyperplane on the circle.
29   * <p>An hyperplane on the 1-sphere is an angle with an orientation.</p>
30   * <p>Instances of this class are guaranteed to be immutable.</p>
31   */
32  public class LimitAngle implements Hyperplane<Sphere1D> {
33  
34      /** Angle location. */
35      private final S1Point location;
36  
37      /** Orientation. */
38      private final boolean direct;
39  
40      /** Tolerance below which angles are considered identical. */
41      private final double tolerance;
42  
43      /** Simple constructor.
44       * @param location location of the hyperplane
45       * @param direct if true, the plus side of the hyperplane is towards
46       * angles greater than {@code location}
47       * @param tolerance tolerance below which angles are considered identical
48       * @exception MathIllegalArgumentException if tolerance is smaller than {@link Sphere1D#SMALLEST_TOLERANCE}
49       */
50      public LimitAngle(final S1Point location, final boolean direct, final double tolerance)
51          throws MathIllegalArgumentException {
52          Sphere1D.checkTolerance(tolerance);
53          this.location  = location;
54          this.direct    = direct;
55          this.tolerance = tolerance;
56      }
57  
58      /** Copy the instance.
59       * <p>Since instances are immutable, this method directly returns
60       * the instance.</p>
61       * @return the instance itself
62       */
63      @Override
64      public LimitAngle copySelf() {
65          return this;
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public double getOffset(final Point<Sphere1D> point) {
71          final double delta = ((S1Point) point).getAlpha() - location.getAlpha();
72          return direct ? delta : -delta;
73      }
74  
75      /** Check if the hyperplane orientation is direct.
76       * @return true if the plus side of the hyperplane is towards
77       * angles greater than hyperplane location
78       */
79      public boolean isDirect() {
80          return direct;
81      }
82  
83      /** Get the reverse of the instance.
84       * <p>Get a limit angle with reversed orientation with respect to the
85       * instance. A new object is built, the instance is untouched.</p>
86       * @return a new limit angle, with orientation opposite to the instance orientation
87       */
88      public LimitAngle getReverse() {
89          return new LimitAngle(location, !direct, tolerance);
90      }
91  
92      /** Build a region covering the whole hyperplane.
93       * <p>Since this class represent zero dimension spaces which does
94       * not have lower dimension sub-spaces, this method returns a dummy
95       * implementation of a {@link
96       * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}.
97       * This implementation is only used to allow the {@link
98       * org.hipparchus.geometry.partitioning.SubHyperplane
99       * SubHyperplane} class implementation to work properly, it should
100      * <em>not</em> be used otherwise.</p>
101      * @return a dummy sub hyperplane
102      */
103     @Override
104     public SubLimitAngle wholeHyperplane() {
105         return new SubLimitAngle(this, null);
106     }
107 
108     /** {@inheritDoc}
109      * <p>Since this class represent zero dimension spaces which does
110      * not have lower dimension sub-spaces, this method returns a dummy
111      * implementation of a {@link
112      * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}.
113      * This implementation is only used to allow the {@link
114      * org.hipparchus.geometry.partitioning.SubHyperplane
115      * SubHyperplane} class implementation to work properly, it should
116      * <em>not</em> be used otherwise.</p>
117      */
118     @Override
119     public SubLimitAngle emptyHyperplane() {
120         return new SubLimitAngle(this, null);
121     }
122 
123     /** Build a region covering the whole space.
124      * @return a region containing the instance (really an {@link
125      * ArcsSet IntervalsSet} instance)
126      */
127     @Override
128     public ArcsSet wholeSpace() {
129         return new ArcsSet(tolerance);
130     }
131 
132     /** {@inheritDoc} */
133     @Override
134     public boolean sameOrientationAs(final Hyperplane<Sphere1D> other) {
135         return !(direct ^ ((LimitAngle) other).direct);
136     }
137 
138     /** Get the hyperplane location on the circle.
139      * @return the hyperplane location
140      */
141     public S1Point getLocation() {
142         return location;
143     }
144 
145     /** {@inheritDoc} */
146     @Override
147     public Point<Sphere1D> project(Point<Sphere1D> point) {
148         return location;
149     }
150 
151     /** {@inheritDoc} */
152     @Override
153     public double getTolerance() {
154         return tolerance;
155     }
156 
157 }