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.ssa.metrics;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.util.MathUtils;
21  import org.orekit.ssa.collision.shorttermencounter.probability.twod.Alfriend1999Max;
22  import org.orekit.ssa.collision.shorttermencounter.probability.twod.Laas2015;
23  
24  /**
25   * Container for values relative to the probability of collision :
26   * <ul>
27   *     <li>Value of the probability of collision.</li>
28   *     <li>Name of the method with which it was computed.</li>
29   *     <li>Upper and lower limit of the value if the method provides them (such as {@link Laas2015} for example).</li>
30   *     <li>Flag defining if the probability was maximized in any way (such as {@link Alfriend1999Max} for example).</li>
31   * </ul>
32   *
33   * @author Vincent Cucchietti
34   * @since 12.0
35   * @param <T> type of the field elements
36   */
37  public class FieldProbabilityOfCollision<T extends CalculusFieldElement<T>> {
38  
39      /** Value of the probability of collision. */
40      private final T value;
41  
42      /**
43       * Lower limit of the probability of collision.
44       * <p>
45       * 0 by default.
46       */
47      private final T lowerLimit;
48  
49      /**
50       * Upper limit of the probability of collision.
51       * <p>
52       * 0 by default.
53       */
54      private final T upperLimit;
55  
56      /** Name of the probability computing method with which this probability was calculated. */
57      private final String probabilityOfCollisionMethodName;
58  
59      /**
60       * Defines if this probability of collision can be considered a maximum probability of collision.
61       * <p>
62       * It depends on what method was used to compute this probability.
63       * <p>
64       * False by default.
65       */
66      private final boolean isMaxProbability;
67  
68      /**
69       * Constructor with default values of 0 for the upper/lower limits and default false flag for maximum probability.
70       *
71       * @param value value of the probability of collision
72       * @param probabilityOfCollisionMethodName name of the probability computing method with which this probability was
73       * computed
74       */
75      public FieldProbabilityOfCollision(final T value, final String probabilityOfCollisionMethodName) {
76          this(value, probabilityOfCollisionMethodName, false);
77      }
78  
79      /**
80       * Constructor with default values of 0 for the upper and lower limits.
81       *
82       * @param value value of the probability of collision
83       * @param probabilityOfCollisionMethodName name of the probability computing method with which this probability was
84       * computed
85       * @param isMaxProbability flag defining if it has been computed using a maximum probability of collision method
86       */
87      public FieldProbabilityOfCollision(final T value, final String probabilityOfCollisionMethodName,
88                                         final boolean isMaxProbability) {
89          this(value, value.getField().getZero(), value.getField().getZero(), probabilityOfCollisionMethodName,
90               isMaxProbability);
91      }
92  
93      /**
94       * Constructor.
95       *
96       * @param value value of the probability of collision
97       * @param lowerLimit lower limit of the probability of collision
98       * @param upperLimit upper limit of the probability of collision
99       * @param probabilityOfCollisionMethodName name of the probability computing method with which this probability was
100      * computed
101      * @param isMaxProbability flag indicating if this method computes a maximum probability of collision
102      */
103     public FieldProbabilityOfCollision(final T value, final T lowerLimit, final T upperLimit,
104                                        final String probabilityOfCollisionMethodName, final boolean isMaxProbability) {
105 
106         // Check that inputs are valid
107         MathUtils.checkRangeInclusive(value.getReal(), 0, 1);
108         MathUtils.checkRangeInclusive(lowerLimit.getReal(), 0, 1);
109         MathUtils.checkRangeInclusive(upperLimit.getReal(), 0, 1);
110 
111         // Initialization
112         this.value                            = value;
113         this.lowerLimit                       = lowerLimit;
114         this.upperLimit                       = upperLimit;
115         this.probabilityOfCollisionMethodName = probabilityOfCollisionMethodName;
116         this.isMaxProbability                 = isMaxProbability;
117     }
118 
119     /** Get value of the probability of collision.
120      * @return value of the probability of collision
121      */
122     public T getValue() {
123         return value;
124     }
125 
126     /** Get lower limit of the probability of collision value.
127      * @return lower limit of the probability of collision value, 0 by default
128      */
129     public T getLowerLimit() {
130         return lowerLimit;
131     }
132 
133     /** Get upper limit of the probability of collision value.
134      * @return upper limit of the probability of collision value, 0 by default
135      */
136     public T getUpperLimit() {
137         return upperLimit;
138     }
139 
140     /** Get name of the probability computing method with which this probability was computed.
141      * @return name of the probability computing method with which this probability was computed
142      */
143     public String getProbabilityOfCollisionMethodName() {
144         return probabilityOfCollisionMethodName;
145     }
146 
147     /** Get flag that defines if this probability of collision can be considered a maximum probability of collision.
148      * @return flag that defines if this probability of collision can be considered a maximum probability of collision
149      */
150     public boolean isMaxProbability() {
151         return isMaxProbability;
152     }
153 
154 }