1   /* Copyright 2002-2025 CS GROUP
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.models.earth.tessellation;
18  
19  import org.hipparchus.ode.events.Action;
20  import org.orekit.propagation.SpacecraftState;
21  import org.orekit.propagation.events.EventDetector;
22  import org.orekit.propagation.events.handlers.EventHandler;
23  import org.orekit.time.AbsoluteDate;
24  
25  /** Event handler for half track span.
26   * @since 7.1
27   * @see AlongTrackAiming
28   * @author Luc Maisonobe
29   */
30  class HalfTrackSpanHandler implements EventHandler {
31  
32      /** Indicator for zone tiling with respect to ascending or descending orbits. */
33      private final boolean isAscending;
34  
35      /** Halftrack start date. */
36      private AbsoluteDate start;
37  
38      /** Halftrack end date. */
39      private AbsoluteDate end;
40  
41      /** Simple constructor.
42       * @param isAscending indicator for zone tiling with respect to ascending
43       * or descending orbits
44       */
45      HalfTrackSpanHandler(final boolean isAscending) {
46          this.isAscending = isAscending;
47          this.start       = null;
48          this.end         = null;
49      }
50  
51      /** Get the start date of the half track.
52       * @return start date of the half track
53       */
54      public AbsoluteDate getStart() {
55          return start;
56      }
57  
58      /** Get the end date of the half track.
59       * @return end date of the half track
60       */
61      public AbsoluteDate getEnd() {
62          return end;
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public Action eventOccurred(final SpacecraftState s, final EventDetector detector, final boolean increasing) {
68          if (increasing ^ isAscending) {
69              // we have found an end event
70              if (start == null) {
71                  // we don't have the start event yet,
72                  // so we ignore this and wait for the next orbit
73                  return Action.CONTINUE;
74              } else {
75                  end = s.getDate();
76                  return Action.STOP;
77              }
78          } else {
79              // we have found the start of the span
80              start = s.getDate();
81              return Action.CONTINUE;
82          }
83      }
84  
85  }