1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
98 @Test
99 void testGetOffset() {
100
101 double twopi = 2 * FastMath.PI;
102 Arc arc = new Arc(twopi + 1, twopi + 2, 1e-6);
103
104
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 }