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