1 package org.djunits.value.vdouble.scalar; 2 3 import org.djunits.unit.AngleUnit; 4 import org.djunits.unit.DirectionUnit; 5 6 /** 7 * Easy access methods for the Absolute Direction DoubleScalar. Instead of: 8 * 9 * <pre> 10 * DoubleScalar.Abs<DirectionUnit> value = new DoubleScalar.Abs<DirectionUnit>(100.0, DirectionUnit.SI); 11 * </pre> 12 * 13 * we can now write: 14 * 15 * <pre> 16 * Direction value = new Direction(100.0, DirectionUnit.BASE); 17 * </pre> 18 * 19 * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit 20 * used are compatible. 21 * <p> 22 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br> 23 * All rights reserved. <br> 24 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 25 * <p> 26 * $LastChangedDate: 2015-12-22 04:32:39 +0100 (Tue, 22 Dec 2015) $, @version $Revision: 180 $, by $Author: averbraeck $, 27 * initial version Sep 1, 2015 <br> 28 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 29 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 30 */ 31 public class Direction extends AbstractDoubleScalarAbs<DirectionUnit, Direction, AngleUnit, Angle> 32 { 33 /** */ 34 private static final long serialVersionUID = 20150901L; 35 36 /** constant with value zero. */ 37 public static final Direction ZERO = new Direction(0.0, DirectionUnit.BASE); 38 39 /** 40 * Construct Direction scalar. 41 * @param value double value 42 * @param unit unit for the double value 43 */ 44 public Direction(final double value, final DirectionUnit unit) 45 { 46 super(value, unit); 47 } 48 49 /** 50 * Construct Direction scalar. 51 * @param value Scalar from which to construct this instance 52 */ 53 public Direction(final Direction value) 54 { 55 super(value); 56 } 57 58 /** {@inheritDoc} */ 59 @Override 60 public final Direction instantiateAbs(final double value, final DirectionUnit unit) 61 { 62 return new Direction(value, unit); 63 } 64 65 /** {@inheritDoc} */ 66 @Override 67 public final Angle instantiateRel(final double value, final AngleUnit unit) 68 { 69 return new Angle(value, unit); 70 } 71 72 /** 73 * Construct %TypeAbsl% scalar. 74 * @param value double value in SI units 75 * @return the new scalar with the SI value 76 */ 77 public static final Direction createSI(final double value) 78 { 79 return new Direction(value, DirectionUnit.BASE); 80 } 81 82 /** 83 * Interpolate between two values. 84 * @param zero the low value 85 * @param one the high value 86 * @param ratio the ratio between 0 and 1, inclusive 87 * @return a Scalar at the ratio between 88 */ 89 public static Direction interpolate(final Direction zero, final Direction one, final double ratio) 90 { 91 return new Direction(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit()); 92 } 93 94 /** 95 * Return the maximum value of two absolute scalars. 96 * @param a1 the first scalar 97 * @param a2 the second scalar 98 * @return the maximum value of two absolute scalars 99 */ 100 public static Direction max(final Direction a1, final Direction a2) 101 { 102 return (a1.gt(a2)) ? a1 : a2; 103 } 104 105 /** 106 * Return the maximum value of more than two absolute scalars. 107 * @param a1 the first scalar 108 * @param a2 the second scalar 109 * @param an the other scalars 110 * @return the maximum value of more than two absolute scalars 111 */ 112 public static Direction max(final Direction a1, final Direction a2, final Direction... an) 113 { 114 Direction maxa = (a1.gt(a2)) ? a1 : a2; 115 for (Direction a : an) 116 { 117 if (a.gt(maxa)) 118 { 119 maxa = a; 120 } 121 } 122 return maxa; 123 } 124 125 /** 126 * Return the minimum value of two absolute scalars. 127 * @param a1 the first scalar 128 * @param a2 the second scalar 129 * @return the minimum value of two absolute scalars 130 */ 131 public static Direction min(final Direction a1, final Direction a2) 132 { 133 return (a1.lt(a2)) ? a1 : a2; 134 } 135 136 /** 137 * Return the minimum value of more than two absolute scalars. 138 * @param a1 the first scalar 139 * @param a2 the second scalar 140 * @param an the other scalars 141 * @return the minimum value of more than two absolute scalars 142 */ 143 public static Direction min(final Direction a1, final Direction a2, final Direction... an) 144 { 145 Direction mina = (a1.lt(a2)) ? a1 : a2; 146 for (Direction a : an) 147 { 148 if (a.lt(mina)) 149 { 150 mina = a; 151 } 152 } 153 return mina; 154 } 155 156 }