Class FractionalLengthData

java.lang.Object
org.opentrafficsim.core.geometry.FractionalLengthData

public class FractionalLengthData extends Object
Container for fractional length data.

Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Wouter Schakel
  • Constructor Details

    • FractionalLengthData

      public FractionalLengthData(double... data) throws IllegalArgumentException
      Create FractionalLengthData.
      Parameters:
      data - double...; fractional length - value pairs. Fractional lengths do not need to be in order.
      Throws:
      IllegalArgumentException - when the number of input values is not even or 0.
      IllegalArgumentException - when a fractional value is not in the range [0 ... 1].
    • FractionalLengthData

      public FractionalLengthData(Map<Double,Double> data) throws IllegalArgumentException
      Create FractionalLengthData.
      Parameters:
      data - Map<Double, Double>; fractional length - value pairs. Fractional lengths do not need to be in order.
      Throws:
      IllegalArgumentException - when the input data is null or empty.
      IllegalArgumentException - when a fractional value is not in the range [0 ... 1].
  • Method Details

    • get

      public double get(double fractionalLength)
      Returns the data at given fractional length. If only data beyond the fractional length is available, the first available value is returned. If only data before the fractional length is available, the last available value is returned. Otherwise data is linearly interpolated.
      Parameters:
      fractionalLength - double; fractional length, may be outside range [0 ... 1].
      Returns:
      double; interpolated or extended value.
    • getDerivative

      public double getDerivative(double fractionalLength)
      Returns the derivative of the data with respect to fractional length.
      Parameters:
      fractionalLength - double; fractional length, may be outside range [0 ... 1].
      Returns:
      double; derivative of the data with respect to fractional length.
    • getFractionalLengths

      public org.djutils.immutablecollections.ImmutableNavigableSet<Double> getFractionalLengths()
      Returns the fractional lengths in the underlying data.
      Returns:
      ImmutableNavigableSet<Double>; fractional lengths in the underlying data.
    • getValues

      public org.djutils.immutablecollections.ImmutableSet<Double> getValues()
      Returns the values in the underlying data.
      Returns:
      ImmutableSet<Double>; values in the underlying data.
    • getFractionalLengthsAsArray

      public double[] getFractionalLengthsAsArray()
      Returns fractional lengths in array form, including 0.0 and 1.0.
      Returns:
      double[]; fractional lengths.
    • getValuesAsArray

      public double[] getValuesAsArray()
      Returns fractional lengths in array form, including values at 0.0 and 1.0.
      Returns:
      double[]; fractional lengths.
    • size

      public int size()
      Returns the number of data points.
      Returns:
      int; number of data points.
    • of

      public static FractionalLengthData of(double... data) throws IllegalArgumentException
      Create FractionalLengthData.
      Parameters:
      data - double...; fractional length - value pairs. Fractional lengths do not need to be in order.
      Returns:
      FractionalLengthData; fractional length data.
      Throws:
      IllegalArgumentException - when the number of input values is not even or 0.
      IllegalArgumentException - when a fractional value is not in the range [0 ... 1].