TimeIntervalDetector.java

  1. /* Copyright 2022-2025 Romain Serra
  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.EventHandler;
  20. import org.orekit.propagation.events.intervals.DateDetectionAdaptableIntervalFactory;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.time.TimeInterval;


  23. /**
  24.  * Detector for time intervals. Positive whenever the date is inside, negative otherwise.
  25.  *
  26.  * @author Romain Serra
  27.  * @since 13.1
  28.  * @see TimeInterval
  29.  */
  30. public class TimeIntervalDetector extends AbstractDetector<TimeIntervalDetector> {

  31.     /** Time interval for detection. */
  32.     private final TimeInterval timeInterval;

  33.     /**
  34.      * Constructor with default detection settings.
  35.      * @param handler event handler
  36.      * @param timeInterval time interval
  37.      */
  38.     public TimeIntervalDetector(final EventHandler handler, final TimeInterval timeInterval) {
  39.         this(new EventDetectionSettings(DateDetectionAdaptableIntervalFactory.getDatesDetectionInterval(timeInterval.getStartDate(), timeInterval.getEndDate()),
  40.                 DateDetector.DEFAULT_THRESHOLD, DEFAULT_MAX_ITER), handler, timeInterval);
  41.     }

  42.     /**
  43.      * Constructor.
  44.      * @param detectionSettings event detection settings
  45.      * @param handler event handler
  46.      * @param timeInterval time interval
  47.      */
  48.     public TimeIntervalDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  49.                                 final TimeInterval timeInterval) {
  50.         super(detectionSettings, handler);
  51.         this.timeInterval = timeInterval;
  52.     }

  53.     /**
  54.      * Getter for the time interval.
  55.      * @return interval
  56.      */
  57.     public TimeInterval getTimeInterval() {
  58.         return timeInterval;
  59.     }

  60.     @Override
  61.     protected TimeIntervalDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  62.         return new TimeIntervalDetector(detectionSettings, newHandler, timeInterval);
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public boolean dependsOnTimeOnly() {
  67.         return true;
  68.     }

  69.     @Override
  70.     public double g(final SpacecraftState s) {
  71.         final AbsoluteDate date = s.getDate();
  72.         return (date.durationFrom(timeInterval.getStartDate())) * (timeInterval.getEndDate().durationFrom(date));
  73.     }
  74. }