View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.unit.LuminousFluxUnit;
7   import org.djunits.unit.SolidAngleUnit;
8   import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
9   import org.djutils.base.NumberParser;
10  import org.djutils.exceptions.Throw;
11  
12  import jakarta.annotation.Generated;
13  
14  /**
15   * Easy access methods for the SolidAngle DoubleScalar, which is relative by definition.
16   * <p>
17   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
19   * </p>
20   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
22   */
23  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
24  public class SolidAngle extends DoubleScalarRel<SolidAngleUnit, SolidAngle>
25  {
26      /** */
27      private static final long serialVersionUID = 20150905L;
28  
29      /** Constant with value zero. */
30      public static final SolidAngle ZERO = new SolidAngle(0.0, SolidAngleUnit.SI);
31  
32      /** Constant with value one. */
33      public static final SolidAngle ONE = new SolidAngle(1.0, SolidAngleUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final SolidAngle NaN = new SolidAngle(Double.NaN, SolidAngleUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final SolidAngle POSITIVE_INFINITY = new SolidAngle(Double.POSITIVE_INFINITY, SolidAngleUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final SolidAngle NEGATIVE_INFINITY = new SolidAngle(Double.NEGATIVE_INFINITY, SolidAngleUnit.SI);
44  
45      /** Constant with value MAX_VALUE. */
46      public static final SolidAngle POS_MAXVALUE = new SolidAngle(Double.MAX_VALUE, SolidAngleUnit.SI);
47  
48      /** Constant with value -MAX_VALUE. */
49      public static final SolidAngle NEG_MAXVALUE = new SolidAngle(-Double.MAX_VALUE, SolidAngleUnit.SI);
50  
51      /**
52       * Construct SolidAngle scalar with a unit.
53       * @param value the double value, expressed in the given unit
54       * @param unit unit for the double value
55       */
56      public SolidAngle(final double value, final SolidAngleUnit unit)
57      {
58          super(value, unit);
59      }
60  
61      /**
62       * Construct SolidAngle scalar.
63       * @param value Scalar from which to construct this instance
64       */
65      public SolidAngle(final SolidAngle value)
66      {
67          super(value);
68      }
69  
70      @Override
71      public final SolidAngle instantiateRel(final double value, final SolidAngleUnit unit)
72      {
73          return new SolidAngle(value, unit);
74      }
75  
76      /**
77       * Construct SolidAngle scalar based on an SI value.
78       * @param value the double value in SI units
79       * @return the new scalar with the SI value
80       */
81      public static final SolidAngle ofSI(final double value)
82      {
83          return new SolidAngle(value, SolidAngleUnit.SI);
84      }
85  
86      /**
87       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
88       * @param zero the value at a ratio of zero
89       * @param one the value at a ratio of one
90       * @param ratio the ratio between 0 and 1, inclusive
91       * @return a SolidAngle at the given ratio between 0 and 1
92       */
93      public static SolidAngle interpolate(final SolidAngle zero, final SolidAngle one, final double ratio)
94      {
95          Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
96                  "ratio for interpolation should be between 0 and 1, but is %f", ratio);
97          return new SolidAngle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
98                  zero.getDisplayUnit());
99      }
100 
101     /**
102      * Return the maximum value of two relative scalars.
103      * @param r1 the first scalar
104      * @param r2 the second scalar
105      * @return the maximum value of two relative scalars
106      */
107     public static SolidAngle max(final SolidAngle r1, final SolidAngle r2)
108     {
109         return r1.gt(r2) ? r1 : r2;
110     }
111 
112     /**
113      * Return the maximum value of more than two relative scalars.
114      * @param r1 the first scalar
115      * @param r2 the second scalar
116      * @param rn the other scalars
117      * @return the maximum value of more than two relative scalars
118      */
119     public static SolidAngle max(final SolidAngle r1, final SolidAngle r2, final SolidAngle... rn)
120     {
121         SolidAngle maxr = r1.gt(r2) ? r1 : r2;
122         for (SolidAngle r : rn)
123         {
124             if (r.gt(maxr))
125             {
126                 maxr = r;
127             }
128         }
129         return maxr;
130     }
131 
132     /**
133      * Return the minimum value of two relative scalars.
134      * @param r1 the first scalar
135      * @param r2 the second scalar
136      * @return the minimum value of two relative scalars
137      */
138     public static SolidAngle min(final SolidAngle r1, final SolidAngle r2)
139     {
140         return r1.lt(r2) ? r1 : r2;
141     }
142 
143     /**
144      * Return the minimum value of more than two relative scalars.
145      * @param r1 the first scalar
146      * @param r2 the second scalar
147      * @param rn the other scalars
148      * @return the minimum value of more than two relative scalars
149      */
150     public static SolidAngle min(final SolidAngle r1, final SolidAngle r2, final SolidAngle... rn)
151     {
152         SolidAngle minr = r1.lt(r2) ? r1 : r2;
153         for (SolidAngle r : rn)
154         {
155             if (r.lt(minr))
156             {
157                 minr = r;
158             }
159         }
160         return minr;
161     }
162 
163     /**
164      * Returns a SolidAngle representation of a textual representation of a value with a unit. The String representation that
165      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
166      * allowed, but not required, between the value and the unit.
167      * @param text the textual representation to parse into a SolidAngle
168      * @return the Scalar representation of the value in its unit
169      * @throws IllegalArgumentException when the text cannot be parsed
170      * @throws NullPointerException when the text argument is null
171      */
172     public static SolidAngle valueOf(final String text)
173     {
174         Throw.whenNull(text, "Error parsing SolidAngle: text to parse is null");
175         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing SolidAngle: empty text to parse");
176         try
177         {
178             NumberParser numberParser = new NumberParser().lenient().trailing();
179             double d = numberParser.parseDouble(text);
180             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
181             SolidAngleUnit unit = SolidAngleUnit.BASE.getUnitByAbbreviation(unitString);
182             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity SolidAngle", unitString);
183             return new SolidAngle(d, unit);
184         }
185         catch (Exception exception)
186         {
187             throw new IllegalArgumentException(
188                     "Error parsing SolidAngle from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
189                     exception);
190         }
191     }
192 
193     /**
194      * Returns a SolidAngle based on a value and the textual representation of the unit, which can be localized.
195      * @param value the value to use
196      * @param unitString the textual representation of the unit
197      * @return the Scalar representation of the value in its unit
198      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
199      * @throws NullPointerException when the unitString argument is null
200      */
201     public static SolidAngle of(final double value, final String unitString)
202     {
203         Throw.whenNull(unitString, "Error parsing SolidAngle: unitString is null");
204         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing SolidAngle: empty unitString");
205         SolidAngleUnit unit = SolidAngleUnit.BASE.getUnitByAbbreviation(unitString);
206         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing SolidAngle with unit %s", unitString);
207         return new SolidAngle(value, unit);
208     }
209 
210     /**
211      * Calculate the division of SolidAngle and SolidAngle, which results in a Dimensionless scalar.
212      * @param v scalar
213      * @return scalar as a division of SolidAngle and SolidAngle
214      */
215     public final Dimensionless divide(final SolidAngle v)
216     {
217         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
218     }
219 
220     /**
221      * Calculate the multiplication of SolidAngle and LuminousIntensity, which results in a LuminousFlux scalar.
222      * @param v scalar
223      * @return scalar as a multiplication of SolidAngle and LuminousIntensity
224      */
225     public final LuminousFlux times(final LuminousIntensity v)
226     {
227         return new LuminousFlux(this.si * v.si, LuminousFluxUnit.SI);
228     }
229 
230     @Override
231     public SIScalar reciprocal()
232     {
233         return SIScalar.divide(Dimensionless.ONE, this);
234     }
235 
236     /**
237      * Multiply two scalars that result in a scalar of type SolidAngle.
238      * @param scalar1 the first scalar
239      * @param scalar2 the second scalar
240      * @return the multiplication of both scalars as an instance of SolidAngle
241      */
242     public static SolidAngle multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
243     {
244         Throw.whenNull(scalar1, "scalar1 cannot be null");
245         Throw.whenNull(scalar2, "scalar2 cannot be null");
246         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
247                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(SolidAngleUnit.BASE.getSiDimensions()),
248                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type SolidAngle",
249                 scalar1.toDisplayString(), scalar2.toDisplayString());
250         return new SolidAngle(scalar1.si * scalar2.si, SolidAngleUnit.SI);
251     }
252 
253     /**
254      * Divide two scalars that result in a scalar of type SolidAngle.
255      * @param scalar1 the first scalar
256      * @param scalar2 the second scalar
257      * @return the division of scalar1 by scalar2 as an instance of SolidAngle
258      */
259     public static SolidAngle divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
260     {
261         Throw.whenNull(scalar1, "scalar1 cannot be null");
262         Throw.whenNull(scalar2, "scalar2 cannot be null");
263         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
264                 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(SolidAngleUnit.BASE.getSiDimensions()),
265                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type SolidAngle",
266                 scalar1.toDisplayString(), scalar2.toDisplayString());
267         return new SolidAngle(scalar1.si / scalar2.si, SolidAngleUnit.SI);
268     }
269 
270 }