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
18 package org.orekit.propagation.events;
19
20 import org.hipparchus.util.FastMath;
21 import org.hipparchus.util.Precision;
22
23
24 /** Transformer for {@link EventHandler#g(double, double[]) g functions}.
25 * <p>This class is heavily based on the class with the same name from the
26 * Hipparchus library. The changes performed consist in replacing
27 * raw types (double and double arrays) with space dynamics types
28 * ({@link AbsoluteDate}, {@link SpacecraftState}).</p>
29 * @see EventSlopeFilter
30 * @see FilterType
31 * @since 6.0
32 */
33 enum Transformer {
34
35 /** Transformer computing transformed = 0.
36 * <p>
37 * This transformer is used when we initialize the filter, until we get at
38 * least one non-zero value to select the proper transformer.
39 * </p>
40 */
41 UNINITIALIZED {
42 /** {@inheritDoc} */
43 protected double transformed(final double g) {
44 return 0;
45 }
46 },
47
48 /** Transformer computing transformed = g.
49 * <p>
50 * When this transformer is applied, the roots of the original function
51 * are preserved, with the same {@code increasing/decreasing} status.
52 * </p>
53 */
54 PLUS {
55 /** {@inheritDoc} */
56 protected double transformed(final double g) {
57 return g;
58 }
59 },
60
61 /** Transformer computing transformed = -g.
62 * <p>
63 * When this transformer is applied, the roots of the original function
64 * are preserved, with reversed {@code increasing/decreasing} status.
65 * </p>
66 */
67 MINUS {
68 /** {@inheritDoc} */
69 protected double transformed(final double g) {
70 return -g;
71 }
72 },
73
74 /** Transformer computing transformed = min(-{@link Precision#SAFE_MIN}, -g, +g).
75 * <p>
76 * When this transformer is applied, the transformed function is
77 * guaranteed to be always strictly negative (i.e. there are no roots).
78 * </p>
79 */
80 MIN {
81 /** {@inheritDoc} */
82 protected double transformed(final double g) {
83 return FastMath.min(-Precision.SAFE_MIN, FastMath.min(-g, +g));
84 }
85 },
86
87 /** Transformer computing transformed = max(+{@link Precision#SAFE_MIN}, -g, +g).
88 * <p>
89 * When this transformer is applied, the transformed function is
90 * guaranteed to be always strictly positive (i.e. there are no roots).
91 * </p>
92 */
93 MAX {
94 /** {@inheritDoc} */
95 protected double transformed(final double g) {
96 return FastMath.max(+Precision.SAFE_MIN, FastMath.max(-g, +g));
97 }
98 };
99
100 /** Transform value of function g.
101 * @param g raw value of function g
102 * @return transformed value of function g
103 */
104 protected abstract double transformed(double g);
105
106 }