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.partitioning.Region;
26  import org.hipparchus.util.FastMath;
27  import org.hipparchus.util.MathUtils;
28  import org.hipparchus.util.Precision;
29  import org.junit.Assert;
30  import org.junit.Test;
31  
32  public class ArcTest {
33  
34      @Test
35      public void testArc() {
36          Arc arc = new Arc(2.3, 5.7, 1.0e-10);
37          Assert.assertEquals(3.4, arc.getSize(), 1.0e-10);
38          Assert.assertEquals(4.0, arc.getBarycenter(), 1.0e-10);
39          Assert.assertEquals(Region.Location.BOUNDARY, arc.checkPoint(2.3));
40          Assert.assertEquals(Region.Location.BOUNDARY, arc.checkPoint(5.7));
41          Assert.assertEquals(Region.Location.OUTSIDE,  arc.checkPoint(1.2));
42          Assert.assertEquals(Region.Location.OUTSIDE,  arc.checkPoint(8.5));
43          Assert.assertEquals(Region.Location.INSIDE,   arc.checkPoint(8.7));
44          Assert.assertEquals(Region.Location.INSIDE,   arc.checkPoint(3.0));
45          Assert.assertEquals(2.3, arc.getInf(), 1.0e-10);
46          Assert.assertEquals(5.7, arc.getSup(), 1.0e-10);
47          Assert.assertEquals(4.0, arc.getBarycenter(), 1.0e-10);
48          Assert.assertEquals(3.4, arc.getSize(), 1.0e-10);
49      }
50  
51      @Test(expected=MathIllegalArgumentException.class)
52      public void testWrongInterval() {
53          new Arc(1.2, 0.0, 1.0e-10);
54      }
55  
56      @Test(expected=MathIllegalArgumentException.class)
57      public void testTooSmallTolerance() {
58          new Arc(0.0, 1.0, 0.9 * Sphere1D.SMALLEST_TOLERANCE);
59      }
60  
61      @Test
62      public void testTolerance() {
63          Assert.assertEquals(Region.Location.OUTSIDE,  new Arc(2.3, 5.7, 1.0).checkPoint(1.2));
64          Assert.assertEquals(Region.Location.BOUNDARY, new Arc(2.3, 5.7, 1.2).checkPoint(1.2));
65          Assert.assertEquals(Region.Location.OUTSIDE,  new Arc(2.3, 5.7, 0.7).checkPoint(6.5));
66          Assert.assertEquals(Region.Location.BOUNDARY, new Arc(2.3, 5.7, 0.9).checkPoint(6.5));
67          Assert.assertEquals(Region.Location.INSIDE,   new Arc(2.3, 5.7, 0.6).checkPoint(3.0));
68          Assert.assertEquals(Region.Location.BOUNDARY, new Arc(2.3, 5.7, 0.8).checkPoint(3.0));
69      }
70  
71      @Test
72      public void testFullCircle() {
73          Arc arc = new Arc(9.0, 9.0, 1.0e-10);
74          // no boundaries on a full circle
75          Assert.assertEquals(Region.Location.INSIDE, arc.checkPoint(9.0));
76          Assert.assertEquals(.0, arc.getInf(), 1.0e-10);
77          Assert.assertEquals(MathUtils.TWO_PI, arc.getSup(), 1.0e-10);
78          Assert.assertEquals(2.0 * FastMath.PI, arc.getSize(), 1.0e-10);
79          for (double alpha = -20.0; alpha <= 20.0; alpha += 0.1) {
80              Assert.assertEquals(Region.Location.INSIDE, arc.checkPoint(alpha));
81          }
82      }
83  
84      @Test
85      public void testSmall() {
86          Arc arc = new Arc(1.0, FastMath.nextAfter(1.0, Double.POSITIVE_INFINITY), 1.01 * Sphere1D.SMALLEST_TOLERANCE);
87          Assert.assertEquals(2 * Precision.EPSILON, arc.getSize(), Precision.SAFE_MIN);
88          Assert.assertEquals(1.0, arc.getBarycenter(), Precision.EPSILON);
89      }
90  
91      /** Check {@link Arc#getOffset(double)}. */
92      @Test
93      public void testGetOffset() {
94          // setup
95          double twopi = 2 * FastMath.PI;
96          Arc arc = new Arc(twopi + 1, twopi + 2, 1e-6);
97  
98          // action & verify
99          double tol = FastMath.ulp(twopi);
100         Assert.assertEquals(arc.getOffset(0), 1, tol);
101         Assert.assertEquals(arc.getOffset(1), 0, tol);
102         Assert.assertEquals(arc.getOffset(1.5), -0.5, tol);
103         Assert.assertEquals(arc.getOffset(2), 0, tol);
104         Assert.assertEquals(arc.getOffset(3), 1, tol);
105     }
106 
107 }