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