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