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