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