NegateDetector.java

  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. import org.orekit.propagation.SpacecraftState;
  19. import org.orekit.propagation.events.handlers.ContinueOnEvent;
  20. import org.orekit.propagation.events.handlers.EventHandler;
  21. import org.orekit.time.AbsoluteDate;

  22. /**
  23.  * An event detector that negates the sign on another event detector's {@link
  24.  * EventDetector#g(SpacecraftState) g} function.
  25.  *
  26.  * @author Evan Ward
  27.  */
  28. public class NegateDetector extends AbstractDetector<NegateDetector> implements DetectorModifier {

  29.     /** the delegate event detector. */
  30.     private final EventDetector original;

  31.     /**
  32.      * Create a new event detector that negates an existing event detector.
  33.      *
  34.      * <p> This detector will be initialized with the same {@link
  35.      * EventDetector#getMaxCheckInterval()}, {@link EventDetector#getThreshold()}, and
  36.      * {@link EventDetector#getMaxIterationCount()} as {@code original}. Initially this
  37.      * detector will use the {@link ContinueOnEvent} event handler.
  38.      *
  39.      * @param original detector.
  40.      */
  41.     public NegateDetector(final EventDetector original) {
  42.         this(original.getDetectionSettings(), new ContinueOnEvent(), original);
  43.     }

  44.     /**
  45.      * Private constructor.
  46.      *
  47.      * @param eventDetectionSettings event detection settings.
  48.      * @param newHandler   event handler.
  49.      * @param original     event detector.
  50.      * @since 13.0
  51.      */
  52.     protected NegateDetector(final EventDetectionSettings eventDetectionSettings,
  53.                              final EventHandler newHandler,
  54.                              final EventDetector original) {
  55.         super(eventDetectionSettings, newHandler);
  56.         this.original = original;
  57.     }

  58.     /**
  59.      * Get the delegate event detector.
  60.      * @return the delegate event detector
  61.      * @since 10.2
  62.      */
  63.     public EventDetector getOriginal() {
  64.         return original;
  65.     }

  66.     @Override
  67.     public EventDetector getDetector() {
  68.         return getOriginal();
  69.     }

  70.     @Override
  71.     public void init(final SpacecraftState s0, final AbsoluteDate t) {
  72.         super.init(s0, t);
  73.         getDetector().init(s0, t);
  74.     }

  75.     @Override
  76.     public double g(final SpacecraftState s) {
  77.         return -this.original.g(s);
  78.     }

  79.     @Override
  80.     protected NegateDetector create(
  81.             final EventDetectionSettings detectionSettings,
  82.             final EventHandler newHandler) {
  83.         return new NegateDetector(detectionSettings, newHandler, this.original);
  84.     }

  85. }