FieldNegateDetector.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.hipparchus.CalculusFieldElement;
  19. import org.orekit.propagation.FieldSpacecraftState;
  20. import org.orekit.propagation.events.handlers.FieldContinueOnEvent;
  21. import org.orekit.propagation.events.handlers.FieldEventHandler;
  22. import org.orekit.time.FieldAbsoluteDate;

  23. /**
  24.  * An event detector that negates the sign on another event detector's {@link
  25.  * FieldEventDetector#g(FieldSpacecraftState) g} function.
  26.  *
  27.  * @since 12.0
  28.  * @param <T> type of the field element
  29.  * @author Evan Ward
  30.  * @author Luc Maisonobe
  31.  */
  32. public class FieldNegateDetector<T extends CalculusFieldElement<T>>  extends FieldAbstractDetector<FieldNegateDetector<T>, T>
  33.         implements FieldDetectorModifier<T> {

  34.     /** the delegate event detector. */
  35.     private final FieldEventDetector<T> original;

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

  49.     /**
  50.      * Protected constructor.
  51.      *
  52.      * @param detectionSettings event detection settings.
  53.      * @param newHandler   event handler.
  54.      * @param original     event detector.
  55.      * @since 13.0
  56.      */
  57.     protected FieldNegateDetector(final FieldEventDetectionSettings<T> detectionSettings,
  58.                                   final FieldEventHandler<T> newHandler,
  59.                                   final FieldEventDetector<T> original) {
  60.         super(detectionSettings, newHandler);
  61.         this.original = original;
  62.     }

  63.     /**
  64.      * Get the delegate event detector.
  65.      * @return the delegate event detector
  66.      */
  67.     public FieldEventDetector<T> getOriginal() {
  68.         return original;
  69.     }

  70.     @Override
  71.     public FieldEventDetector<T> getDetector() {
  72.         return getOriginal();
  73.     }

  74.     @Override
  75.     public void init(final FieldSpacecraftState<T> s0, final FieldAbsoluteDate<T> t) {
  76.         super.init(s0, t);
  77.         getDetector().init(s0, t);
  78.     }

  79.     @Override
  80.     public T g(final FieldSpacecraftState<T> s) {
  81.         return original.g(s).negate();
  82.     }

  83.     @Override
  84.     protected FieldNegateDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  85.                                             final FieldEventHandler<T> newHandler) {
  86.         return new FieldNegateDetector<>(detectionSettings, newHandler, original);
  87.     }

  88. }