1   /* Copyright 2022-2025 Romain Serra
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.orbits;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  import org.junit.jupiter.params.ParameterizedTest;
22  import org.junit.jupiter.params.provider.EnumSource;
23  import org.junit.jupiter.params.provider.ValueSource;
24  import org.orekit.errors.OrekitException;
25  import org.orekit.errors.OrekitMessages;
26  
27  class CircularLatitudeArgumentUtilityTest {
28  
29      private static final double EX = 0.1;
30      private static final double EY = 0.66;
31      private static final double TOLERANCE = 1e-10;
32  
33      @Test
34      void testMeanToTrueAndBack() {
35          // GIVEN
36          final double expectedLatitudeArgument = 3.;
37          // WHEN
38          final double intermediateLatitudeArgument = CircularLatitudeArgumentUtility.meanToTrue(EX, EY,
39                  expectedLatitudeArgument);
40          final double actualLatitudeArgument = CircularLatitudeArgumentUtility.trueToMean(EX, EY,
41                  intermediateLatitudeArgument);
42          // THEN
43          Assertions.assertEquals(expectedLatitudeArgument, actualLatitudeArgument, TOLERANCE);
44      }
45  
46      @Test
47      void testEccentricToTrueAndBack() {
48          // GIVEN
49          final double expectedLatitudeArgument = 3.;
50          // WHEN
51          final double intermediateLatitudeArgument = CircularLatitudeArgumentUtility.eccentricToTrue(EX, EY,
52                  expectedLatitudeArgument);
53          final double actualLatitudeArgument = CircularLatitudeArgumentUtility.trueToEccentric(EX, EY,
54                  intermediateLatitudeArgument);
55          // THEN
56          Assertions.assertEquals(expectedLatitudeArgument, actualLatitudeArgument, TOLERANCE);
57      }
58  
59      @Test
60      void testEccentricToMeanAndBack() {
61          // GIVEN
62          final double expectedLatitudeArgument = 3.;
63          // WHEN
64          final double intermediateLatitudeArgument = CircularLatitudeArgumentUtility.eccentricToMean(EX, EY,
65                  expectedLatitudeArgument);
66          final double actualLatitudeArgument = CircularLatitudeArgumentUtility.meanToEccentric(EX, EY,
67                  intermediateLatitudeArgument);
68          // THEN
69          Assertions.assertEquals(expectedLatitudeArgument, actualLatitudeArgument, TOLERANCE);
70      }
71  
72      @ParameterizedTest
73      @EnumSource(PositionAngleType.class)
74      void testConvertAlpha(final PositionAngleType inputType) {
75          // GIVEN
76          final double expectedLatitudeArgument = 3.;
77          final PositionAngleType intermediateType = PositionAngleType.MEAN;
78          // WHEN
79          final double intermediateLatitudeArgument = CircularLatitudeArgumentUtility.convertAlpha(inputType,
80                  expectedLatitudeArgument, EX, EY, intermediateType);
81          final double actualLatitudeArgument = CircularLatitudeArgumentUtility.convertAlpha(intermediateType,
82                  intermediateLatitudeArgument, EX, EY, inputType);
83          // THEN
84          Assertions.assertEquals(expectedLatitudeArgument, actualLatitudeArgument, TOLERANCE);
85      }
86  
87      @Test
88      void testMeanToEccentricException() {
89          // GIVEN
90          final double nanLatitudeArgument = Double.NaN;
91          // WHEN & THEN
92          Assertions.assertThrows(OrekitException.class, () -> CircularLatitudeArgumentUtility.meanToEccentric(EX, EY,
93                  nanLatitudeArgument), OrekitMessages.UNABLE_TO_COMPUTE_ECCENTRIC_LATITUDE_ARGUMENT.toString());
94      }
95  
96      @ParameterizedTest
97      @ValueSource(doubles = {1e3, 5e3, 1e4, 1e5, 5e5})
98      void testIssue1525(final double alphaM) {
99          final double ex = 0.44940492906694396;
100         final double ey = 0.56419162961687;
101         Assertions.assertDoesNotThrow(() -> CircularLatitudeArgumentUtility.meanToEccentric(ex, ey, alphaM));
102     }
103 
104 }