1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.regex.Matcher;
4
5 import org.djunits.unit.AngleUnit;
6 import org.djunits.unit.DimensionlessUnit;
7 import org.djunits.unit.DirectionUnit;
8 import org.djunits.unit.Unit;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class FloatAngle extends AbstractFloatScalarRel<AngleUnit, FloatAngle>
36 {
37
38 private static final long serialVersionUID = 20150901L;
39
40
41 public static final FloatAngle ZERO = new FloatAngle(0.0f, AngleUnit.SI);
42
43
44 @SuppressWarnings("checkstyle:constantname")
45 public static final FloatAngle NaN = new FloatAngle(Float.NaN, AngleUnit.SI);
46
47
48 public static final FloatAngle POSITIVE_INFINITY = new FloatAngle(Float.POSITIVE_INFINITY, AngleUnit.SI);
49
50
51 public static final FloatAngle NEGATIVE_INFINITY = new FloatAngle(Float.NEGATIVE_INFINITY, AngleUnit.SI);
52
53
54 public static final FloatAngle POS_MAXVALUE = new FloatAngle(Float.MAX_VALUE, AngleUnit.SI);
55
56
57 public static final FloatAngle NEG_MAXVALUE = new FloatAngle(-Float.MAX_VALUE, AngleUnit.SI);
58
59
60
61
62
63
64 public FloatAngle(final float value, final AngleUnit unit)
65 {
66 super(value, unit);
67 }
68
69
70
71
72
73 public FloatAngle(final FloatAngle value)
74 {
75 super(value);
76 }
77
78
79
80
81
82
83 public FloatAngle(final double value, final AngleUnit unit)
84 {
85 super((float) value, unit);
86 }
87
88
89 @Override
90 public final FloatAngle instantiateRel(final float value, final AngleUnit unit)
91 {
92 return new FloatAngle(value, unit);
93 }
94
95
96
97
98
99
100 public static final FloatAngle createSI(final float value)
101 {
102 return new FloatAngle(value, AngleUnit.SI);
103 }
104
105
106
107
108
109
110
111 public final FloatDirection instantiateAbs(final float value, final DirectionUnit unit)
112 {
113 return new FloatDirection(value, unit);
114 }
115
116
117
118
119
120
121
122
123 public static FloatAngle interpolate(final FloatAngle zero, final FloatAngle one, final float ratio)
124 {
125 return new FloatAngle(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
126 }
127
128
129
130
131
132
133 public final FloatDirection plus(final FloatDirection v)
134 {
135 DirectionUnit targetUnit = v.getUnit();
136 return instantiateAbs(v.getInUnit() + getInUnit(targetUnit.getRelativeUnit()), targetUnit);
137 }
138
139
140
141
142
143
144
145 public static FloatAngle max(final FloatAngle r1, final FloatAngle r2)
146 {
147 return (r1.gt(r2)) ? r1 : r2;
148 }
149
150
151
152
153
154
155
156
157 public static FloatAngle max(final FloatAngle r1, final FloatAngle r2, final FloatAngle... rn)
158 {
159 FloatAngle maxr = (r1.gt(r2)) ? r1 : r2;
160 for (FloatAngle r : rn)
161 {
162 if (r.gt(maxr))
163 {
164 maxr = r;
165 }
166 }
167 return maxr;
168 }
169
170
171
172
173
174
175
176 public static FloatAngle min(final FloatAngle r1, final FloatAngle r2)
177 {
178 return (r1.lt(r2)) ? r1 : r2;
179 }
180
181
182
183
184
185
186
187
188 public static FloatAngle min(final FloatAngle r1, final FloatAngle r2, final FloatAngle... rn)
189 {
190 FloatAngle minr = (r1.lt(r2)) ? r1 : r2;
191 for (FloatAngle r : rn)
192 {
193 if (r.lt(minr))
194 {
195 minr = r;
196 }
197 }
198 return minr;
199 }
200
201
202
203
204
205
206
207
208
209 public static FloatAngle valueOf(final String text) throws IllegalArgumentException
210 {
211 if (text == null || text.length() == 0)
212 {
213 throw new IllegalArgumentException("Error parsing FloatAngle -- null or empty argument");
214 }
215 Matcher matcher = NUMBER_PATTERN.matcher(text);
216 if (matcher.find())
217 {
218 int index = matcher.end();
219 try
220 {
221 String unitString = text.substring(index).trim();
222 String valueString = text.substring(0, index).trim();
223 for (AngleUnit unit : Unit.getUnits(AngleUnit.class))
224 {
225 if (unit.getDefaultLocaleTextualRepresentations().contains(unitString))
226 {
227 float f = Float.parseFloat(valueString);
228 return new FloatAngle(f, unit);
229 }
230 }
231 }
232 catch (Exception exception)
233 {
234 throw new IllegalArgumentException("Error parsing FloatAngle from " + text, exception);
235 }
236 }
237 throw new IllegalArgumentException("Error parsing FloatAngle from " + text);
238 }
239
240
241
242
243
244
245 public final FloatDimensionless divideBy(final FloatAngle v)
246 {
247 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
248 }
249
250 }