FieldTransformGenerator.java

  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.frames;

  18. import java.util.ArrayList;
  19. import java.util.List;

  20. import org.hipparchus.Field;
  21. import org.hipparchus.CalculusFieldElement;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.time.FieldAbsoluteDate;
  24. import org.orekit.utils.GenericTimeStampedCache;
  25. import org.orekit.utils.TimeStampedGenerator;

  26. /** Generator to use field transforms in {@link GenericTimeStampedCache}.
  27.  * @see GenericTimeStampedCache
  28.  * @since 9.0
  29.  * @author Luc Maisonobe
  30.  * @param <T> type of the field elements
  31.  */
  32. public class FieldTransformGenerator<T extends CalculusFieldElement<T>> implements TimeStampedGenerator<FieldTransform<T>> {

  33.     /** Field to which the elements belong. */
  34.     private final Field<T> field;

  35.     /** Number of neighbors. */
  36.     private int neighborsSize;

  37.     /** Underlying provider. */
  38.     private final TransformProvider provider;

  39.     /** Step size. */
  40.     private final double step;

  41.     /** simple constructor.
  42.      * @param field field to which the elements belong
  43.      * @param neighborsSize number of neighbors
  44.      * @param provider underlying provider
  45.      * @param step step size
  46.      */
  47.     public FieldTransformGenerator(final Field<T> field,
  48.                                    final int neighborsSize,
  49.                                    final TransformProvider provider,
  50.                                    final double step) {
  51.         this.field         = field;
  52.         this.neighborsSize = neighborsSize;
  53.         this.provider      = provider;
  54.         this.step          = step;
  55.     }

  56.     /** {@inheritDoc} */
  57.     public List<FieldTransform<T>> generate(final AbsoluteDate existingDate, final AbsoluteDate date) {

  58.         final FieldAbsoluteDate<T> fieldDate = new FieldAbsoluteDate<>(field, date);
  59.         final List<FieldTransform<T>> generated = new ArrayList<>();

  60.         if (existingDate == null) {

  61.             // no prior existing transforms, just generate a first set
  62.             for (int i = 0; i < neighborsSize; ++i) {
  63.                 generated.add(provider.getTransform(fieldDate.shiftedBy(i * step)));
  64.             }

  65.         } else {

  66.             // some transforms have already been generated
  67.             // add the missing ones up to specified date
  68.             FieldAbsoluteDate<T> t = new FieldAbsoluteDate<>(field, existingDate);
  69.             if (date.compareTo(t.toAbsoluteDate()) > 0) {
  70.                 // forward generation
  71.                 do {
  72.                     t = t.shiftedBy(step);
  73.                     generated.add(generated.size(), provider.getTransform(t));
  74.                 } while (t.compareTo(fieldDate) <= 0);
  75.             } else {
  76.                 // backward generation
  77.                 do {
  78.                     t = t.shiftedBy(-step);
  79.                     generated.add(0, provider.getTransform(t));
  80.                 } while (t.compareTo(fieldDate) >= 0);
  81.             }

  82.         }

  83.         // return the generated transforms
  84.         return generated;

  85.     }

  86. }