View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.AngleUnit;
9   import org.djunits.unit.AngularVelocityUnit;
10  import org.djunits.unit.DimensionlessUnit;
11  import org.djunits.unit.DirectionUnit;
12  import org.djunits.unit.DurationUnit;
13  import org.djunits.value.util.ValueUtil;
14  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRelWithAbs;
15  import org.djunits.value.vdouble.scalar.base.DoubleScalar;
16  
17  /**
18   * Easy access methods for the Relative Angle DoubleScalar.
19   * <p>
20   * Copyright (c) 2013-2022 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 = "2022-03-14T11:14:15.180987200Z")
28  public class Angle extends AbstractDoubleScalarRelWithAbs<DirectionUnit, Direction, AngleUnit, Angle>
29  {
30      /** */
31      private static final long serialVersionUID = 20150901L;
32  
33      /** Constant with value zero. */
34      public static final Angleble/scalar/Angle.html#Angle">Angle ZERO = new Angle(0.0, AngleUnit.SI);
35  
36      /** Constant with value one. */
37      public static final Angleuble/scalar/Angle.html#Angle">Angle ONE = new Angle(1.0, AngleUnit.SI);
38  
39      /** Constant with value NaN. */
40      @SuppressWarnings("checkstyle:constantname")
41      public static final Angleuble/scalar/Angle.html#Angle">Angle NaN = new Angle(Double.NaN, AngleUnit.SI);
42  
43      /** Constant with value POSITIVE_INFINITY. */
44      public static final Anglegle.html#Angle">Angle POSITIVE_INFINITY = new Angle(Double.POSITIVE_INFINITY, AngleUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final Anglegle.html#Angle">Angle NEGATIVE_INFINITY = new Angle(Double.NEGATIVE_INFINITY, AngleUnit.SI);
48  
49      /** Constant with value MAX_VALUE. */
50      public static final Anglear/Angle.html#Angle">Angle POS_MAXVALUE = new Angle(Double.MAX_VALUE, AngleUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final Anglear/Angle.html#Angle">Angle NEG_MAXVALUE = new Angle(-Double.MAX_VALUE, AngleUnit.SI);
54  
55      /**
56       * Construct Angle scalar.
57       * @param value double; double value
58       * @param unit AngleUnit; unit for the double value
59       */
60      public Angle(final double value, final AngleUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct Angle scalar.
67       * @param value Angle; Scalar from which to construct this instance
68       */
69      public Angle/vdouble/scalar/Angle.html#Angle">Angle(final Angle value)
70      {
71          super(value);
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public final Angle instantiateRel(final double value, final AngleUnit unit)
77      {
78          return new Angle(value, unit);
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public final Direction instantiateAbs(final double value, final DirectionUnit unit)
84      {
85          return new Direction(value, unit);
86      }
87  
88      /**
89       * Construct Angle scalar.
90       * @param value double; the double value in SI units
91       * @return Angle; the new scalar with the SI value
92       */
93      public static final Angle instantiateSI(final double value)
94      {
95          return new Angle(value, AngleUnit.SI);
96      }
97  
98      /**
99       * Interpolate between two values.
100      * @param zero Angle; the low value
101      * @param one Angle; the high value
102      * @param ratio double; the ratio between 0 and 1, inclusive
103      * @return Angle; a Scalar at the ratio between
104      */
105     public static Anglele/scalar/Angle.html#Angle">Anglelar/Angle.html#Angle">Angle interpolate(final Anglele/scalar/Angle.html#Angle">Angle zero, final Angle one, final double ratio)
106     {
107         return new Angle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
108     }
109 
110     /**
111      * Return the maximum value of two relative scalars.
112      * @param r1 Angle; the first scalar
113      * @param r2 Angle; the second scalar
114      * @return Angle; the maximum value of two relative scalars
115      */
116     public static Angleuble/scalar/Angle.html#Angle">Angleuble/scalar/Angle.html#Angle">Angle max(final Angleuble/scalar/Angle.html#Angle">Angle r1, final Angle 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 Angle; the first scalar
124      * @param r2 Angle; the second scalar
125      * @param rn Angle...; the other scalars
126      * @return Angle; the maximum value of more than two relative scalars
127      */
128     public static Angleuble/scalar/Angle.html#Angle">Angleuble/scalar/Angle.html#Angle">Angle max(final Angleuble/scalar/Angle.html#Angle">Angle r1, final Angle r2, final Angle... rn)
129     {
130         Angle maxr = r1.gt(r2) ? r1 : r2;
131         for (Angle 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 Angle; the first scalar
144      * @param r2 Angle; the second scalar
145      * @return Angle; the minimum value of two relative scalars
146      */
147     public static Angleuble/scalar/Angle.html#Angle">Angleuble/scalar/Angle.html#Angle">Angle min(final Angleuble/scalar/Angle.html#Angle">Angle r1, final Angle 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 Angle; the first scalar
155      * @param r2 Angle; the second scalar
156      * @param rn Angle...; the other scalars
157      * @return Angle; the minimum value of more than two relative scalars
158      */
159     public static Angleuble/scalar/Angle.html#Angle">Angleuble/scalar/Angle.html#Angle">Angle min(final Angleuble/scalar/Angle.html#Angle">Angle r1, final Angle r2, final Angle... rn)
160     {
161         Angle minr = r1.lt(r2) ? r1 : r2;
162         for (Angle r : rn)
163         {
164             if (r.lt(minr))
165             {
166                 minr = r;
167             }
168         }
169         return minr;
170     }
171 
172     /**
173      * Returns a Angle representation of a textual representation of a value with a unit. The String representation that can be
174      * parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but not
175      * required, between the value and the unit.
176      * @param text String; the textual representation to parse into a Angle
177      * @return Angle; 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 Angle valueOf(final String text)
182     {
183         Throw.whenNull(text, "Error parsing Angle: text to parse is null");
184         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Angle: empty text to parse");
185         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
186         if (matcher.find())
187         {
188             int index = matcher.end();
189             String unitString = text.substring(index).trim();
190             String valueString = text.substring(0, index).trim();
191             AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
192             if (unit != null)
193             {
194                 double d = Double.parseDouble(valueString);
195                 return new Angle(d, unit);
196             }
197         }
198         throw new IllegalArgumentException("Error parsing Angle from " + text);
199     }
200 
201     /**
202      * Returns a Angle based on a value and the textual representation of the unit.
203      * @param value double; the value to use
204      * @param unitString String; the textual representation of the unit
205      * @return Angle; the Scalar representation of the value in its unit
206      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
207      * @throws NullPointerException when the unitString argument is null
208      */
209     public static Angle of(final double value, final String unitString)
210     {
211         Throw.whenNull(unitString, "Error parsing Angle: unitString is null");
212         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Angle: empty unitString");
213         AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
214         if (unit != null)
215         {
216             return new Angle(value, unit);
217         }
218         throw new IllegalArgumentException("Error parsing Angle with unit " + unitString);
219     }
220 
221     /**
222      * Calculate the division of Angle and Angle, which results in a Dimensionless scalar.
223      * @param v Angle; scalar
224      * @return Dimensionless; scalar as a division of Angle and Angle
225      */
226     public final Dimensionless divide(final Angle v)
227     {
228         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
229     }
230 
231     /**
232      * Calculate the multiplication of Angle and Frequency, which results in a AngularVelocity scalar.
233      * @param v Angle; scalar
234      * @return AngularVelocity; scalar as a multiplication of Angle and Frequency
235      */
236     public final AngularVelocity times(final Frequency v)
237     {
238         return new AngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
239     }
240 
241     /**
242      * Calculate the division of Angle and Duration, which results in a AngularVelocity scalar.
243      * @param v Angle; scalar
244      * @return AngularVelocity; scalar as a division of Angle and Duration
245      */
246     public final AngularVelocity divide(final Duration v)
247     {
248         return new AngularVelocity(this.si / v.si, AngularVelocityUnit.SI);
249     }
250 
251     /**
252      * Calculate the division of Angle and AngularVelocity, which results in a Duration scalar.
253      * @param v Angle; scalar
254      * @return Duration; scalar as a division of Angle and AngularVelocity
255      */
256     public final Duration divide(final AngularVelocity v)
257     {
258         return new Duration(this.si / v.si, DurationUnit.SI);
259     }
260 
261     /** {@inheritDoc} */
262     @Override
263     public SIScalar reciprocal()
264     {
265         return DoubleScalar.divide(Dimensionless.ONE, this);
266     }
267 
268 }