1 package org.djunits.value.vdouble.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 DoubleScalar, which is relative by definition. Instead of:
14 *
15 * <pre>
16 * DoubleScalar.Rel<AreaUnit> value = new DoubleScalar.Rel<AreaUnit>(100.0, AreaUnit.SI);
17 * </pre>
18 *
19 * we can now write:
20 *
21 * <pre>
22 * Area value = new Area(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 Area extends AbstractDoubleScalarRel<AreaUnit, Area>
37 {
38 /** */
39 private static final long serialVersionUID = 20150905L;
40
41 /** constant with value zero. */
42 public static final Area ZERO = new Area(0.0, AreaUnit.SI);
43
44 /** constant with value NaN. */
45 @SuppressWarnings("checkstyle:constantname")
46 public static final Area NaN = new Area(Double.NaN, AreaUnit.SI);
47
48 /** constant with value POSITIVE_INFINITY. */
49 public static final Area POSITIVE_INFINITY = new Area(Double.POSITIVE_INFINITY, AreaUnit.SI);
50
51 /** constant with value NEGATIVE_INFINITY. */
52 public static final Area NEGATIVE_INFINITY = new Area(Double.NEGATIVE_INFINITY, AreaUnit.SI);
53
54 /** constant with value MAX_VALUE. */
55 public static final Area POS_MAXVALUE = new Area(Double.MAX_VALUE, AreaUnit.SI);
56
57 /** constant with value -MAX_VALUE. */
58 public static final Area NEG_MAXVALUE = new Area(-Double.MAX_VALUE, AreaUnit.SI);
59
60 /**
61 * Construct Area scalar.
62 * @param value double value
63 * @param unit unit for the double value
64 */
65 public Area(final double value, final AreaUnit unit)
66 {
67 super(value, unit);
68 }
69
70 /**
71 * Construct Area scalar.
72 * @param value Scalar from which to construct this instance
73 */
74 public Area(final Area value)
75 {
76 super(value);
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public final Area instantiateRel(final double value, final AreaUnit unit)
82 {
83 return new Area(value, unit);
84 }
85
86 /**
87 * Construct Area scalar.
88 * @param value double value in SI units
89 * @return the new scalar with the SI value
90 */
91 public static final Area createSI(final double value)
92 {
93 return new Area(value, AreaUnit.SI);
94 }
95
96 /**
97 * Interpolate between two values.
98 * @param zero the low value
99 * @param one the high value
100 * @param ratio the ratio between 0 and 1, inclusive
101 * @return a Scalar at the ratio between
102 */
103 public static Area interpolate(final Area zero, final Area one, final double ratio)
104 {
105 return new Area(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
106 }
107
108 /**
109 * Return the maximum value of two relative scalars.
110 * @param r1 the first scalar
111 * @param r2 the second scalar
112 * @return the maximum value of two relative scalars
113 */
114 public static Area max(final Area r1, final Area r2)
115 {
116 return (r1.gt(r2)) ? r1 : r2;
117 }
118
119 /**
120 * Return the maximum value of more than two relative scalars.
121 * @param r1 the first scalar
122 * @param r2 the second scalar
123 * @param rn the other scalars
124 * @return the maximum value of more than two relative scalars
125 */
126 public static Area max(final Area r1, final Area r2, final Area... rn)
127 {
128 Area maxr = (r1.gt(r2)) ? r1 : r2;
129 for (Area r : rn)
130 {
131 if (r.gt(maxr))
132 {
133 maxr = r;
134 }
135 }
136 return maxr;
137 }
138
139 /**
140 * Return the minimum value of two relative scalars.
141 * @param r1 the first scalar
142 * @param r2 the second scalar
143 * @return the minimum value of two relative scalars
144 */
145 public static Area min(final Area r1, final Area r2)
146 {
147 return (r1.lt(r2)) ? r1 : r2;
148 }
149
150 /**
151 * Return the minimum value of more than two relative scalars.
152 * @param r1 the first scalar
153 * @param r2 the second scalar
154 * @param rn the other scalars
155 * @return the minimum value of more than two relative scalars
156 */
157 public static Area min(final Area r1, final Area r2, final Area... rn)
158 {
159 Area minr = (r1.lt(r2)) ? r1 : r2;
160 for (Area r : rn)
161 {
162 if (r.lt(minr))
163 {
164 minr = r;
165 }
166 }
167 return minr;
168 }
169
170 /**
171 * Calculate the division of Area and Area, which results in a Dimensionless scalar.
172 * @param v Area scalar
173 * @return Dimensionless scalar as a division of Area and Area
174 */
175 public final Dimensionless divideBy(final Area v)
176 {
177 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
178 }
179
180 /**
181 * Calculate the multiplication of Area and Length, which results in a Volume scalar.
182 * @param v Area scalar
183 * @return Volume scalar as a multiplication of Area and Length
184 */
185 public final Volume multiplyBy(final Length v)
186 {
187 return new Volume(this.si * v.si, VolumeUnit.SI);
188 }
189
190 /**
191 * Calculate the division of Area and LinearDensity, which results in a Volume scalar.
192 * @param v Area scalar
193 * @return Volume scalar as a division of Area and LinearDensity
194 */
195 public final Volume divideBy(final LinearDensity v)
196 {
197 return new Volume(this.si / v.si, VolumeUnit.SI);
198 }
199
200 /**
201 * Calculate the division of Area and Volume, which results in a LinearDensity scalar.
202 * @param v Area scalar
203 * @return LinearDensity scalar as a division of Area and Volume
204 */
205 public final LinearDensity divideBy(final Volume v)
206 {
207 return new LinearDensity(this.si / v.si, LinearDensityUnit.SI);
208 }
209
210 /**
211 * Calculate the division of Area and Length, which results in a Length scalar.
212 * @param v Area scalar
213 * @return Length scalar as a division of Area and Length
214 */
215 public final Length divideBy(final Length v)
216 {
217 return new Length(this.si / v.si, LengthUnit.SI);
218 }
219
220 /**
221 * Calculate the multiplication of Area and LinearDensity, which results in a Length scalar.
222 * @param v Area scalar
223 * @return Length scalar as a multiplication of Area and LinearDensity
224 */
225 public final Length multiplyBy(final LinearDensity v)
226 {
227 return new Length(this.si * v.si, LengthUnit.SI);
228 }
229
230 /**
231 * Calculate the multiplication of Area and Speed, which results in a FlowVolume scalar.
232 * @param v Area scalar
233 * @return FlowVolume scalar as a multiplication of Area and Speed
234 */
235 public final FlowVolume multiplyBy(final Speed v)
236 {
237 return new FlowVolume(this.si * v.si, FlowVolumeUnit.SI);
238 }
239
240 /**
241 * Calculate the multiplication of Area and Pressure, which results in a Force scalar.
242 * @param v Area scalar
243 * @return Force scalar as a multiplication of Area and Pressure
244 */
245 public final Force multiplyBy(final Pressure v)
246 {
247 return new Force(this.si * v.si, ForceUnit.SI);
248 }
249
250 /**
251 * Calculate the multiplication of Area and MoneyPerArea, which results in a Money scalar.
252 * @param v Area scalar
253 * @return Money scalar as a multiplication of Area and MoneyPerArea
254 */
255 public final Money multiplyBy(final MoneyPerArea v)
256 {
257 return new Money(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
258 }
259
260 }