1 package org.djunits.value.vdouble.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.vdouble.scalar.base.DoubleScalar;
11 import org.djunits.value.vdouble.scalar.base.DoubleScalarRelWithAbs;
12 import org.djutils.base.NumberParser;
13 import org.djutils.exceptions.Throw;
14
15 import jakarta.annotation.Generated;
16
17
18
19
20
21
22
23
24
25
26
27 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
28 public class Angle extends DoubleScalarRelWithAbs<DirectionUnit, Direction, AngleUnit, Angle>
29 {
30
31 private static final long serialVersionUID = 20150901L;
32
33
34 public static final Angle ZERO = new Angle(0.0, AngleUnit.SI);
35
36
37 public static final Angle ONE = new Angle(1.0, AngleUnit.SI);
38
39
40 @SuppressWarnings("checkstyle:constantname")
41 public static final Angle NaN = new Angle(Double.NaN, AngleUnit.SI);
42
43
44 public static final Angle POSITIVE_INFINITY = new Angle(Double.POSITIVE_INFINITY, AngleUnit.SI);
45
46
47 public static final Angle NEGATIVE_INFINITY = new Angle(Double.NEGATIVE_INFINITY, AngleUnit.SI);
48
49
50 public static final Angle POS_MAXVALUE = new Angle(Double.MAX_VALUE, AngleUnit.SI);
51
52
53 public static final Angle NEG_MAXVALUE = new Angle(-Double.MAX_VALUE, AngleUnit.SI);
54
55
56
57
58
59
60 public Angle(final double value, final AngleUnit unit)
61 {
62 super(value, unit);
63 }
64
65
66
67
68
69 public Angle(final Angle value)
70 {
71 super(value);
72 }
73
74 @Override
75 public final Angle instantiateRel(final double value, final AngleUnit unit)
76 {
77 return new Angle(value, unit);
78 }
79
80 @Override
81 public final Direction instantiateAbs(final double value, final DirectionUnit unit)
82 {
83 return new Direction(value, unit);
84 }
85
86
87
88
89
90
91 public static final Angle instantiateSI(final double value)
92 {
93 return new Angle(value, AngleUnit.SI);
94 }
95
96
97
98
99
100
101
102
103 public static Angle interpolate(final Angle zero, final Angle one, final double ratio)
104 {
105 return new Angle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
106 }
107
108
109
110
111
112
113
114 public static Angle max(final Angle r1, final Angle r2)
115 {
116 return r1.gt(r2) ? r1 : r2;
117 }
118
119
120
121
122
123
124
125
126 public static Angle max(final Angle r1, final Angle r2, final Angle... rn)
127 {
128 Angle maxr = r1.gt(r2) ? r1 : r2;
129 for (Angle r : rn)
130 {
131 if (r.gt(maxr))
132 {
133 maxr = r;
134 }
135 }
136 return maxr;
137 }
138
139
140
141
142
143
144
145 public static Angle min(final Angle r1, final Angle r2)
146 {
147 return r1.lt(r2) ? r1 : r2;
148 }
149
150
151
152
153
154
155
156
157 public static Angle min(final Angle r1, final Angle r2, final Angle... rn)
158 {
159 Angle minr = r1.lt(r2) ? r1 : r2;
160 for (Angle r : rn)
161 {
162 if (r.lt(minr))
163 {
164 minr = r;
165 }
166 }
167 return minr;
168 }
169
170
171
172
173
174
175
176
177
178
179 public static Angle valueOf(final String text)
180 {
181 Throw.whenNull(text, "Error parsing Angle: text to parse is null");
182 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Angle: empty text to parse");
183 try
184 {
185 NumberParser numberParser = new NumberParser().lenient().trailing();
186 double d = numberParser.parseDouble(text);
187 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
188 AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
189 if (unit == null)
190 throw new IllegalArgumentException("Unit " + unitString + " not found");
191 return new Angle(d, unit);
192 }
193 catch (Exception exception)
194 {
195 throw new IllegalArgumentException(
196 "Error parsing Angle from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
197 exception);
198 }
199 }
200
201
202
203
204
205
206
207
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
223
224
225
226 public final Dimensionless divide(final Angle v)
227 {
228 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
229 }
230
231
232
233
234
235
236 public final AngularVelocity times(final Frequency v)
237 {
238 return new AngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
239 }
240
241
242
243
244
245
246 public final AngularVelocity divide(final Duration v)
247 {
248 return new AngularVelocity(this.si / v.si, AngularVelocityUnit.SI);
249 }
250
251
252
253
254
255
256 public final Duration divide(final AngularVelocity v)
257 {
258 return new Duration(this.si / v.si, DurationUnit.SI);
259 }
260
261 @Override
262 public SIScalar reciprocal()
263 {
264 return DoubleScalar.divide(Dimensionless.ONE, this);
265 }
266
267 }