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.attitudes;
18  
19  import org.hipparchus.geometry.euclidean.threed.FieldRotation;
20  import org.hipparchus.geometry.euclidean.threed.Rotation;
21  import org.hipparchus.util.Binary64;
22  import org.hipparchus.util.Binary64Field;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.TestUtils;
25  import org.orekit.frames.FramesFactory;
26  import org.orekit.orbits.FieldCartesianOrbit;
27  import org.orekit.orbits.FieldOrbit;
28  import org.orekit.orbits.Orbit;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.time.TimeInterval;
31  
32  import static org.junit.jupiter.api.Assertions.assertEquals;
33  import static org.mockito.Mockito.mock;
34  
35  class BoundedAttitudeProviderTest {
36  
37      @Test
38      void testOfGetters() {
39          // GIVEN
40          final AbsoluteDate minDate = AbsoluteDate.ARBITRARY_EPOCH;
41          final AbsoluteDate maxDate = minDate.shiftedBy(10.);
42          final TimeInterval timeInterval = TimeInterval.of(minDate, maxDate);
43          final AttitudeProvider provider = mock();
44          // WHEN
45          final BoundedAttitudeProvider boundedAttitudeProvider = BoundedAttitudeProvider.of(provider, timeInterval);
46          // THEN
47          assertEquals(minDate, boundedAttitudeProvider.getMinDate());
48          assertEquals(maxDate, boundedAttitudeProvider.getMaxDate());
49      }
50  
51      @Test
52      void testOfAttitude() {
53          // GIVEN
54          final AbsoluteDate minDate = AbsoluteDate.ARBITRARY_EPOCH;
55          final AbsoluteDate maxDate = minDate.shiftedBy(10.);
56          final TimeInterval timeInterval = TimeInterval.of(minDate, maxDate);
57          final FrameAlignedProvider provider = new FrameAlignedProvider(FramesFactory.getEME2000());
58          final Orbit orbit = TestUtils.getDefaultOrbit(minDate);
59          // WHEN
60          final BoundedAttitudeProvider boundedAttitudeProvider = BoundedAttitudeProvider.of(provider, timeInterval);
61          // THEN
62          final Attitude actualAttitude = boundedAttitudeProvider.getAttitude(orbit, orbit.getDate(), orbit.getFrame());
63          final Attitude expectedAttitude = provider.getAttitude(orbit, orbit.getDate(), orbit.getFrame());
64          assertEquals(0., Rotation.distance(actualAttitude.getRotation(), expectedAttitude.getRotation()), 1e-6);
65          assertEquals(actualAttitude.getSpin(), expectedAttitude.getSpin());
66          assertEquals(actualAttitude.getRotationAcceleration(), expectedAttitude.getRotationAcceleration());
67          assertEquals(actualAttitude.getDate(), expectedAttitude.getDate());
68          assertEquals(actualAttitude.getReferenceFrame(), expectedAttitude.getReferenceFrame());
69          final Rotation actualRotation = boundedAttitudeProvider.getAttitudeRotation(orbit, orbit.getDate(), orbit.getFrame());
70          final Rotation expectedRotation = provider.getAttitudeRotation(orbit, orbit.getDate(), orbit.getFrame());
71          assertEquals(0., Rotation.distance(actualRotation, expectedRotation), 1e-6);
72      }
73  
74      @Test
75      void testOfFieldAttitude() {
76          // GIVEN
77          final AbsoluteDate minDate = AbsoluteDate.ARBITRARY_EPOCH;
78          final AbsoluteDate maxDate = minDate.shiftedBy(10.);
79          final TimeInterval timeInterval = TimeInterval.of(minDate, maxDate);
80          final FrameAlignedProvider provider = new FrameAlignedProvider(FramesFactory.getEME2000());
81          final Orbit orbit = TestUtils.getDefaultOrbit(maxDate);
82          final FieldOrbit<Binary64> fieldOrbit = new FieldCartesianOrbit<>(Binary64Field.getInstance(), orbit);
83          // WHEN
84          final BoundedAttitudeProvider boundedAttitudeProvider = BoundedAttitudeProvider.of(provider, timeInterval);
85          // THEN
86          final FieldAttitude<Binary64> actualAttitude = boundedAttitudeProvider.getAttitude(fieldOrbit, fieldOrbit.getDate(), orbit.getFrame());
87          final FieldAttitude<Binary64> expectedAttitude = provider.getAttitude(fieldOrbit, fieldOrbit.getDate(), orbit.getFrame());
88          assertEquals(0., Rotation.distance(actualAttitude.getRotation().toRotation(),
89                  expectedAttitude.getRotation().toRotation()), 1e-6);
90          assertEquals(actualAttitude.getSpin(), expectedAttitude.getSpin());
91          assertEquals(actualAttitude.getRotationAcceleration(), expectedAttitude.getRotationAcceleration());
92          assertEquals(actualAttitude.getDate(), expectedAttitude.getDate());
93          assertEquals(actualAttitude.getReferenceFrame(), expectedAttitude.getReferenceFrame());
94          final FieldRotation<Binary64> actualRotation = boundedAttitudeProvider.getAttitudeRotation(fieldOrbit, fieldOrbit.getDate(), orbit.getFrame());
95          final FieldRotation<Binary64> expectedRotation = provider.getAttitudeRotation(fieldOrbit, fieldOrbit.getDate(), orbit.getFrame());
96          assertEquals(0., Rotation.distance(actualRotation.toRotation(), expectedRotation.toRotation()), 1e-6);
97      }
98  }