1 /* Copyright 2002-2025 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.time;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.orekit.errors.OrekitIllegalArgumentException;
21 import org.orekit.errors.OrekitMessages;
22
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Optional;
26 import java.util.stream.Collectors;
27 import java.util.stream.Stream;
28
29 /**
30 * This interface represents objects that can interpolate a time stamped value with respect to time.
31 *
32 * @param <T> type of the interpolated instance
33 * @param <KK> type of the field element
34 *
35 * @author Vincent Cucchietti
36 * @see FieldAbsoluteDate
37 * @see FieldTimeStamped
38 * @see CalculusFieldElement
39 */
40 public interface FieldTimeInterpolator<T extends FieldTimeStamped<KK>, KK extends CalculusFieldElement<KK>> {
41
42 /**
43 * Get an interpolated instance.
44 *
45 * @param interpolationDate interpolation date
46 * @param sample time stamped sample
47 *
48 * @return a new instance, interpolated at specified date
49 *
50 * @see TimeStamped
51 * @see AbsoluteDate
52 */
53 default T interpolate(AbsoluteDate interpolationDate, Stream<T> sample) {
54 return interpolate(interpolationDate, sample.collect(Collectors.toList()));
55 }
56
57 /**
58 * Get an interpolated instance.
59 *
60 * @param interpolationDate interpolation date
61 * @param sample time stamped sample
62 *
63 * @return a new instance, interpolated at specified date
64 */
65 default T interpolate(AbsoluteDate interpolationDate, Collection<T> sample) {
66 final Optional<T> optionalElement = sample.stream().findAny();
67 if (optionalElement.isPresent()) {
68 final T element = optionalElement.get();
69 return interpolate(new FieldAbsoluteDate<>(element.getDate().getField(), interpolationDate), sample);
70 }
71 throw new OrekitIllegalArgumentException(OrekitMessages.NOT_ENOUGH_DATA, 0);
72 }
73
74 /**
75 * Get an interpolated instance.
76 *
77 * @param interpolationDate interpolation date
78 * @param sample time stamped sample
79 *
80 * @return a new instance, interpolated at specified date
81 *
82 * @see TimeStamped
83 * @see AbsoluteDate
84 */
85 T interpolate(FieldAbsoluteDate<KK> interpolationDate, Stream<T> sample);
86
87 /**
88 * Get an interpolated instance.
89 *
90 * @param interpolationDate interpolation date
91 * @param sample time stamped sample
92 *
93 * @return a new instance, interpolated at specified date
94 */
95 T interpolate(FieldAbsoluteDate<KK> interpolationDate, Collection<T> sample);
96
97 /**
98 * Get all lowest level interpolators implemented by this instance, otherwise return a list with this instance only.
99 * <p>
100 * An example would be the spacecraft state interpolator which can use different interpolators for each of its attributes
101 * (orbit, absolute position-velocity-acceleration coordinates, mass...). In this case, it would return the list of all
102 * of these interpolators (or possibly all of their sub-interpolators if they were to use multiple interpolators
103 * themselves).
104 *
105 * @return list of interpolators
106 */
107 List<FieldTimeInterpolator<? extends FieldTimeStamped<KK>, KK>> getSubInterpolators();
108
109 /**
110 * Get the number of interpolation points. In the specific case where this interpolator contains multiple
111 * sub-interpolators, this method will return the maximum number of interpolation points required among all
112 * sub-interpolators.
113 *
114 * @return the number of interpolation points
115 *
116 * @since 12.0.1
117 */
118 int getNbInterpolationPoints();
119
120 /** Get the extrapolation threshold.
121 * @return get the extrapolation threshold.
122 */
123 double getExtrapolationThreshold();
124 }