1   /* Copyright 2002-2026 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.orbits;
18  
19  import org.orekit.errors.OrekitIllegalArgumentException;
20  import org.orekit.errors.OrekitMessages;
21  import org.orekit.frames.Frame;
22  import org.orekit.time.AbsoluteDate;
23  import org.orekit.time.AbstractTimeInterpolator;
24  
25  import java.util.ArrayList;
26  import java.util.Collection;
27  import java.util.List;
28  
29  /**
30   * Abstract class for orbit interpolator.
31   *
32   * @author Vincent Cucchietti
33   */
34  public abstract class AbstractOrbitInterpolator extends AbstractTimeInterpolator<Orbit> {
35  
36      /** Output inertial frame. */
37      private final Frame outputInertialFrame;
38  
39      /**
40       * Constructor.
41       *
42       * @param interpolationPoints number of interpolation points
43       * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
44       * @param outputInertialFrame output inertial frame
45       */
46      protected AbstractOrbitInterpolator(final int interpolationPoints, final double extrapolationThreshold,
47                                          final Frame outputInertialFrame) {
48          super(interpolationPoints, extrapolationThreshold);
49          checkFrameIsInertial(outputInertialFrame);
50          this.outputInertialFrame = outputInertialFrame;
51      }
52  
53      /**
54       * Check orbits consistency by comparing their frame and gravitational parameters ยต.
55       *
56       * @param sample orbits sample
57       */
58      public static void checkOrbitsConsistency(
59              final Collection<? extends Orbit> sample) {
60  
61          // Convert sample to list
62          final List<Orbit> sampleList = new ArrayList<>(sample);
63  
64          // Check consistency
65          for (int i = 0; i < sampleList.size() - 1; i++) {
66              final Orbit currentOrbit = sampleList.get(i);
67              final Orbit nextOrbit    = sampleList.get(i + 1);
68  
69              if (currentOrbit.getFrame() != nextOrbit.getFrame()) {
70                  throw new OrekitIllegalArgumentException(OrekitMessages.FRAMES_MISMATCH,
71                                                           currentOrbit.getFrame(),
72                                                           nextOrbit.getFrame());
73              }
74  
75              if (currentOrbit.getMu() != nextOrbit.getMu()) {
76                  throw new OrekitIllegalArgumentException(OrekitMessages.ORBITS_MUS_MISMATCH, currentOrbit.getMu(),
77                                                           nextOrbit.getMu());
78              }
79          }
80      }
81  
82      /** {@inheritDoc}. */
83      @Override
84      public Orbit interpolate(final AbsoluteDate interpolationDate,
85                               final Collection<? extends Orbit> sample) {
86  
87          // Check orbits consistency
88          checkOrbitsConsistency(sample);
89  
90          return super.interpolate(interpolationDate, sample);
91      }
92  
93      /** Get output inertial frame.
94       * @return output inertial frame
95       */
96      public Frame getOutputInertialFrame() {
97          return outputInertialFrame;
98      }
99  
100     /**
101      * Check if given frame is pseudo inertial and throw an error otherwise.
102      *
103      * @param frame frame to check
104      *
105      * @throws OrekitIllegalArgumentException if given frame is not pseudo inertial
106      */
107     private void checkFrameIsInertial(final Frame frame) {
108         if (!frame.isPseudoInertial()) {
109             throw new OrekitIllegalArgumentException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME, frame.getName());
110         }
111     }
112 }