1 package org.djunits.unit.scale; 2 3 /** 4 * A Scale for linear transformations not involving a zero-offset, e.g. for Length, Time, Area. <br> 5 * A linear scale is a scale that is linearly relates a unit to the underlying SI standard unit. E.g. Mile is linearly related 6 * to meter (the SI unit for length) and the conversion is zero-based (0 miles equals 0 meter). Unlike temperature in degrees 7 * Celsius which is <strong>not</strong> linearly related to the Kelvin (the SI unit for temperature) because the conversion is 8 * not zero-based (0°C is 273.15K). 9 * <p> 10 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 11 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 12 * </p> 13 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, 14 * initial version Oct 11, 2015 <br> 15 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 16 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 17 */ 18 public class LinearScale implements Scale 19 { 20 /** multiply by this number to convert to the standard (e.g., SI) unit. */ 21 private final double conversionFactorToStandardUnit; 22 23 /** 24 * Construct a Scale for linear transformations. 25 * @param conversionFactorToStandardUnit the conversion factor by which this number has to be multiplied to convert it to 26 * the standard (e.g., SI) unit. 27 */ 28 public LinearScale(final double conversionFactorToStandardUnit) 29 { 30 super(); 31 this.conversionFactorToStandardUnit = conversionFactorToStandardUnit; 32 } 33 34 /** {@inheritDoc} */ 35 @SuppressWarnings("checkstyle:designforextension") 36 @Override 37 public double toStandardUnit(final double value) 38 { 39 return value * this.conversionFactorToStandardUnit; 40 } 41 42 /** {@inheritDoc} */ 43 @SuppressWarnings("checkstyle:designforextension") 44 @Override 45 public double fromStandardUnit(final double value) 46 { 47 return value / this.conversionFactorToStandardUnit; 48 } 49 50 /** 51 * @return conversionFactorToStandardUnit 52 */ 53 public final double getConversionFactorToStandardUnit() 54 { 55 return this.conversionFactorToStandardUnit; 56 } 57 58 /** {@inheritDoc} */ 59 @Override 60 @SuppressWarnings("checkstyle:designforextension") 61 public boolean isBaseSIScale() 62 { 63 return this.conversionFactorToStandardUnit == 1.0; 64 } 65 66 }