1   /* Copyright 2002-2022 CS GROUP
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.utils;
18  
19  
20  import org.hipparchus.Field;
21  import org.hipparchus.CalculusFieldElement;
22  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23  import org.hipparchus.util.Decimal64;
24  import org.hipparchus.util.Decimal64Field;
25  import org.junit.Assert;
26  import org.junit.Test;
27  import org.orekit.frames.Frame;
28  import org.orekit.frames.FramesFactory;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.time.FieldAbsoluteDate;
31  
32  public class ExtendedPVCoordinatesTest {
33  
34      @Test
35      public void testConversion() {
36          final ExtendedPVCoordinatesProvider provider = new ExtendedPVCoordinatesProvider() {
37              
38              @Override
39              public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame) {
40                  return null;
41              }
42              
43              @Override
44              public <T extends CalculusFieldElement<T>> TimeStampedFieldPVCoordinates<T>
45                  getPVCoordinates(final FieldAbsoluteDate<T> date, final Frame frame)
46                      {
47                  return new TimeStampedFieldPVCoordinates<>(date,
48                                                             FieldVector3D.getPlusI(date.getField()),
49                                                             FieldVector3D.getPlusJ(date.getField()),
50                                                             FieldVector3D.getPlusK(date.getField()));
51              }
52          };
53  
54          Field<Decimal64> field = Decimal64Field.getInstance();
55          final FieldPVCoordinatesProvider<Decimal64> converted =
56                          provider.toFieldPVCoordinatesProvider(field);
57          FieldPVCoordinates<Decimal64> pv = converted.getPVCoordinates(FieldAbsoluteDate.getJ2000Epoch(field),
58                                                                        FramesFactory.getGCRF());
59          Assert.assertEquals(0.0, FieldVector3D.distance(pv.getPosition(),FieldVector3D.getPlusI(field)).getReal(), 1.0e-15);
60          Assert.assertEquals(0.0, FieldVector3D.distance(pv.getVelocity(),FieldVector3D.getPlusJ(field)).getReal(), 1.0e-15);
61          Assert.assertEquals(0.0, FieldVector3D.distance(pv.getAcceleration(),FieldVector3D.getPlusK(field)).getReal(), 1.0e-15);
62  
63      }
64  
65  }