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.AbstractFloatScalarRelWithAbs;
11 import org.djunits.value.vfloat.scalar.base.FloatScalar;
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 FloatAngle extends AbstractFloatScalarRelWithAbs<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 @SuppressWarnings("checkstyle:constantname")
41 public static final FloatAngle NaN = new FloatAngle(Float.NaN, AngleUnit.SI);
42
43
44 public static final FloatAngle POSITIVE_INFINITY = new FloatAngle(Float.POSITIVE_INFINITY, AngleUnit.SI);
45
46
47 public static final FloatAngle NEGATIVE_INFINITY = new FloatAngle(Float.NEGATIVE_INFINITY, AngleUnit.SI);
48
49
50 public static final FloatAngle POS_MAXVALUE = new FloatAngle(Float.MAX_VALUE, AngleUnit.SI);
51
52
53 public static final FloatAngle NEG_MAXVALUE = new FloatAngle(-Float.MAX_VALUE, AngleUnit.SI);
54
55
56
57
58
59
60 public FloatAngle(final float value, final AngleUnit unit)
61 {
62 super(value, unit);
63 }
64
65
66
67
68
69 public FloatAngle(final FloatAngle value)
70 {
71 super(value);
72 }
73
74
75
76
77
78
79 public FloatAngle(final double value, final AngleUnit unit)
80 {
81 super((float) value, unit);
82 }
83
84
85 @Override
86 public final FloatAngle instantiateRel(final float value, final AngleUnit unit)
87 {
88 return new FloatAngle(value, unit);
89 }
90
91
92
93
94
95
96 public static final FloatAngle instantiateSI(final float value)
97 {
98 return new FloatAngle(value, AngleUnit.SI);
99 }
100
101
102 @Override
103 public final FloatDirection instantiateAbs(final float value, final DirectionUnit unit)
104 {
105 return new FloatDirection(value, unit);
106 }
107
108
109
110
111
112
113
114
115 public static FloatAngle interpolate(final FloatAngle zero, final FloatAngle one, final float ratio)
116 {
117 return new FloatAngle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
118 zero.getDisplayUnit());
119 }
120
121
122
123
124
125
126
127 public static FloatAngle max(final FloatAngle r1, final FloatAngle r2)
128 {
129 return r1.gt(r2) ? r1 : r2;
130 }
131
132
133
134
135
136
137
138
139 public static FloatAngle max(final FloatAngle r1, final FloatAngle r2, final FloatAngle... rn)
140 {
141 FloatAngle maxr = r1.gt(r2) ? r1 : r2;
142 for (FloatAngle r : rn)
143 {
144 if (r.gt(maxr))
145 {
146 maxr = r;
147 }
148 }
149 return maxr;
150 }
151
152
153
154
155
156
157
158 public static FloatAngle min(final FloatAngle r1, final FloatAngle r2)
159 {
160 return r1.lt(r2) ? r1 : r2;
161 }
162
163
164
165
166
167
168
169
170 public static FloatAngle min(final FloatAngle r1, final FloatAngle r2, final FloatAngle... rn)
171 {
172 FloatAngle minr = r1.lt(r2) ? r1 : r2;
173 for (FloatAngle r : rn)
174 {
175 if (r.lt(minr))
176 {
177 minr = r;
178 }
179 }
180 return minr;
181 }
182
183
184
185
186
187
188
189
190
191
192 public static FloatAngle valueOf(final String text)
193 {
194 Throw.whenNull(text, "Error parsing FloatAngle: text to parse is null");
195 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatAngle: empty text to parse");
196 try
197 {
198 NumberParser numberParser = new NumberParser().lenient().trailing();
199 float f = numberParser.parseFloat(text);
200 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
201 AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
202 if (unit == null)
203 throw new IllegalArgumentException("Unit " + unitString + " not found");
204 return new FloatAngle(f, unit);
205 }
206 catch (Exception exception)
207 {
208 throw new IllegalArgumentException(
209 "Error parsing FloatAngle from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
210 exception);
211 }
212 }
213
214
215
216
217
218
219
220
221
222 public static FloatAngle of(final float value, final String unitString)
223 {
224 Throw.whenNull(unitString, "Error parsing FloatAngle: unitString is null");
225 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatAngle: empty unitString");
226 AngleUnit unit = AngleUnit.BASE.getUnitByAbbreviation(unitString);
227 if (unit != null)
228 {
229 return new FloatAngle(value, unit);
230 }
231 throw new IllegalArgumentException("Error parsing FloatAngle with unit " + unitString);
232 }
233
234
235
236
237
238
239 public final FloatDimensionless divide(final FloatAngle v)
240 {
241 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
242 }
243
244
245
246
247
248
249 public final FloatAngularVelocity times(final FloatFrequency v)
250 {
251 return new FloatAngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
252 }
253
254
255
256
257
258
259 public final FloatAngularVelocity divide(final FloatDuration v)
260 {
261 return new FloatAngularVelocity(this.si / v.si, AngularVelocityUnit.SI);
262 }
263
264
265
266
267
268
269 public final FloatDuration divide(final FloatAngularVelocity v)
270 {
271 return new FloatDuration(this.si / v.si, DurationUnit.SI);
272 }
273
274
275 @Override
276 public FloatSIScalar reciprocal()
277 {
278 return FloatScalar.divide(FloatDimensionless.ONE, this);
279 }
280
281 }