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