NegateDetector.java

  1. /* Contributed in the public domain.
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  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.  * An event detector that negates the sign on another event detector's {@link
  25.  * EventDetector#g(SpacecraftState) g} function.
  26.  *
  27.  * @author Evan Ward
  28.  */
  29. public class NegateDetector extends AbstractDetector<NegateDetector> {

  30.     /** Serializable UID. */
  31.     private static final long serialVersionUID = 20170410L;

  32.     /** the delegate event detector. */
  33.     private final EventDetector original;

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

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

  68.     @Override
  69.     public void init(final SpacecraftState s0,
  70.                      final AbsoluteDate t) throws OrekitException {
  71.         super.init(s0, t);
  72.         this.original.init(s0, t);
  73.     }

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

  78.     @Override
  79.     protected NegateDetector create(
  80.             final double newMaxCheck,
  81.             final double newThreshold,
  82.             final int newMaxIter,
  83.             final EventHandler<? super NegateDetector> newHandler) {
  84.         return new NegateDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  85.                 this.original);
  86.     }

  87. }