LimitAngle.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.spherical.oned;

  22. import org.hipparchus.exception.MathIllegalArgumentException;
  23. import org.hipparchus.geometry.partitioning.Hyperplane;


  24. /** This class represents a 1D oriented hyperplane on the circle.
  25.  * <p>An hyperplane on the 1-sphere is an angle with an orientation.</p>
  26.  * <p>Instances of this class are guaranteed to be immutable.</p>
  27.  */
  28. public class LimitAngle implements Hyperplane<Sphere1D, S1Point, LimitAngle, SubLimitAngle> {

  29.     /** Angle location. */
  30.     private final S1Point location;

  31.     /** Orientation. */
  32.     private final boolean direct;

  33.     /** Tolerance below which angles are considered identical. */
  34.     private final double tolerance;

  35.     /** Simple constructor.
  36.      * @param location location of the hyperplane
  37.      * @param direct if true, the plus side of the hyperplane is towards
  38.      * angles greater than {@code location}
  39.      * @param tolerance tolerance below which angles are considered identical
  40.      * @exception MathIllegalArgumentException if tolerance is smaller than {@link Sphere1D#SMALLEST_TOLERANCE}
  41.      */
  42.     public LimitAngle(final S1Point location, final boolean direct, final double tolerance)
  43.         throws MathIllegalArgumentException {
  44.         Sphere1D.checkTolerance(tolerance);
  45.         this.location  = location;
  46.         this.direct    = direct;
  47.         this.tolerance = tolerance;
  48.     }

  49.     /** Copy the instance.
  50.      * <p>Since instances are immutable, this method directly returns
  51.      * the instance.</p>
  52.      * @return the instance itself
  53.      */
  54.     @Override
  55.     public LimitAngle copySelf() {
  56.         return this;
  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public double getOffset(final S1Point point) {
  61.         final double delta = point.getAlpha() - location.getAlpha();
  62.         return direct ? delta : -delta;
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public S1Point moveToOffset(final S1Point point, final double offset) {
  67.         return new S1Point(location.getAlpha() + (direct ? offset : -offset));
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public S1Point arbitraryPoint() {
  72.         return location;
  73.     }

  74.     /** Check if the hyperplane orientation is direct.
  75.      * @return true if the plus side of the hyperplane is towards
  76.      * angles greater than hyperplane location
  77.      */
  78.     public boolean isDirect() {
  79.         return direct;
  80.     }

  81.     /** Get the reverse of the instance.
  82.      * <p>Get a limit angle with reversed orientation with respect to the
  83.      * instance. A new object is built, the instance is untouched.</p>
  84.      * @return a new limit angle, with orientation opposite to the instance orientation
  85.      */
  86.     public LimitAngle getReverse() {
  87.         return new LimitAngle(location, !direct, tolerance);
  88.     }

  89.     /** Build a region covering the whole hyperplane.
  90.      * <p>Since this class represent zero dimension spaces which does
  91.      * not have lower dimension sub-spaces, this method returns a dummy
  92.      * implementation of a {@link
  93.      * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}.
  94.      * This implementation is only used to allow the {@link
  95.      * org.hipparchus.geometry.partitioning.SubHyperplane
  96.      * SubHyperplane} class implementation to work properly, it should
  97.      * <em>not</em> be used otherwise.</p>
  98.      * @return a dummy sub hyperplane
  99.      */
  100.     @Override
  101.     public SubLimitAngle wholeHyperplane() {
  102.         return new SubLimitAngle(this, null);
  103.     }

  104.     /** {@inheritDoc}
  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.      */
  114.     @Override
  115.     public SubLimitAngle emptyHyperplane() {
  116.         return new SubLimitAngle(this, null);
  117.     }

  118.     /** Build a region covering the whole space.
  119.      * @return a region containing the instance (really an {@link
  120.      * ArcsSet IntervalsSet} instance)
  121.      */
  122.     @Override
  123.     public ArcsSet wholeSpace() {
  124.         return new ArcsSet(tolerance);
  125.     }

  126.     /** {@inheritDoc} */
  127.     @Override
  128.     public boolean sameOrientationAs(final LimitAngle other) {
  129.         return direct == other.direct;
  130.     }

  131.     /** Get the hyperplane location on the circle.
  132.      * @return the hyperplane location
  133.      */
  134.     public S1Point getLocation() {
  135.         return location;
  136.     }

  137.     /** {@inheritDoc} */
  138.     @Override
  139.     public S1Point project(S1Point point) {
  140.         return location;
  141.     }

  142.     /** {@inheritDoc} */
  143.     @Override
  144.     public double getTolerance() {
  145.         return tolerance;
  146.     }

  147. }