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