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
16
17
18
19
20
21
22
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
31 public static final Angleble/scalar/Angle.html#Angle">Angle ZERO = new Angle(0.0, AngleUnit.SI);
32
33
34 public static final Angleuble/scalar/Angle.html#Angle">Angle ONE = new Angle(1.0, AngleUnit.SI);
35
36
37 @SuppressWarnings("checkstyle:constantname")
38 public static final Angleuble/scalar/Angle.html#Angle">Angle NaN = new Angle(Double.NaN, AngleUnit.SI);
39
40
41 public static final Anglegle.html#Angle">Angle POSITIVE_INFINITY = new Angle(Double.POSITIVE_INFINITY, AngleUnit.SI);
42
43
44 public static final Anglegle.html#Angle">Angle NEGATIVE_INFINITY = new Angle(Double.NEGATIVE_INFINITY, AngleUnit.SI);
45
46
47 public static final Anglear/Angle.html#Angle">Angle POS_MAXVALUE = new Angle(Double.MAX_VALUE, AngleUnit.SI);
48
49
50 public static final Anglear/Angle.html#Angle">Angle NEG_MAXVALUE = new Angle(-Double.MAX_VALUE, AngleUnit.SI);
51
52
53
54
55
56
57 public Angle(final double value, final AngleUnit unit)
58 {
59 super(value, unit);
60 }
61
62
63
64
65
66 public Angle/vdouble/scalar/Angle.html#Angle">Angle(final Angle value)
67 {
68 super(value);
69 }
70
71
72 @Override
73 public final Angle instantiateRel(final double value, final AngleUnit unit)
74 {
75 return new Angle(value, unit);
76 }
77
78
79 @Override
80 public final Direction instantiateAbs(final double value, final DirectionUnit unit)
81 {
82 return new Direction(value, unit);
83 }
84
85
86
87
88
89
90 public static final Angle instantiateSI(final double value)
91 {
92 return new Angle(value, AngleUnit.SI);
93 }
94
95
96
97
98
99
100
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
109
110
111
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
120
121
122
123
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
140
141
142
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
151
152
153
154
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
171
172
173
174
175
176
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
200
201
202
203
204
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
220
221
222
223 public final Dimensionless divide(final Angle v)
224 {
225 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
226 }
227
228 }