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