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.propagation.events;
18  
19  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
20  import org.hipparchus.util.Binary64;
21  import org.hipparchus.util.Binary64Field;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.TestUtils;
24  import org.orekit.frames.Frame;
25  import org.orekit.propagation.FieldSpacecraftState;
26  import org.orekit.propagation.SpacecraftState;
27  import org.orekit.time.AbsoluteDate;
28  import org.orekit.utils.ExtendedPositionProvider;
29  
30  import static org.junit.jupiter.api.Assertions.*;
31  import static org.mockito.Mockito.mock;
32  import static org.mockito.Mockito.when;
33  
34  class FieldAngularSeparationDetectorTest {
35  
36      @Test
37      void testGetter() {
38          // GIVEN
39          final ExtendedPositionProvider mockedBeacon = mock();
40          final ExtendedPositionProvider mockedObserver = mock();
41          final Binary64 expectedAngle = Binary64.ONE;
42          // WHEN
43          final FieldAngularSeparationDetector<Binary64> detector = new FieldAngularSeparationDetector<>(mockedBeacon,
44                  mockedObserver, expectedAngle);
45          // THEN
46          assertEquals(expectedAngle, detector.getProximityAngle());
47          assertEquals(mockedBeacon, detector.getBeacon());
48          assertEquals(mockedObserver, detector.getObserver());
49      }
50  
51      @Test
52      void testG() {
53          // GIVEN
54          final Binary64Field field = Binary64Field.getInstance();
55          final SpacecraftState state = new SpacecraftState(TestUtils.getDefaultOrbit(AbsoluteDate.ARBITRARY_EPOCH));
56          final FieldSpacecraftState<Binary64> fieldState = new FieldSpacecraftState<>(field, state);
57          final Frame frame = fieldState.getFrame();
58          final ExtendedPositionProvider mockedBeacon = mock();
59          final FieldVector3D<Binary64> beaconPosition = FieldVector3D.getMinusJ(field);
60          final FieldVector3D<Binary64> observerPosition = FieldVector3D.getMinusK(field);
61          when(mockedBeacon.getPosition(fieldState.getDate(), frame)).thenReturn(beaconPosition);
62          when(mockedBeacon.getPosition(state.getDate(), frame)).thenReturn(beaconPosition.toVector3D());
63          final ExtendedPositionProvider mockedObserver = mock();
64          when(mockedObserver.getPosition(fieldState.getDate(), frame)).thenReturn(observerPosition);
65          when(mockedObserver.getPosition(state.getDate(), frame)).thenReturn(observerPosition.toVector3D());
66          final Binary64 angle = Binary64.ONE;
67          // WHEN
68          final FieldAngularSeparationDetector<Binary64> fieldDetector = new FieldAngularSeparationDetector<>(mockedBeacon,
69                  mockedObserver, angle);
70          // THEN
71          final AngularSeparationDetector detector = new AngularSeparationDetector(mockedBeacon, mockedObserver,
72                  angle.getReal());
73          final Binary64 actualG = fieldDetector.g(fieldState);
74          assertEquals(detector.g(state), actualG.getReal());
75      }
76  }