1 package org.djunits.value.vfloat.scalar;
2
3 import org.djunits.unit.AccelerationUnit;
4 import org.djunits.unit.DimensionlessUnit;
5 import org.djunits.unit.DurationUnit;
6 import org.djunits.unit.FlowVolumeUnit;
7 import org.djunits.unit.ForceUnit;
8 import org.djunits.unit.FrequencyUnit;
9 import org.djunits.unit.LengthUnit;
10 import org.djunits.unit.PowerUnit;
11 import org.djunits.unit.SpeedUnit;
12
13 /**
14 * Easy access methods for the Speed FloatScalar, which is relative by definition. An example is Speed. Instead of:
15 *
16 * <pre>
17 * FloatScalar.Rel<SpeedUnit> value = new FloatScalar.Rel<SpeedUnit>(100.0, SpeedUnit.SI);
18 * </pre>
19 *
20 * we can now write:
21 *
22 * <pre>
23 * FloatSpeed value = new FloatSpeed(100.0, SpeedUnit.SI);
24 * </pre>
25 *
26 * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
27 * used are compatible.
28 * <p>
29 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
30 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
31 * <p>
32 * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
33 * initial version Sep 5, 2015 <br>
34 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
35 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
36 */
37 public class FloatSpeed extends AbstractFloatScalarRel<SpeedUnit, FloatSpeed>
38 {
39 /** */
40 private static final long serialVersionUID = 20150901L;
41
42 /** constant with value zero. */
43 public static final FloatSpeed ZERO = new FloatSpeed(0.0f, SpeedUnit.SI);
44
45 /** constant with value NaN. */
46 @SuppressWarnings("checkstyle:constantname")
47 public static final FloatSpeed NaN = new FloatSpeed(Float.NaN, SpeedUnit.SI);
48
49 /** constant with value POSITIVE_INFINITY. */
50 public static final FloatSpeed POSITIVE_INFINITY = new FloatSpeed(Float.POSITIVE_INFINITY, SpeedUnit.SI);
51
52 /** constant with value NEGATIVE_INFINITY. */
53 public static final FloatSpeed NEGATIVE_INFINITY = new FloatSpeed(Float.NEGATIVE_INFINITY, SpeedUnit.SI);
54
55 /** constant with value MAX_VALUE. */
56 public static final FloatSpeed POS_MAXVALUE = new FloatSpeed(Float.MAX_VALUE, SpeedUnit.SI);
57
58 /** constant with value -MAX_VALUE. */
59 public static final FloatSpeed NEG_MAXVALUE = new FloatSpeed(-Float.MAX_VALUE, SpeedUnit.SI);
60
61 /**
62 * Construct FloatSpeed scalar.
63 * @param value float value
64 * @param unit unit for the float value
65 */
66 public FloatSpeed(final float value, final SpeedUnit unit)
67 {
68 super(value, unit);
69 }
70
71 /**
72 * Construct FloatSpeed scalar.
73 * @param value Scalar from which to construct this instance
74 */
75 public FloatSpeed(final FloatSpeed value)
76 {
77 super(value);
78 }
79
80 /**
81 * Construct FloatSpeed scalar using a double value.
82 * @param value double value
83 * @param unit unit for the resulting float value
84 */
85 public FloatSpeed(final double value, final SpeedUnit unit)
86 {
87 super((float) value, unit);
88 }
89
90 /** {@inheritDoc} */
91 @Override
92 public final FloatSpeed instantiateRel(final float value, final SpeedUnit unit)
93 {
94 return new FloatSpeed(value, unit);
95 }
96
97 /**
98 * Construct FloatSpeed scalar.
99 * @param value float value in SI units
100 * @return the new scalar with the SI value
101 */
102 public static final FloatSpeed createSI(final float value)
103 {
104 return new FloatSpeed(value, SpeedUnit.SI);
105 }
106
107 /**
108 * Interpolate between two values.
109 * @param zero the low value
110 * @param one the high value
111 * @param ratio the ratio between 0 and 1, inclusive
112 * @return a Scalar at the ratio between
113 */
114 public static FloatSpeed interpolate(final FloatSpeed zero, final FloatSpeed one, final float ratio)
115 {
116 return new FloatSpeed(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
117 }
118
119 /**
120 * Return the maximum value of two relative scalars.
121 * @param r1 the first scalar
122 * @param r2 the second scalar
123 * @return the maximum value of two relative scalars
124 */
125 public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2)
126 {
127 return (r1.gt(r2)) ? r1 : r2;
128 }
129
130 /**
131 * Return the maximum value of more than two relative scalars.
132 * @param r1 the first scalar
133 * @param r2 the second scalar
134 * @param rn the other scalars
135 * @return the maximum value of more than two relative scalars
136 */
137 public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
138 {
139 FloatSpeed maxr = (r1.gt(r2)) ? r1 : r2;
140 for (FloatSpeed r : rn)
141 {
142 if (r.gt(maxr))
143 {
144 maxr = r;
145 }
146 }
147 return maxr;
148 }
149
150 /**
151 * Return the minimum value of two relative scalars.
152 * @param r1 the first scalar
153 * @param r2 the second scalar
154 * @return the minimum value of two relative scalars
155 */
156 public static FloatSpeed min(final FloatSpeed r1, final FloatSpeed r2)
157 {
158 return (r1.lt(r2)) ? r1 : r2;
159 }
160
161 /**
162 * Return the minimum value of more than two relative scalars.
163 * @param r1 the first scalar
164 * @param r2 the second scalar
165 * @param rn the other scalars
166 * @return the minimum value of more than two relative scalars
167 */
168 public static FloatSpeed min(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
169 {
170 FloatSpeed minr = (r1.lt(r2)) ? r1 : r2;
171 for (FloatSpeed r : rn)
172 {
173 if (r.lt(minr))
174 {
175 minr = r;
176 }
177 }
178 return minr;
179 }
180
181 /**
182 * Calculate the division of FloatSpeed and FloatSpeed, which results in a FloatDimensionless scalar.
183 * @param v FloatSpeed scalar
184 * @return FloatDimensionless scalar as a division of FloatSpeed and FloatSpeed
185 */
186 public final FloatDimensionless divideBy(final FloatSpeed v)
187 {
188 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
189 }
190
191 /**
192 * Calculate the multiplication of FloatSpeed and FloatArea, which results in a FloatFlowVolume scalar.
193 * @param v FloatSpeed scalar
194 * @return FloatFlowVolume scalar as a multiplication of FloatSpeed and FloatArea
195 */
196 public final FloatFlowVolume multiplyBy(final FloatArea v)
197 {
198 return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
199 }
200
201 /**
202 * Calculate the multiplication of FloatSpeed and FloatForce, which results in a FloatPower scalar.
203 * @param v FloatSpeed scalar
204 * @return FloatPower scalar as a multiplication of FloatSpeed and FloatForce
205 */
206 public final FloatPower multiplyBy(final FloatForce v)
207 {
208 return new FloatPower(this.si * v.si, PowerUnit.SI);
209 }
210
211 /**
212 * Calculate the multiplication of FloatSpeed and FloatFrequency, which results in a FloatAcceleration scalar.
213 * @param v FloatSpeed scalar
214 * @return FloatAcceleration scalar as a multiplication of FloatSpeed and FloatFrequency
215 */
216 public final FloatAcceleration multiplyBy(final FloatFrequency v)
217 {
218 return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
219 }
220
221 /**
222 * Calculate the division of FloatSpeed and FloatLength, which results in a FloatFrequency scalar.
223 * @param v FloatSpeed scalar
224 * @return FloatFrequency scalar as a division of FloatSpeed and FloatLength
225 */
226 public final FloatFrequency divideBy(final FloatLength v)
227 {
228 return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
229 }
230
231 /**
232 * Calculate the division of FloatSpeed and FloatFrequency, which results in a FloatLength scalar.
233 * @param v FloatSpeed scalar
234 * @return FloatLength scalar as a division of FloatSpeed and FloatFrequency
235 */
236 public final FloatLength divideBy(final FloatFrequency v)
237 {
238 return new FloatLength(this.si / v.si, LengthUnit.SI);
239 }
240
241 /**
242 * Calculate the multiplication of FloatSpeed and FloatLinearDensity, which results in a FloatFrequency scalar.
243 * @param v FloatSpeed scalar
244 * @return FloatFrequency scalar as a multiplication of FloatSpeed and FloatLinearDensity
245 */
246 public final FloatFrequency multiplyBy(final FloatLinearDensity v)
247 {
248 return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
249 }
250
251 /**
252 * Calculate the multiplication of FloatSpeed and FloatDuration, which results in a FloatLength scalar.
253 * @param v FloatSpeed scalar
254 * @return FloatLength scalar as a multiplication of FloatSpeed and FloatDuration
255 */
256 public final FloatLength multiplyBy(final FloatDuration v)
257 {
258 return new FloatLength(this.si * v.si, LengthUnit.SI);
259 }
260
261 /**
262 * Calculate the division of FloatSpeed and FloatDuration, which results in a FloatAcceleration scalar.
263 * @param v FloatSpeed scalar
264 * @return FloatAcceleration scalar as a division of FloatSpeed and FloatDuration
265 */
266 public final FloatAcceleration divideBy(final FloatDuration v)
267 {
268 return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
269 }
270
271 /**
272 * Calculate the division of FloatSpeed and FloatAcceleration, which results in a FloatDuration scalar.
273 * @param v FloatSpeed scalar
274 * @return FloatDuration scalar as a division of FloatSpeed and FloatAcceleration
275 */
276 public final FloatDuration divideBy(final FloatAcceleration v)
277 {
278 return new FloatDuration(this.si / v.si, DurationUnit.SI);
279 }
280
281 /**
282 * Calculate the multiplication of FloatSpeed and FloatFlowMass, which results in a FloatForce scalar.
283 * @param v FloatSpeed scalar
284 * @return FloatForce scalar as a multiplication of FloatSpeed and FloatFlowMass
285 */
286 public final FloatForce multiplyBy(final FloatFlowMass v)
287 {
288 return new FloatForce(this.si * v.si, ForceUnit.SI);
289 }
290
291 }