1 /* Contributed in the public domain.
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.propagation.events;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.orekit.propagation.FieldSpacecraftState;
21 import org.orekit.propagation.events.handlers.FieldContinueOnEvent;
22 import org.orekit.propagation.events.handlers.FieldEventHandler;
23 import org.orekit.time.FieldAbsoluteDate;
24
25 /**
26 * An event detector that negates the sign on another event detector's {@link
27 * FieldEventDetector#g(FieldSpacecraftState) g} function.
28 *
29 * @since 12.0
30 * @param <T> type of the field element
31 * @author Evan Ward
32 * @author Luc Maisonobe
33 */
34 public class FieldNegateDetector<T extends CalculusFieldElement<T>> extends FieldAbstractDetector<FieldNegateDetector<T>, T>
35 implements FieldDetectorModifier<T> {
36
37 /** the delegate event detector. */
38 private final FieldEventDetector<T> original;
39
40 /**
41 * Create a new event detector that negates an existing event detector.
42 *
43 * <p> This detector will be initialized with the same {@link
44 * FieldEventDetector#getMaxCheckInterval()}, {@link FieldEventDetector#getThreshold()}, and
45 * {@link FieldEventDetector#getMaxIterationCount()} as {@code original}. Initially this
46 * detector will use the {@link FieldContinueOnEvent} event handler.
47 *
48 * @param original detector.
49 */
50 public FieldNegateDetector(final FieldEventDetector<T> original) {
51 this(original.getDetectionSettings(), new FieldContinueOnEvent<>(), original);
52 }
53
54 /**
55 * Protected constructor.
56 *
57 * @param detectionSettings event detection settings.
58 * @param newHandler event handler.
59 * @param original event detector.
60 * @since 13.0
61 */
62 protected FieldNegateDetector(final FieldEventDetectionSettings<T> detectionSettings,
63 final FieldEventHandler<T> newHandler,
64 final FieldEventDetector<T> original) {
65 super(detectionSettings, newHandler);
66 this.original = original;
67 }
68
69 /**
70 * Get the delegate event detector.
71 * @return the delegate event detector
72 */
73 public FieldEventDetector<T> getOriginal() {
74 return original;
75 }
76
77 @Override
78 public FieldEventDetector<T> getDetector() {
79 return getOriginal();
80 }
81
82 @Override
83 public void init(final FieldSpacecraftState<T> s0, final FieldAbsoluteDate<T> t) {
84 super.init(s0, t);
85 getDetector().init(s0, t);
86 }
87
88 @Override
89 public T g(final FieldSpacecraftState<T> s) {
90 return original.g(s).negate();
91 }
92
93 @Override
94 protected FieldNegateDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
95 final FieldEventHandler<T> newHandler) {
96 return new FieldNegateDetector<>(detectionSettings, newHandler, original);
97 }
98
99 }