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.IlluminanceUnit;
7   import org.djunits.unit.LuminousFluxUnit;
8   import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
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 FloatIlluminance FloatScalar, 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 FloatIlluminance extends FloatScalarRel<IlluminanceUnit, FloatIlluminance>
25  {
26      /** */
27      private static final long serialVersionUID = 20150901L;
28  
29      /** Constant with value zero. */
30      public static final FloatIlluminance ZERO = new FloatIlluminance(0.0f, IlluminanceUnit.SI);
31  
32      /** Constant with value one. */
33      public static final FloatIlluminance ONE = new FloatIlluminance(1.0f, IlluminanceUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final FloatIlluminance NaN = new FloatIlluminance(Float.NaN, IlluminanceUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final FloatIlluminance POSITIVE_INFINITY = new FloatIlluminance(Float.POSITIVE_INFINITY, IlluminanceUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final FloatIlluminance NEGATIVE_INFINITY = new FloatIlluminance(Float.NEGATIVE_INFINITY, IlluminanceUnit.SI);
44  
45      /** Constant with value MAX_VALUE. */
46      public static final FloatIlluminance POS_MAXVALUE = new FloatIlluminance(Float.MAX_VALUE, IlluminanceUnit.SI);
47  
48      /** Constant with value -MAX_VALUE. */
49      public static final FloatIlluminance NEG_MAXVALUE = new FloatIlluminance(-Float.MAX_VALUE, IlluminanceUnit.SI);
50  
51      /**
52       * Construct FloatIlluminance scalar with a unit.
53       * @param value the float value, expressed in the given unit
54       * @param unit unit for the float value
55       */
56      public FloatIlluminance(final float value, final IlluminanceUnit unit)
57      {
58          super(value, unit);
59      }
60  
61      /**
62       * Construct FloatIlluminance scalar.
63       * @param value Scalar from which to construct this instance
64       */
65      public FloatIlluminance(final FloatIlluminance value)
66      {
67          super(value);
68      }
69  
70      /**
71       * Construct FloatIlluminance scalar with a unit using a double value.
72       * @param value the double value, expressed in the given unit
73       * @param unit unit for the resulting float value
74       */
75      public FloatIlluminance(final double value, final IlluminanceUnit unit)
76      {
77          super((float) value, unit);
78      }
79  
80      @Override
81      public final FloatIlluminance instantiateRel(final float value, final IlluminanceUnit unit)
82      {
83          return new FloatIlluminance(value, unit);
84      }
85  
86      /**
87       * Construct FloatIlluminance scalar based on an SI value.
88       * @param value the float value in SI units
89       * @return the new scalar with the SI value
90       */
91      public static final FloatIlluminance ofSI(final float value)
92      {
93          return new FloatIlluminance(value, IlluminanceUnit.SI);
94      }
95  
96      /**
97       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
98       * @param zero the value at a ratio of zero
99       * @param one the value at a ratio of one
100      * @param ratio the ratio between 0 and 1, inclusive
101      * @return a FloatIlluminance at the given ratio between 0 and 1
102      */
103     public static FloatIlluminance interpolate(final FloatIlluminance zero, final FloatIlluminance one, final float ratio)
104     {
105         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
106                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
107         return new FloatIlluminance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
108                 zero.getDisplayUnit());
109     }
110 
111     /**
112      * Return the maximum value of two relative scalars.
113      * @param r1 the first scalar
114      * @param r2 the second scalar
115      * @return the maximum value of two relative scalars
116      */
117     public static FloatIlluminance max(final FloatIlluminance r1, final FloatIlluminance r2)
118     {
119         return r1.gt(r2) ? r1 : r2;
120     }
121 
122     /**
123      * Return the maximum value of more than two relative scalars.
124      * @param r1 the first scalar
125      * @param r2 the second scalar
126      * @param rn the other scalars
127      * @return the maximum value of more than two relative scalars
128      */
129     public static FloatIlluminance max(final FloatIlluminance r1, final FloatIlluminance r2, final FloatIlluminance... rn)
130     {
131         FloatIlluminance maxr = r1.gt(r2) ? r1 : r2;
132         for (FloatIlluminance r : rn)
133         {
134             if (r.gt(maxr))
135             {
136                 maxr = r;
137             }
138         }
139         return maxr;
140     }
141 
142     /**
143      * Return the minimum value of two relative scalars.
144      * @param r1 the first scalar
145      * @param r2 the second scalar
146      * @return the minimum value of two relative scalars
147      */
148     public static FloatIlluminance min(final FloatIlluminance r1, final FloatIlluminance r2)
149     {
150         return r1.lt(r2) ? r1 : r2;
151     }
152 
153     /**
154      * Return the minimum value of more than two relative scalars.
155      * @param r1 the first scalar
156      * @param r2 the second scalar
157      * @param rn the other scalars
158      * @return the minimum value of more than two relative scalars
159      */
160     public static FloatIlluminance min(final FloatIlluminance r1, final FloatIlluminance r2, final FloatIlluminance... rn)
161     {
162         FloatIlluminance minr = r1.lt(r2) ? r1 : r2;
163         for (FloatIlluminance r : rn)
164         {
165             if (r.lt(minr))
166             {
167                 minr = r;
168             }
169         }
170         return minr;
171     }
172 
173     /**
174      * Returns a FloatIlluminance representation of a textual representation of a value with a unit. The String representation
175      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
176      * are allowed, but not required, between the value and the unit.
177      * @param text the textual representation to parse into a FloatIlluminance
178      * @return the Scalar representation of the value in its unit
179      * @throws IllegalArgumentException when the text cannot be parsed
180      * @throws NullPointerException when the text argument is null
181      */
182     public static FloatIlluminance valueOf(final String text)
183     {
184         Throw.whenNull(text, "Error parsing FloatIlluminance: text to parse is null");
185         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatIlluminance: empty text to parse");
186         try
187         {
188             NumberParser numberParser = new NumberParser().lenient().trailing();
189             float f = numberParser.parseFloat(text);
190             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
191             IlluminanceUnit unit = IlluminanceUnit.BASE.getUnitByAbbreviation(unitString);
192             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity Illuminance", unitString);
193             return new FloatIlluminance(f, unit);
194         }
195         catch (Exception exception)
196         {
197             throw new IllegalArgumentException("Error parsing FloatIlluminance from " + text + " using Locale "
198                     + Locale.getDefault(Locale.Category.FORMAT), exception);
199         }
200     }
201 
202     /**
203      * Returns a FloatIlluminance based on a value and the textual representation of the unit, which can be localized.
204      * @param value the value to use
205      * @param unitString the textual representation of the unit
206      * @return the Scalar representation of the value in its unit
207      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
208      * @throws NullPointerException when the unitString argument is null
209      */
210     public static FloatIlluminance of(final float value, final String unitString)
211     {
212         Throw.whenNull(unitString, "Error parsing FloatIlluminance: unitString is null");
213         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
214                 "Error parsing FloatIlluminance: empty unitString");
215         IlluminanceUnit unit = IlluminanceUnit.BASE.getUnitByAbbreviation(unitString);
216         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatIlluminance with unit %s", unitString);
217         return new FloatIlluminance(value, unit);
218     }
219 
220     /**
221      * Calculate the division of FloatIlluminance and FloatIlluminance, which results in a FloatDimensionless scalar.
222      * @param v scalar
223      * @return scalar as a division of FloatIlluminance and FloatIlluminance
224      */
225     public final FloatDimensionless divide(final FloatIlluminance v)
226     {
227         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
228     }
229 
230     /**
231      * Calculate the multiplication of FloatIlluminance and FloatArea, which results in a FloatLuminousFlux scalar.
232      * @param v scalar
233      * @return scalar as a multiplication of FloatIlluminance and FloatArea
234      */
235     public final FloatLuminousFlux times(final FloatArea v)
236     {
237         return new FloatLuminousFlux(this.si * v.si, LuminousFluxUnit.SI);
238     }
239 
240     @Override
241     public FloatSIScalar reciprocal()
242     {
243         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
244     }
245 
246     /**
247      * Multiply two scalars that result in a scalar of type FloatIlluminance.
248      * @param scalar1 the first scalar
249      * @param scalar2 the second scalar
250      * @return the multiplication of both scalars as an instance of FloatIlluminance
251      */
252     public static FloatIlluminance multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
253     {
254         Throw.whenNull(scalar1, "scalar1 cannot be null");
255         Throw.whenNull(scalar2, "scalar2 cannot be null");
256         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
257                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(IlluminanceUnit.BASE.getSiDimensions()),
258                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatIlluminance",
259                 scalar1.toDisplayString(), scalar2.toDisplayString());
260         return new FloatIlluminance(scalar1.si * scalar2.si, IlluminanceUnit.SI);
261     }
262 
263     /**
264      * Divide two scalars that result in a scalar of type FloatIlluminance.
265      * @param scalar1 the first scalar
266      * @param scalar2 the second scalar
267      * @return the division of scalar1 by scalar2 as an instance of FloatIlluminance
268      */
269     public static FloatIlluminance divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
270     {
271         Throw.whenNull(scalar1, "scalar1 cannot be null");
272         Throw.whenNull(scalar2, "scalar2 cannot be null");
273         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
274                 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(IlluminanceUnit.BASE.getSiDimensions()),
275                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatIlluminance",
276                 scalar1.toDisplayString(), scalar2.toDisplayString());
277         return new FloatIlluminance(scalar1.si / scalar2.si, IlluminanceUnit.SI);
278     }
279 
280 }