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.AbstractFloatScalarRelWithAbs;
11  import org.djunits.value.vfloat.scalar.base.FloatScalar;
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-2023 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-04-30T13:59:27.633664900Z")
28  public class FloatAngle extends AbstractFloatScalarRelWithAbs<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      /** {@inheritDoc} */
85      @Override
86      public final FloatAngle instantiateRel(final float value, final AngleUnit unit)
87      {
88          return new FloatAngle(value, unit);
89      }
90  
91      /**
92       * Construct FloatAngle scalar.
93       * @param value float; the float value in SI units
94       * @return FloatAngle; the new scalar with the SI value
95       */
96      public static final FloatAngle instantiateSI(final float value)
97      {
98          return new FloatAngle(value, AngleUnit.SI);
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public final FloatDirection instantiateAbs(final float value, final DirectionUnit unit)
104     {
105         return new FloatDirection(value, unit);
106     }
107 
108     /**
109      * Interpolate between two values.
110      * @param zero FloatAngle; the low value
111      * @param one FloatAngle; the high value
112      * @param ratio double; the ratio between 0 and 1, inclusive
113      * @return FloatAngle; a Scalar at the ratio between
114      */
115     public static FloatAngle interpolate(final FloatAngle zero, final FloatAngle one, final float ratio)
116     {
117         return new FloatAngle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
118                 zero.getDisplayUnit());
119     }
120 
121     /**
122      * Return the maximum value of two relative scalars.
123      * @param r1 FloatAngle; the first scalar
124      * @param r2 FloatAngle; the second scalar
125      * @return FloatAngle; the maximum value of two relative scalars
126      */
127     public static FloatAngle max(final FloatAngle r1, final FloatAngle r2)
128     {
129         return r1.gt(r2) ? r1 : r2;
130     }
131 
132     /**
133      * Return the maximum value of more than two relative scalars.
134      * @param r1 FloatAngle; the first scalar
135      * @param r2 FloatAngle; the second scalar
136      * @param rn FloatAngle...; the other scalars
137      * @return FloatAngle; the maximum value of more than two relative scalars
138      */
139     public static FloatAngle max(final FloatAngle r1, final FloatAngle r2, final FloatAngle... rn)
140     {
141         FloatAngle maxr = r1.gt(r2) ? r1 : r2;
142         for (FloatAngle r : rn)
143         {
144             if (r.gt(maxr))
145             {
146                 maxr = r;
147             }
148         }
149         return maxr;
150     }
151 
152     /**
153      * Return the minimum value of two relative scalars.
154      * @param r1 FloatAngle; the first scalar
155      * @param r2 FloatAngle; the second scalar
156      * @return FloatAngle; the minimum value of two relative scalars
157      */
158     public static FloatAngle min(final FloatAngle r1, final FloatAngle r2)
159     {
160         return r1.lt(r2) ? r1 : r2;
161     }
162 
163     /**
164      * Return the minimum value of more than two relative scalars.
165      * @param r1 FloatAngle; the first scalar
166      * @param r2 FloatAngle; the second scalar
167      * @param rn FloatAngle...; the other scalars
168      * @return FloatAngle; the minimum value of more than two relative scalars
169      */
170     public static FloatAngle min(final FloatAngle r1, final FloatAngle r2, final FloatAngle... rn)
171     {
172         FloatAngle minr = r1.lt(r2) ? r1 : r2;
173         for (FloatAngle r : rn)
174         {
175             if (r.lt(minr))
176             {
177                 minr = r;
178             }
179         }
180         return minr;
181     }
182 
183     /**
184      * Returns a FloatAngle representation of a textual representation of a value with a unit. The String representation that
185      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
186      * allowed, but not required, between the value and the unit.
187      * @param text String; the textual representation to parse into a FloatAngle
188      * @return FloatAngle; the Scalar representation of the value in its unit
189      * @throws IllegalArgumentException when the text cannot be parsed
190      * @throws NullPointerException when the text argument is null
191      */
192     public static FloatAngle valueOf(final String text)
193     {
194         Throw.whenNull(text, "Error parsing FloatAngle: text to parse is null");
195         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatAngle: empty text to parse");
196         try
197         {
198             NumberParser numberParser = new NumberParser().lenient().trailing();
199             float f = numberParser.parseFloat(text);
200             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
201             AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
202             if (unit == null)
203                 throw new IllegalArgumentException("Unit " + unitString + " not found");
204             return new FloatAngle(f, unit);
205         }
206         catch (Exception exception)
207         {
208             throw new IllegalArgumentException(
209                     "Error parsing FloatAngle from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
210                     exception);
211         }
212     }
213 
214     /**
215      * Returns a FloatAngle based on a value and the textual representation of the unit, which can be localized.
216      * @param value double; the value to use
217      * @param unitString String; the textual representation of the unit
218      * @return FloatAngle; the Scalar representation of the value in its unit
219      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
220      * @throws NullPointerException when the unitString argument is null
221      */
222     public static FloatAngle of(final float value, final String unitString)
223     {
224         Throw.whenNull(unitString, "Error parsing FloatAngle: unitString is null");
225         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatAngle: empty unitString");
226         AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
227         if (unit != null)
228         {
229             return new FloatAngle(value, unit);
230         }
231         throw new IllegalArgumentException("Error parsing FloatAngle with unit " + unitString);
232     }
233 
234     /**
235      * Calculate the division of FloatAngle and FloatAngle, which results in a FloatDimensionless scalar.
236      * @param v FloatAngle; scalar
237      * @return FloatDimensionless; scalar as a division of FloatAngle and FloatAngle
238      */
239     public final FloatDimensionless divide(final FloatAngle v)
240     {
241         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
242     }
243 
244     /**
245      * Calculate the multiplication of FloatAngle and FloatFrequency, which results in a FloatAngularVelocity scalar.
246      * @param v FloatAngle; scalar
247      * @return FloatAngularVelocity; scalar as a multiplication of FloatAngle and FloatFrequency
248      */
249     public final FloatAngularVelocity times(final FloatFrequency v)
250     {
251         return new FloatAngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
252     }
253 
254     /**
255      * Calculate the division of FloatAngle and FloatDuration, which results in a FloatAngularVelocity scalar.
256      * @param v FloatAngle; scalar
257      * @return FloatAngularVelocity; scalar as a division of FloatAngle and FloatDuration
258      */
259     public final FloatAngularVelocity divide(final FloatDuration v)
260     {
261         return new FloatAngularVelocity(this.si / v.si, AngularVelocityUnit.SI);
262     }
263 
264     /**
265      * Calculate the division of FloatAngle and FloatAngularVelocity, which results in a FloatDuration scalar.
266      * @param v FloatAngle; scalar
267      * @return FloatDuration; scalar as a division of FloatAngle and FloatAngularVelocity
268      */
269     public final FloatDuration divide(final FloatAngularVelocity v)
270     {
271         return new FloatDuration(this.si / v.si, DurationUnit.SI);
272     }
273 
274     /** {@inheritDoc} */
275     @Override
276     public FloatSIScalar reciprocal()
277     {
278         return FloatScalar.divide(FloatDimensionless.ONE, this);
279     }
280 
281 }