Transformer.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF 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.propagation.events;

  18. import org.hipparchus.util.FastMath;
  19. import org.hipparchus.util.Precision;


  20. /** Transformer for {@link EventHandler#g(double, double[]) g functions}.
  21.  * <p>This class is heavily based on the class with the same name from the
  22.  * Hipparchus library. The changes performed consist in replacing
  23.  * raw types (double and double arrays) with space dynamics types
  24.  * ({@link AbsoluteDate}, {@link SpacecraftState}).</p>
  25.  * @see EventSlopeFilter
  26.  * @see FilterType
  27.  * @since 6.0
  28.  */
  29. enum Transformer {

  30.     /** Transformer computing transformed = 0.
  31.      * <p>
  32.      * This transformer is used when we initialize the filter, until we get at
  33.      * least one non-zero value to select the proper transformer.
  34.      * </p>
  35.      */
  36.     UNINITIALIZED {
  37.         /**  {@inheritDoc} */
  38.         protected double transformed(final double g) {
  39.             return 0;
  40.         }
  41.     },

  42.     /** Transformer computing transformed = g.
  43.      * <p>
  44.      * When this transformer is applied, the roots of the original function
  45.      * are preserved, with the same {@code increasing/decreasing} status.
  46.      * </p>
  47.      */
  48.     PLUS {
  49.         /**  {@inheritDoc} */
  50.         protected double transformed(final double g) {
  51.             return g;
  52.         }
  53.     },

  54.     /** Transformer computing transformed = -g.
  55.      * <p>
  56.      * When this transformer is applied, the roots of the original function
  57.      * are preserved, with reversed {@code increasing/decreasing} status.
  58.      * </p>
  59.      */
  60.     MINUS {
  61.         /**  {@inheritDoc} */
  62.         protected double transformed(final double g) {
  63.             return -g;
  64.         }
  65.     },

  66.     /** Transformer computing transformed = min(-{@link Precision#SAFE_MIN}, -g, +g).
  67.      * <p>
  68.      * When this transformer is applied, the transformed function is
  69.      * guaranteed to be always strictly negative (i.e. there are no roots).
  70.      * </p>
  71.      */
  72.     MIN {
  73.         /**  {@inheritDoc} */
  74.         protected double transformed(final double g) {
  75.             return FastMath.min(-Precision.SAFE_MIN, FastMath.min(-g, +g));
  76.         }
  77.     },

  78.     /** Transformer computing transformed = max(+{@link Precision#SAFE_MIN}, -g, +g).
  79.      * <p>
  80.      * When this transformer is applied, the transformed function is
  81.      * guaranteed to be always strictly positive (i.e. there are no roots).
  82.      * </p>
  83.      */
  84.     MAX {
  85.         /**  {@inheritDoc} */
  86.         protected double transformed(final double g) {
  87.             return FastMath.max(+Precision.SAFE_MIN, FastMath.max(-g, +g));
  88.         }
  89.     };

  90.     /** Transform value of function g.
  91.      * @param g raw value of function g
  92.      * @return transformed value of function g
  93.      */
  94.     protected abstract double transformed(double g);

  95. }