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.partitioning.Hyperplane; 26 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, S1Point, LimitAngle, SubLimitAngle> { 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 S1Point point) { 71 final double delta = point.getAlpha() - location.getAlpha(); 72 return direct ? delta : -delta; 73 } 74 75 /** {@inheritDoc} */ 76 @Override 77 public S1Point moveToOffset(final S1Point point, final double offset) { 78 return new S1Point(location.getAlpha() + (direct ? offset : -offset)); 79 } 80 81 /** {@inheritDoc} */ 82 @Override 83 public S1Point arbitraryPoint() { 84 return location; 85 } 86 87 /** Check if the hyperplane orientation is direct. 88 * @return true if the plus side of the hyperplane is towards 89 * angles greater than hyperplane location 90 */ 91 public boolean isDirect() { 92 return direct; 93 } 94 95 /** Get the reverse of the instance. 96 * <p>Get a limit angle with reversed orientation with respect to the 97 * instance. A new object is built, the instance is untouched.</p> 98 * @return a new limit angle, with orientation opposite to the instance orientation 99 */ 100 public LimitAngle getReverse() { 101 return new LimitAngle(location, !direct, tolerance); 102 } 103 104 /** Build a region covering the whole hyperplane. 105 * <p>Since this class represent zero dimension spaces which does 106 * not have lower dimension sub-spaces, this method returns a dummy 107 * implementation of a {@link 108 * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}. 109 * This implementation is only used to allow the {@link 110 * org.hipparchus.geometry.partitioning.SubHyperplane 111 * SubHyperplane} class implementation to work properly, it should 112 * <em>not</em> be used otherwise.</p> 113 * @return a dummy sub hyperplane 114 */ 115 @Override 116 public SubLimitAngle wholeHyperplane() { 117 return new SubLimitAngle(this, null); 118 } 119 120 /** {@inheritDoc} 121 * <p>Since this class represent zero dimension spaces which does 122 * not have lower dimension sub-spaces, this method returns a dummy 123 * implementation of a {@link 124 * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}. 125 * This implementation is only used to allow the {@link 126 * org.hipparchus.geometry.partitioning.SubHyperplane 127 * SubHyperplane} class implementation to work properly, it should 128 * <em>not</em> be used otherwise.</p> 129 */ 130 @Override 131 public SubLimitAngle emptyHyperplane() { 132 return new SubLimitAngle(this, null); 133 } 134 135 /** Build a region covering the whole space. 136 * @return a region containing the instance (really an {@link 137 * ArcsSet IntervalsSet} instance) 138 */ 139 @Override 140 public ArcsSet wholeSpace() { 141 return new ArcsSet(tolerance); 142 } 143 144 /** {@inheritDoc} */ 145 @Override 146 public boolean sameOrientationAs(final LimitAngle other) { 147 return direct == other.direct; 148 } 149 150 /** Get the hyperplane location on the circle. 151 * @return the hyperplane location 152 */ 153 public S1Point getLocation() { 154 return location; 155 } 156 157 /** {@inheritDoc} */ 158 @Override 159 public S1Point project(S1Point point) { 160 return location; 161 } 162 163 /** {@inheritDoc} */ 164 @Override 165 public double getTolerance() { 166 return tolerance; 167 } 168 169 }