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