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.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.util.Decimal64;
22  import org.hipparchus.util.FastMath;
23  import org.junit.Assert;
24  import org.junit.Test;
25  
26  /**
27   * Unit tests for {@link FieldGeodeticPoint}.
28   *
29   * @author Evan Ward
30   *
31   */
32  public class FieldGeodeticPointTest {
33  
34      /**
35       * check {@link FieldGeodeticPoint#GeodeticPoint(CalculusFieldElement, CalculusFieldElement, CalculusFieldElement)} angle
36       * normalization.
37       */
38      @Test
39      public void testGeodeticPointAngleNormalization() {
40          // action
41          FieldGeodeticPoint<Decimal64> point =
42                  new FieldGeodeticPoint<Decimal64>(new Decimal64(FastMath.toRadians(135)),
43                                                    new Decimal64(FastMath.toRadians(90 - 360)),
44                                                    new Decimal64(0));
45  
46          // verify
47          Assert.assertEquals(FastMath.toRadians(45), point.getLatitude().getReal(), 1.0e-15);
48          Assert.assertEquals(FastMath.toRadians(-90), point.getLongitude().getReal(), 1.0e-15);
49  
50          Assert.assertEquals(0, Vector3D.distance(point.getEast().toVector3D(),   Vector3D.PLUS_I), 1.0e-15);
51          Assert.assertEquals(0, Vector3D.distance(point.getNorth().toVector3D(),  new Vector3D( 0.50 * FastMath.PI,  0.25 * FastMath.PI)), 1.0e-15);
52          Assert.assertEquals(0, Vector3D.distance(point.getWest().toVector3D(),   Vector3D.MINUS_I), 1.0e-15);
53          Assert.assertEquals(0, Vector3D.distance(point.getSouth().toVector3D(),  new Vector3D(-0.50 * FastMath.PI, -0.25 * FastMath.PI)), 1.0e-15);
54          Assert.assertEquals(0, Vector3D.distance(point.getZenith().toVector3D(), new Vector3D(-0.50 * FastMath.PI,  0.25 * FastMath.PI)), 1.0e-15);
55          Assert.assertEquals(0, Vector3D.distance(point.getNadir().toVector3D(),  new Vector3D( 0.50 * FastMath.PI, -0.25 * FastMath.PI)), 1.0e-15);
56  
57      }
58  
59      /**
60       * check {@link FieldGeodeticPoint#GeodeticPoint(CalculusFieldElement, CalculusFieldElement, CalculusFieldElement)} for
61       * several different angles.
62       */
63      @Test
64      public void testGeodeticPoint() {
65          // setup
66          // the input and expected results
67          final double pi = FastMath.PI;
68          double[][] points = {
69                  // Input lat, Input lon; expected lat, expected lon
70                  // first quadrant
71                  { pi / 6, pi / 6, pi / 6, pi / 6 },
72                  // second quadrant
73                  { 4 * pi / 6, 4 * pi / 6, pi / 3, -pi / 3 },
74                  // third quadrant
75                  { 7 * pi / 6, 7 * pi / 6, -pi / 6, pi / 6 },
76                  // fourth quadrant
77                  { -pi / 6, -pi / 6, -pi / 6, -pi / 6 },
78                  { -4 * pi / 6, -4 * pi / 6, -pi / 3, pi / 3 },
79                  { -pi / 6, -4 * pi / 3, -pi / 6, 2 * pi / 3 } };
80  
81          for (double[] point : points) {
82              // action
83              FieldGeodeticPoint<Decimal64> gp =
84                      new FieldGeodeticPoint<Decimal64>(new Decimal64(point[0]),
85                                                        new Decimal64(point[1]),
86                                                        Decimal64.ZERO);
87              Assert.assertEquals(0, gp.getEast().crossProduct(gp.getNorth()).distance(gp.getZenith()).getReal(), 1.0e-15);
88              Assert.assertEquals(0, gp.getNorth().crossProduct(gp.getWest()).distance(gp.getZenith()).getReal(), 1.0e-15);
89              Assert.assertEquals(0, gp.getSouth().crossProduct(gp.getWest()).distance(gp.getNadir()).getReal(), 1.0e-15);
90              Assert.assertEquals(0, gp.getEast().crossProduct(gp.getSouth()).distance(gp.getNadir()).getReal(), 1.0e-15);
91              Assert.assertEquals(0, gp.getZenith().crossProduct(gp.getSouth()).distance(gp.getEast()).getReal(), 1.0e-15);
92              Assert.assertEquals(0, gp.getNadir().crossProduct(gp.getWest()).distance(gp.getNorth()).getReal(), 1.0e-15);
93  
94              // verify to within 5 ulps
95              Assert.assertEquals(point[2], gp.getLatitude().getReal(), 5 * FastMath.ulp(point[2]));
96              Assert.assertEquals(point[3], gp.getLongitude().getReal(), 5 * FastMath.ulp(point[3]));
97          }
98      }
99  
100     /**
101      * check {@link FieldGeodeticPoint#equals(Object)}.
102      */
103     @Test
104     public void testEquals() {
105         // setup
106         FieldGeodeticPoint<Decimal64> point =
107                 new FieldGeodeticPoint<Decimal64>(new Decimal64(1),
108                                                   new Decimal64(2),
109                                                   new Decimal64(3));
110 
111         // actions + verify
112         Assert.assertEquals(point, new FieldGeodeticPoint<Decimal64>(new Decimal64(1),
113                                                                      new Decimal64(2),
114                                                                      new Decimal64(3)));
115         Assert.assertFalse(point.equals(new FieldGeodeticPoint<Decimal64>(new Decimal64(0),
116                                                                           new Decimal64(2),
117                                                                           new Decimal64(3))));
118         Assert.assertFalse(point.equals(new FieldGeodeticPoint<Decimal64>(new Decimal64(1),
119                                                                           new Decimal64(0),
120                                                                           new Decimal64(3))));
121         Assert.assertFalse(point.equals(new FieldGeodeticPoint<Decimal64>(new Decimal64(1),
122                                                                           new Decimal64(2),
123                                                                           new Decimal64(0))));
124         Assert.assertFalse(point.equals(new Object()));
125         Assert.assertEquals(point.hashCode(),
126                             new FieldGeodeticPoint<Decimal64>(new Decimal64(1),
127                                                               new Decimal64(2),
128                                                               new Decimal64(3)).hashCode());
129         Assert.assertNotEquals(point.hashCode(),
130                                new FieldGeodeticPoint<Decimal64>(new Decimal64(1),
131                                                                  new Decimal64(FastMath.nextUp(2)),
132                                                                  new Decimal64(3)).hashCode());
133     }
134 
135     /**
136      * check {@link FieldGeodeticPoint#toString()}.
137      */
138     @Test
139     public void testToString() {
140         // setup
141         FieldGeodeticPoint<Decimal64> point =
142                 new FieldGeodeticPoint<Decimal64>(new Decimal64(FastMath.toRadians(30)),
143                                                   new Decimal64(FastMath.toRadians(60)),
144                                                   new Decimal64(90));
145 
146         // action
147         String actual = point.toString();
148 
149         // verify
150         Assert.assertEquals("{lat: 30 deg, lon: 60 deg, alt: 90}", actual);
151     }
152 
153 }