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
18 package org.orekit.frames;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.hipparchus.Field;
24 import org.hipparchus.CalculusFieldElement;
25 import org.orekit.time.AbsoluteDate;
26 import org.orekit.time.FieldAbsoluteDate;
27 import org.orekit.utils.GenericTimeStampedCache;
28 import org.orekit.utils.TimeStampedGenerator;
29
30 /** Generator to use field transforms in {@link GenericTimeStampedCache}.
31 * @see GenericTimeStampedCache
32 * @since 9.0
33 * @author Luc Maisonobe
34 * @param <T> type of the field elements
35 */
36 public class FieldTransformGenerator<T extends CalculusFieldElement<T>> implements TimeStampedGenerator<FieldTransform<T>> {
37
38 /** Field to which the elements belong. */
39 private final Field<T> field;
40
41 /** Number of neighbors. */
42 private int neighborsSize;
43
44 /** Underlying provider. */
45 private final TransformProvider provider;
46
47 /** Step size. */
48 private final double step;
49
50 /** simple constructor.
51 * @param field field to which the elements belong
52 * @param neighborsSize number of neighbors
53 * @param provider underlying provider
54 * @param step step size
55 */
56 public FieldTransformGenerator(final Field<T> field,
57 final int neighborsSize,
58 final TransformProvider provider,
59 final double step) {
60 this.field = field;
61 this.neighborsSize = neighborsSize;
62 this.provider = provider;
63 this.step = step;
64 }
65
66 /** {@inheritDoc} */
67 public List<FieldTransform<T>> generate(final AbsoluteDate existingDate, final AbsoluteDate date) {
68
69 final FieldAbsoluteDate<T> fieldDate = new FieldAbsoluteDate<>(field, date);
70 final List<FieldTransform<T>> generated = new ArrayList<>();
71
72 if (existingDate == null) {
73
74 // no prior existing transforms, just generate a first set
75 for (int i = 0; i < neighborsSize; ++i) {
76 generated.add(provider.getTransform(fieldDate.shiftedBy(i * step)));
77 }
78
79 } else {
80
81 // some transforms have already been generated
82 // add the missing ones up to specified date
83 FieldAbsoluteDate<T> t = new FieldAbsoluteDate<>(field, existingDate);
84 if (date.compareTo(t.toAbsoluteDate()) > 0) {
85 // forward generation
86 do {
87 t = t.shiftedBy(step);
88 generated.add(generated.size(), provider.getTransform(t));
89 } while (t.compareTo(fieldDate) <= 0);
90 } else {
91 // backward generation
92 do {
93 t = t.shiftedBy(-step);
94 generated.add(0, provider.getTransform(t));
95 } while (t.compareTo(fieldDate) >= 0);
96 }
97
98 }
99
100 // return the generated transforms
101 return generated;
102
103 }
104
105 }