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> {

  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.getMaxCheckInterval(),
  43.                 original.getThreshold(),
  44.                 original.getMaxIterationCount(),
  45.                 new ContinueOnEvent(),
  46.                 original);
  47.     }

  48.     /**
  49.      * Private constructor.
  50.      *
  51.      * @param newMaxCheck  max check interval.
  52.      * @param newThreshold convergence threshold in seconds.
  53.      * @param newMaxIter   max iterations.
  54.      * @param newHandler   event handler.
  55.      * @param original     event detector.
  56.      */
  57.     protected NegateDetector(final AdaptableInterval newMaxCheck,
  58.                              final double newThreshold,
  59.                              final int newMaxIter,
  60.                              final EventHandler newHandler,
  61.                              final EventDetector original) {
  62.         super(newMaxCheck, newThreshold, newMaxIter, newHandler);
  63.         this.original = original;
  64.     }

  65.     /**
  66.      * Get the delegate event detector.
  67.      * @return the delegate event detector
  68.      * @since 10.2
  69.      */
  70.     public EventDetector getOriginal() {
  71.         return original;
  72.     }

  73.     @Override
  74.     public void init(final SpacecraftState s0,
  75.                      final AbsoluteDate t) {
  76.         super.init(s0, t);
  77.         this.original.init(s0, t);
  78.     }

  79.     @Override
  80.     public double g(final SpacecraftState s) {
  81.         return -this.original.g(s);
  82.     }

  83.     @Override
  84.     protected NegateDetector create(
  85.             final AdaptableInterval newMaxCheck,
  86.             final double newThreshold,
  87.             final int newMaxIter,
  88.             final EventHandler newHandler) {
  89.         return new NegateDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  90.                 this.original);
  91.     }

  92. }