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.AbstractDoubleScalarRelWithAbs;
11 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
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-04-30T13:59:27.633664900Z")
28 public class Angle extends AbstractDoubleScalarRelWithAbs<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
75 @Override
76 public final Angle instantiateRel(final double value, final AngleUnit unit)
77 {
78 return new Angle(value, unit);
79 }
80
81
82 @Override
83 public final Direction instantiateAbs(final double value, final DirectionUnit unit)
84 {
85 return new Direction(value, unit);
86 }
87
88
89
90
91
92
93 public static final Angle instantiateSI(final double value)
94 {
95 return new Angle(value, AngleUnit.SI);
96 }
97
98
99
100
101
102
103
104
105 public static Angle interpolate(final Angle zero, final Angle one, final double ratio)
106 {
107 return new Angle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
108 }
109
110
111
112
113
114
115
116 public static Angle max(final Angle r1, final Angle r2)
117 {
118 return r1.gt(r2) ? r1 : r2;
119 }
120
121
122
123
124
125
126
127
128 public static Angle max(final Angle r1, final Angle r2, final Angle... rn)
129 {
130 Angle maxr = r1.gt(r2) ? r1 : r2;
131 for (Angle r : rn)
132 {
133 if (r.gt(maxr))
134 {
135 maxr = r;
136 }
137 }
138 return maxr;
139 }
140
141
142
143
144
145
146
147 public static Angle min(final Angle r1, final Angle r2)
148 {
149 return r1.lt(r2) ? r1 : r2;
150 }
151
152
153
154
155
156
157
158
159 public static Angle min(final Angle r1, final Angle r2, final Angle... rn)
160 {
161 Angle minr = r1.lt(r2) ? r1 : r2;
162 for (Angle r : rn)
163 {
164 if (r.lt(minr))
165 {
166 minr = r;
167 }
168 }
169 return minr;
170 }
171
172
173
174
175
176
177
178
179
180
181 public static Angle valueOf(final String text)
182 {
183 Throw.whenNull(text, "Error parsing Angle: text to parse is null");
184 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Angle: empty text to parse");
185 try
186 {
187 NumberParser numberParser = new NumberParser().lenient().trailing();
188 double d = numberParser.parseDouble(text);
189 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
190 AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
191 if (unit == null)
192 throw new IllegalArgumentException("Unit " + unitString + " not found");
193 return new Angle(d, unit);
194 }
195 catch (Exception exception)
196 {
197 throw new IllegalArgumentException(
198 "Error parsing Angle from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
199 exception);
200 }
201 }
202
203
204
205
206
207
208
209
210
211 public static Angle of(final double value, final String unitString)
212 {
213 Throw.whenNull(unitString, "Error parsing Angle: unitString is null");
214 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Angle: empty unitString");
215 AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
216 if (unit != null)
217 {
218 return new Angle(value, unit);
219 }
220 throw new IllegalArgumentException("Error parsing Angle with unit " + unitString);
221 }
222
223
224
225
226
227
228 public final Dimensionless divide(final Angle v)
229 {
230 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
231 }
232
233
234
235
236
237
238 public final AngularVelocity times(final Frequency v)
239 {
240 return new AngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
241 }
242
243
244
245
246
247
248 public final AngularVelocity divide(final Duration v)
249 {
250 return new AngularVelocity(this.si / v.si, AngularVelocityUnit.SI);
251 }
252
253
254
255
256
257
258 public final Duration divide(final AngularVelocity v)
259 {
260 return new Duration(this.si / v.si, DurationUnit.SI);
261 }
262
263
264 @Override
265 public SIScalar reciprocal()
266 {
267 return DoubleScalar.divide(Dimensionless.ONE, this);
268 }
269
270 }