// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package edu.wpi.first.units; /** * A measure holds the magnitude and unit of some dimension, such as distance, time, or speed. Two * measures with the same unit and magnitude are effectively the same object. * * @param the unit type of the measure */ public interface Measure> extends Comparable> { /** * The threshold for two measures to be considered equivalent if converted to the same unit. This * is only needed due to floating-point error. */ double EQUIVALENCE_THRESHOLD = 1e-12; /** Gets the unitless magnitude of this measure. */ double magnitude(); /** Gets the magnitude of this measure in terms of the base unit. */ double baseUnitMagnitude(); /** Gets the units of this measure. */ U unit(); /** * Converts this measure to a measure with a different unit of the same type, eg minutes to * seconds. Converting to the same unit is equivalent to calling {@link #magnitude()}. * *
   *   Meters.of(12).in(Feet) // => 39.3701
   *   Seconds.of(15).in(Minutes) // => 0.25
   * 
* * @param unit the unit to convert this measure to * @return the value of this measure in the given unit */ default double in(Unit unit) { if (this.unit().equals(unit)) { return magnitude(); } else { return unit.fromBaseUnits(baseUnitMagnitude()); } } /** * Multiplies this measurement by some constant multiplier and returns the result. * * @param multiplier the constant to multiply by */ default Measure times(double multiplier) { return ImmutableMeasure.ofBaseUnits(baseUnitMagnitude() * multiplier, unit()); } /** * Generates a new measure that is equal to this measure multiplied by another. Some dimensional * analysis is performed to reduce the units down somewhat; for example, multiplying a {@code * Measure