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