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