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.DoubleScalarRel;
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 = "2025-09-06T15:16:28.380798Z")
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 public static final Angle PI = new Angle(Math.PI, AngleUnit.RADIAN);
41
42
43 public static final Angle HALF_PI = new Angle(Math.PI / 2.0, AngleUnit.RADIAN);
44
45
46 public static final Angle TAU = new Angle(Math.PI * 2.0, AngleUnit.RADIAN);
47
48
49 @SuppressWarnings("checkstyle:constantname")
50 public static final Angle NaN = new Angle(Double.NaN, AngleUnit.SI);
51
52
53 public static final Angle POSITIVE_INFINITY = new Angle(Double.POSITIVE_INFINITY, AngleUnit.SI);
54
55
56 public static final Angle NEGATIVE_INFINITY = new Angle(Double.NEGATIVE_INFINITY, AngleUnit.SI);
57
58
59 public static final Angle POS_MAXVALUE = new Angle(Double.MAX_VALUE, AngleUnit.SI);
60
61
62 public static final Angle NEG_MAXVALUE = new Angle(-Double.MAX_VALUE, AngleUnit.SI);
63
64
65
66
67
68
69 public Angle(final double value, final AngleUnit unit)
70 {
71 super(value, unit);
72 }
73
74
75
76
77
78 public Angle(final Angle value)
79 {
80 super(value);
81 }
82
83 @Override
84 public final Angle instantiateRel(final double value, final AngleUnit unit)
85 {
86 return new Angle(value, unit);
87 }
88
89 @Override
90 public final Direction instantiateAbs(final double value, final DirectionUnit unit)
91 {
92 return new Direction(value, unit);
93 }
94
95
96
97
98
99
100 public static final Angle ofSI(final double value)
101 {
102 return new Angle(value, AngleUnit.SI);
103 }
104
105
106
107
108
109
110
111
112 public static Angle interpolate(final Angle zero, final Angle one, final double ratio)
113 {
114 Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
115 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
116 return new Angle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
117 }
118
119
120
121
122
123
124
125 public static Angle max(final Angle r1, final Angle r2)
126 {
127 return r1.gt(r2) ? r1 : r2;
128 }
129
130
131
132
133
134
135
136
137 public static Angle max(final Angle r1, final Angle r2, final Angle... rn)
138 {
139 Angle maxr = r1.gt(r2) ? r1 : r2;
140 for (Angle r : rn)
141 {
142 if (r.gt(maxr))
143 {
144 maxr = r;
145 }
146 }
147 return maxr;
148 }
149
150
151
152
153
154
155
156 public static Angle min(final Angle r1, final Angle r2)
157 {
158 return r1.lt(r2) ? r1 : r2;
159 }
160
161
162
163
164
165
166
167
168 public static Angle min(final Angle r1, final Angle r2, final Angle... rn)
169 {
170 Angle minr = r1.lt(r2) ? r1 : r2;
171 for (Angle r : rn)
172 {
173 if (r.lt(minr))
174 {
175 minr = r;
176 }
177 }
178 return minr;
179 }
180
181
182
183
184
185
186
187
188
189
190 public static Angle valueOf(final String text)
191 {
192 Throw.whenNull(text, "Error parsing Angle: text to parse is null");
193 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Angle: empty text to parse");
194 try
195 {
196 NumberParser numberParser = new NumberParser().lenient().trailing();
197 double d = numberParser.parseDouble(text);
198 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
199 AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
200 Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity Angle", unitString);
201 return new Angle(d, unit);
202 }
203 catch (Exception exception)
204 {
205 throw new IllegalArgumentException(
206 "Error parsing Angle from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
207 exception);
208 }
209 }
210
211
212
213
214
215
216
217
218
219 public static Angle of(final double value, final String unitString)
220 {
221 Throw.whenNull(unitString, "Error parsing Angle: unitString is null");
222 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Angle: empty unitString");
223 AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
224 Throw.when(unit == null, IllegalArgumentException.class, "Error parsing Angle with unit %s", unitString);
225 return new Angle(value, unit);
226 }
227
228
229
230
231
232
233 public final Dimensionless divide(final Angle v)
234 {
235 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
236 }
237
238
239
240
241
242
243 public final AngularVelocity times(final Frequency v)
244 {
245 return new AngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
246 }
247
248
249
250
251
252
253 public final AngularVelocity divide(final Duration v)
254 {
255 return new AngularVelocity(this.si / v.si, AngularVelocityUnit.SI);
256 }
257
258
259
260
261
262
263 public final Duration divide(final AngularVelocity v)
264 {
265 return new Duration(this.si / v.si, DurationUnit.SI);
266 }
267
268 @Override
269 public SIScalar reciprocal()
270 {
271 return SIScalar.divide(Dimensionless.ONE, this);
272 }
273
274
275
276
277
278
279
280 public static Angle multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
281 {
282 Throw.whenNull(scalar1, "scalar1 cannot be null");
283 Throw.whenNull(scalar2, "scalar2 cannot be null");
284 Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
285 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(AngleUnit.BASE.getSiDimensions()),
286 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type Angle",
287 scalar1.toDisplayString(), scalar2.toDisplayString());
288 return new Angle(scalar1.si * scalar2.si, AngleUnit.SI);
289 }
290
291
292
293
294
295
296
297 public static Angle divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
298 {
299 Throw.whenNull(scalar1, "scalar1 cannot be null");
300 Throw.whenNull(scalar2, "scalar2 cannot be null");
301 Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
302 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(AngleUnit.BASE.getSiDimensions()),
303 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type Angle",
304 scalar1.toDisplayString(), scalar2.toDisplayString());
305 return new Angle(scalar1.si / scalar2.si, AngleUnit.SI);
306 }
307
308 }