1 package org.djunits.value.vfloat.scalar;
2
3 import org.djunits.unit.AreaUnit;
4 import org.djunits.unit.DimensionlessUnit;
5 import org.djunits.unit.FlowVolumeUnit;
6 import org.djunits.unit.ForceUnit;
7 import org.djunits.unit.LengthUnit;
8 import org.djunits.unit.LinearDensityUnit;
9 import org.djunits.unit.MoneyUnit;
10 import org.djunits.unit.VolumeUnit;
11
12 /**
13 * Easy access methods for the Area FloatScalar, which is relative by definition. An example is Speed. Instead of:
14 *
15 * <pre>
16 * FloatScalar.Rel<AreaUnit> value = new FloatScalar.Rel<AreaUnit>(100.0, AreaUnit.SI);
17 * </pre>
18 *
19 * we can now write:
20 *
21 * <pre>
22 * FloatArea value = new FloatArea(100.0, AreaUnit.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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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 FloatArea extends AbstractFloatScalarRel<AreaUnit, FloatArea>
37 {
38 /** */
39 private static final long serialVersionUID = 20150901L;
40
41 /** constant with value zero. */
42 public static final FloatArea ZERO = new FloatArea(0.0f, AreaUnit.SI);
43
44 /** constant with value NaN. */
45 @SuppressWarnings("checkstyle:constantname")
46 public static final FloatArea NaN = new FloatArea(Float.NaN, AreaUnit.SI);
47
48 /** constant with value POSITIVE_INFINITY. */
49 public static final FloatArea POSITIVE_INFINITY = new FloatArea(Float.POSITIVE_INFINITY, AreaUnit.SI);
50
51 /** constant with value NEGATIVE_INFINITY. */
52 public static final FloatArea NEGATIVE_INFINITY = new FloatArea(Float.NEGATIVE_INFINITY, AreaUnit.SI);
53
54 /** constant with value MAX_VALUE. */
55 public static final FloatArea POS_MAXVALUE = new FloatArea(Float.MAX_VALUE, AreaUnit.SI);
56
57 /** constant with value -MAX_VALUE. */
58 public static final FloatArea NEG_MAXVALUE = new FloatArea(-Float.MAX_VALUE, AreaUnit.SI);
59
60 /**
61 * Construct FloatArea scalar.
62 * @param value float value
63 * @param unit unit for the float value
64 */
65 public FloatArea(final float value, final AreaUnit unit)
66 {
67 super(value, unit);
68 }
69
70 /**
71 * Construct FloatArea scalar.
72 * @param value Scalar from which to construct this instance
73 */
74 public FloatArea(final FloatArea value)
75 {
76 super(value);
77 }
78
79 /**
80 * Construct FloatArea scalar using a double value.
81 * @param value double value
82 * @param unit unit for the resulting float value
83 */
84 public FloatArea(final double value, final AreaUnit unit)
85 {
86 super((float) value, unit);
87 }
88
89 /** {@inheritDoc} */
90 @Override
91 public final FloatArea instantiateRel(final float value, final AreaUnit unit)
92 {
93 return new FloatArea(value, unit);
94 }
95
96 /**
97 * Construct FloatArea scalar.
98 * @param value float value in SI units
99 * @return the new scalar with the SI value
100 */
101 public static final FloatArea createSI(final float value)
102 {
103 return new FloatArea(value, AreaUnit.SI);
104 }
105
106 /**
107 * Interpolate between two values.
108 * @param zero the low value
109 * @param one the high value
110 * @param ratio the ratio between 0 and 1, inclusive
111 * @return a Scalar at the ratio between
112 */
113 public static FloatArea interpolate(final FloatArea zero, final FloatArea one, final float ratio)
114 {
115 return new FloatArea(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 the first scalar
121 * @param r2 the second scalar
122 * @return the maximum value of two relative scalars
123 */
124 public static FloatArea max(final FloatArea r1, final FloatArea 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 the first scalar
132 * @param r2 the second scalar
133 * @param rn the other scalars
134 * @return the maximum value of more than two relative scalars
135 */
136 public static FloatArea max(final FloatArea r1, final FloatArea r2, final FloatArea... rn)
137 {
138 FloatArea maxr = (r1.gt(r2)) ? r1 : r2;
139 for (FloatArea 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 the first scalar
152 * @param r2 the second scalar
153 * @return the minimum value of two relative scalars
154 */
155 public static FloatArea min(final FloatArea r1, final FloatArea 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 the first scalar
163 * @param r2 the second scalar
164 * @param rn the other scalars
165 * @return the minimum value of more than two relative scalars
166 */
167 public static FloatArea min(final FloatArea r1, final FloatArea r2, final FloatArea... rn)
168 {
169 FloatArea minr = (r1.lt(r2)) ? r1 : r2;
170 for (FloatArea 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 FloatArea and FloatArea, which results in a FloatDimensionless scalar.
182 * @param v FloatArea scalar
183 * @return FloatDimensionless scalar as a division of FloatArea and FloatArea
184 */
185 public final FloatDimensionless divideBy(final FloatArea v)
186 {
187 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
188 }
189
190 /**
191 * Calculate the multiplication of FloatArea and FloatLength, which results in a FloatVolume scalar.
192 * @param v FloatArea scalar
193 * @return FloatVolume scalar as a multiplication of FloatArea and FloatLength
194 */
195 public final FloatVolume multiplyBy(final FloatLength v)
196 {
197 return new FloatVolume(this.si * v.si, VolumeUnit.SI);
198 }
199
200 /**
201 * Calculate the division of FloatArea and FloatLinearDensity, which results in a FloatVolume scalar.
202 * @param v FloatArea scalar
203 * @return FloatVolume scalar as a division of FloatArea and FloatLinearDensity
204 */
205 public final FloatVolume divideBy(final FloatLinearDensity v)
206 {
207 return new FloatVolume(this.si / v.si, VolumeUnit.SI);
208 }
209
210 /**
211 * Calculate the division of FloatArea and FloatVolume, which results in a FloatLinearDensity scalar.
212 * @param v FloatArea scalar
213 * @return FloatLinearDensity scalar as a division of FloatArea and FloatVolume
214 */
215 public final FloatLinearDensity divideBy(final FloatVolume v)
216 {
217 return new FloatLinearDensity(this.si / v.si, LinearDensityUnit.SI);
218 }
219
220 /**
221 * Calculate the division of FloatArea and FloatLength, which results in a FloatLength scalar.
222 * @param v FloatArea scalar
223 * @return FloatLength scalar as a division of FloatArea and FloatLength
224 */
225 public final FloatLength divideBy(final FloatLength v)
226 {
227 return new FloatLength(this.si / v.si, LengthUnit.SI);
228 }
229
230 /**
231 * Calculate the multiplication of FloatArea and FloatLinearDensity, which results in a FloatLength scalar.
232 * @param v FloatArea scalar
233 * @return FloatLength scalar as a multiplication of FloatArea and FloatLinearDensity
234 */
235 public final FloatLength multiplyBy(final FloatLinearDensity v)
236 {
237 return new FloatLength(this.si * v.si, LengthUnit.SI);
238 }
239
240 /**
241 * Calculate the multiplication of FloatArea and FloatSpeed, which results in a FloatFlowVolume scalar.
242 * @param v FloatArea scalar
243 * @return FloatFlowVolume scalar as a multiplication of FloatArea and FloatSpeed
244 */
245 public final FloatFlowVolume multiplyBy(final FloatSpeed v)
246 {
247 return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
248 }
249
250 /**
251 * Calculate the multiplication of FloatArea and FloatPressure, which results in a FloatForce scalar.
252 * @param v FloatArea scalar
253 * @return FloatForce scalar as a multiplication of FloatArea and FloatPressure
254 */
255 public final FloatForce multiplyBy(final FloatPressure v)
256 {
257 return new FloatForce(this.si * v.si, ForceUnit.SI);
258 }
259
260 /**
261 * Calculate the multiplication of FloatArea and FloatMoneyPerArea, which results in a FloatMoney scalar.
262 * @param v FloatArea scalar
263 * @return FloatMoney scalar as a multiplication of FloatArea and FloatMoneyPerArea
264 */
265 public final FloatMoney multiplyBy(final FloatMoneyPerArea v)
266 {
267 return new FloatMoney(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
268 }
269
270 }