1   /* Contributed in the public domain.
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS 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    *   http://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  package org.orekit.bodies;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.util.FastMath;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  
24  /**
25   * Unit tests for {@link GeodeticPoint}.
26   *
27   * @author Evan Ward
28   *
29   */
30  public class GeodeticPointTest {
31  
32      /**
33       * check {@link GeodeticPoint#GeodeticPoint(double, double, double)} angle
34       * normalization.
35       */
36      @Test
37      void testGeodeticPointAngleNormalization() {
38          // action
39          GeodeticPoint point = new GeodeticPoint(FastMath.toRadians(135),
40                  FastMath.toRadians(90 - 360), 0);
41  
42          // verify
43          Assertions.assertEquals(FastMath.toRadians(45), point.getLatitude(), 0);
44          Assertions.assertEquals(FastMath.toRadians(-90), point.getLongitude(), 0);
45  
46          Assertions.assertEquals(0, Vector3D.distance(point.getEast(),   Vector3D.PLUS_I), 1.0e-15);
47          Assertions.assertEquals(0, Vector3D.distance(point.getNorth(),  new Vector3D( 0.50 * FastMath.PI,  0.25 * FastMath.PI)), 1.0e-15);
48          Assertions.assertEquals(0, Vector3D.distance(point.getWest(),   Vector3D.MINUS_I), 1.0e-15);
49          Assertions.assertEquals(0, Vector3D.distance(point.getSouth(),  new Vector3D(-0.50 * FastMath.PI, -0.25 * FastMath.PI)), 1.0e-15);
50          Assertions.assertEquals(0, Vector3D.distance(point.getZenith(), new Vector3D(-0.50 * FastMath.PI,  0.25 * FastMath.PI)), 1.0e-15);
51          Assertions.assertEquals(0, Vector3D.distance(point.getNadir(),  new Vector3D( 0.50 * FastMath.PI, -0.25 * FastMath.PI)), 1.0e-15);
52  
53      }
54  
55      /**
56       * check {@link GeodeticPoint#GeodeticPoint(double, double, double)} for
57       * several different angles.
58       */
59      @Test
60      void testGeodeticPoint() {
61          // setup
62          // the input and expected results
63          final double pi = FastMath.PI;
64          double[][] points = {
65                  // Input lat, Input lon; expected lat, expected lon
66                  // first quadrant
67                  { pi / 6, pi / 6, pi / 6, pi / 6 },
68                  // second quadrant
69                  { 4 * pi / 6, 4 * pi / 6, pi / 3, -pi / 3 },
70                  // third quadrant
71                  { 7 * pi / 6, 7 * pi / 6, -pi / 6, pi / 6 },
72                  // fourth quadrant
73                  { -pi / 6, -pi / 6, -pi / 6, -pi / 6 },
74                  { -4 * pi / 6, -4 * pi / 6, -pi / 3, pi / 3 },
75                  { -pi / 6, -4 * pi / 3, -pi / 6, 2 * pi / 3 } };
76  
77          for (double[] point : points) {
78              // action
79              GeodeticPoint gp = new GeodeticPoint(point[0], point[1], 0);
80              Assertions.assertEquals(0, gp.getEast().crossProduct(gp.getNorth()).distance(gp.getZenith()), 1.0e-15);
81              Assertions.assertEquals(0, gp.getNorth().crossProduct(gp.getWest()).distance(gp.getZenith()), 1.0e-15);
82              Assertions.assertEquals(0, gp.getSouth().crossProduct(gp.getWest()).distance(gp.getNadir()), 1.0e-15);
83              Assertions.assertEquals(0, gp.getEast().crossProduct(gp.getSouth()).distance(gp.getNadir()), 1.0e-15);
84              Assertions.assertEquals(0, gp.getZenith().crossProduct(gp.getSouth()).distance(gp.getEast()), 1.0e-15);
85              Assertions.assertEquals(0, gp.getNadir().crossProduct(gp.getWest()).distance(gp.getNorth()), 1.0e-15);
86  
87              // verify to within 5 ulps
88              Assertions.assertEquals(point[2], gp.getLatitude(), 5 * FastMath.ulp(point[2]));
89              Assertions.assertEquals(point[3], gp.getLongitude(), 5 * FastMath.ulp(point[3]));
90          }
91      }
92  
93      /**
94       * check {@link GeodeticPoint#equals(Object)}.
95       */
96      @Test
97      void testEquals() {
98          // setup
99          GeodeticPoint point = new GeodeticPoint(1, 2, 3);
100 
101         // actions + verify
102         Assertions.assertEquals(point, new GeodeticPoint(1, 2, 3));
103         Assertions.assertFalse(point.equals(new GeodeticPoint(0, 2, 3)));
104         Assertions.assertFalse(point.equals(new GeodeticPoint(1, 0, 3)));
105         Assertions.assertFalse(point.equals(new GeodeticPoint(1, 2, 0)));
106         Assertions.assertFalse(point.equals(new Object()));
107         Assertions.assertEquals(point.hashCode(), new GeodeticPoint(1, 2, 3).hashCode());
108         Assertions.assertNotEquals(point.hashCode(), new GeodeticPoint(1, FastMath.nextUp(2), 3).hashCode());
109     }
110 
111     /**
112      * check {@link GeodeticPoint#toString()}.
113      */
114     @Test
115     void testToString() {
116         // setup
117         GeodeticPoint point = new GeodeticPoint(FastMath.toRadians(30),
118                 FastMath.toRadians(60), 90);
119 
120         // action
121         String actual = point.toString();
122 
123         // verify
124         Assertions.assertEquals("{lat: 30 deg, lon: 60 deg, alt: 90}", actual);
125     }
126 }