Class Position

All Implemented Interfaces:
Serializable, Comparable<Position>, Value<Position,Length>

public class Position extends AbsQuantity<Position,Length,Position.Reference>
Position is the absolute equivalent of Length, and can, e.g., represent an absolute offset relative to a defined origin.

Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.

Author:
Alexander Verbraeck
See Also:
  • Constructor Details

    • Position

      public Position(double valueInUnit, Length.Unit unit, Position.Reference reference)
      Instantiate a Position quantity with a unit and a reference point.
      Parameters:
      valueInUnit - the length value, expressed in a length unit
      unit - the length unit in which the value is expressed, relative to the reference point
      reference - the reference point of this position
    • Position

      public Position(double valueInUnit, String abbreviation, Position.Reference reference)
      Instantiate a Position quantity with a unit, expressed as a String, and a reference point.
      Parameters:
      valueInUnit - the length value, expressed in the unit, relative to the reference point
      abbreviation - the String abbreviation of the unit in which the value is expressed
      reference - the reference point of this position
    • Position

      public Position(Length length, Position.Reference reference)
      Instantiate a Position instance based on an length and a reference point.
      Parameters:
      length - the length, relative to the reference point
      reference - the reference point of this position
  • Method Details

    • ofSi

      public static Position ofSi(double si, Position.Reference reference)
      Return a Position instance based on an SI value and a reference point.
      Parameters:
      si - the length si value, relative to the reference point
      reference - the reference point of this position
      Returns:
      the Position instance based on an SI value
    • instantiate

      public Position instantiate(Length length, Position.Reference reference)
      Description copied from class: AbsQuantity
      Instantiate an absolute quantity with a quantity and a reference.
      Specified by:
      instantiate in class AbsQuantity<Position,Length,Position.Reference>
      Parameters:
      length - the relative quantity that indicates the 'distance' to the reference point
      reference - the reference point
      Returns:
      the absolute quantity with a quantity and a reference
    • valueOf

      public static Position valueOf(String text, Position.Reference reference)
      Returns a Position representation of a textual representation of a value with a unit. The String representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are allowed, but not required, between the value and the unit.
      Parameters:
      text - the textual representation to parse into a Position
      reference - the reference point of this position
      Returns:
      the Scalar representation of the value in its unit
      Throws:
      IllegalArgumentException - when the text cannot be parsed
      NullPointerException - when the text argument is null
    • of

      public static Position of(double valueInUnit, String unitString, Position.Reference reference)
      Returns a Position based on a value and the textual representation of the unit, which can be localized.
      Parameters:
      valueInUnit - the value, expressed in the unit as given by unitString
      unitString - the textual representation of the unit
      reference - the reference point of this position
      Returns:
      the Scalar representation of the value in its unit
      Throws:
      IllegalArgumentException - when the unit cannot be parsed or is incorrect
      NullPointerException - when the unitString argument is null
    • subtract

      public Length subtract(Position other)
      Description copied from class: AbsQuantity
      Subtract two absolute quantities from each other, resulting in the corresponding relative quantity. The unit of the resulting quantity will be the unit of 'this' absolute quantity. Quantity 'other' will be transformed to the reference point of this absolute quantity. If the reference points of this and other are different, and no transformations between the reference points exist, an exception will be thrown.
      Specified by:
      subtract in class AbsQuantity<Position,Length,Position.Reference>
      Parameters:
      other - the absolute quantity to subtract
      Returns:
      the relative quantity as a result of the subtraction
    • add

      public Position add(Length other)
      Description copied from class: AbsQuantity
      Add a relative quantity to this absolute quantity, resulting in a new absolute quantity containing the sum. The new quantity will have the same reference point and unit as this absolute quantity.
      Specified by:
      add in class AbsQuantity<Position,Length,Position.Reference>
      Parameters:
      other - the relative quantity to add
      Returns:
      the absolute quantity as a result of the addition
    • subtract

      public Position subtract(Length other)
      Description copied from class: AbsQuantity
      Subtract a relative quantity from this absolute quantity, resulting in a new absolute quantity containing the difference. The new quantity will have the same reference point and unit as this absolute quantity.
      Specified by:
      subtract in class AbsQuantity<Position,Length,Position.Reference>
      Parameters:
      other - the relative quantity to subtract
      Returns:
      the absolute quantity as a result of the subtraction