Class DistanceUnit

java.lang.Object
edu.wpi.first.units.Unit
edu.wpi.first.units.DistanceUnit

public final class DistanceUnit extends Unit
Unit of linear dimension.

This is the base type for units of linear dimension. It is also used to specify the dimension for Measure: Measure<DistanceUnit>.

Actual units (such as Units.Meters and Units.Inches) can be found in the Units class.

  • Method Details

    • getBaseUnit

      Description copied from class: Unit
      Gets the base unit of measurement that this unit is derived from. If the unit is the base unit, the unit will be returned.

      NOTE: Subclasses must override this method to provide the correct return type. Failing to do say will make unit combinations that use it break at runtime!

      
         Unit baseUnit = new Unit(null, ...);
         baseUnit.getBaseUnit(); // returns baseUnit
      
         Unit derivedUnit = new Unit(baseUnit, ...);
         derivedUnit.getBaseUnit(); // returns baseUnit
       
      Overrides:
      getBaseUnit in class Unit
      Returns:
      the base unit
    • per

      public LinearVelocityUnit per(TimeUnit period)
      Description copied from class: Unit
      Combines this unit with a unit of time. This often - but not always - results in a velocity. Subclasses should sharpen the return type to be unit-specific.
      Specified by:
      per in class Unit
      Parameters:
      period - the unit of time
      Returns:
      the combined unit
    • per

      public <U extends Unit> PerUnit<DistanceUnit,U> per(U other)
      Creates a ratio unit between this unit and an arbitrary other unit.
      Type Parameters:
      U - the type of the other unit
      Parameters:
      other - the other unit
      Returns:
      the ratio unit
    • convertFrom

      public double convertFrom(double magnitude, DistanceUnit otherUnit)
      Converts a measurement value in terms of another distance unit to this unit.
      Parameters:
      magnitude - the magnitude of the measurement in terms of the other distance unit
      otherUnit - the other distance unit
      Returns:
      the value of the measurement in terms of this unit
    • of

      public Distance of(double magnitude)
      Description copied from class: Unit
      Creates a new immutable measurement of the given magnitude in terms of this unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.
      Specified by:
      of in class Unit
      Parameters:
      magnitude - the magnitude of the measurement.
      Returns:
      the measurement object
    • ofBaseUnits

      public Distance ofBaseUnits(double baseUnitMagnitude)
      Description copied from class: Unit
      Creates a new immutable measurement of the given magnitude in terms of this unit's base unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.
      Specified by:
      ofBaseUnits in class Unit
      Parameters:
      baseUnitMagnitude - the magnitude in terms of the base unit
      Returns:
      the measurement object
    • zero

      public Distance zero()
      Description copied from class: Unit
      Gets a measure of zero magnitude in terms of this unit. The returned object is guaranteed to be of the same type returned by Unit.of(double). Subclasses are encouraged to override this method to sharpen the return type.
      Overrides:
      zero in class Unit
      Returns:
      a zero-magnitude measure of this unit
    • one

      public Distance one()
      Description copied from class: Unit
      Gets a measure with a magnitude of 1.0 in terms of this unit. The returned object is guaranteed to be of the same type returned by Unit.of(double). Subclasses are encouraged to override this method to sharpen the return type.
      Overrides:
      one in class Unit
      Returns:
      a measure of magnitude 1.0 in terms of this unit
    • mutable

      public MutDistance mutable(double initialMagnitude)
      Description copied from class: Unit
      Creates a new mutable measurement that is initialized to the given magnitude in terms of this unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.
      Specified by:
      mutable in class Unit
      Parameters:
      initialMagnitude - the initial magnitude of the mutable measurement
      Returns:
      the mutable measurement object
    • multAsTorque

      Multiplies this distance unit by a unit of force to create a unit of torque.
      Parameters:
      force - the unit of force
      Returns:
      the combined torque unit