Interface PolyLine<L extends PolyLine<L,​P,​S,​R>,​P extends Point<P,​S>,​S extends Space,​R>

  • Type Parameters:
    L - the Line type (2d or 3d)
    P - The Point type (2d or 3d)
    S - The Space type (2d, or 3d)
    R - The matching Ray type (2d or 3d)
    All Superinterfaces:
    Drawable<P,​S>, Serializable
    All Known Implementing Classes:
    Polygon2d, PolyLine2d, PolyLine3d

    public interface PolyLine<L extends PolyLine<L,​P,​S,​R>,​P extends Point<P,​S>,​S extends Space,​R>
    extends Drawable<P,​S>
    PolyLine is the interface for PolyLine2d and PolyLine3d implementations.

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

    Author:
    Alexander Verbraeck, Peter Knoppers
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      L extract​(double start, double end)
      Create a new L that covers a sub-section of this L.
      default L extractFractional​(double start, double end)
      Construct a new L covering the indicated fraction of this L.
      default int find​(double pos)
      Binary search for a position on the line.
      P get​(int index)
      Return one of the points of this line.
      default P getFirst()
      Return the first point of this line.
      default P getLast()
      Return the last point of this line.
      double getLength()
      Return the length of this line.
      R getLocation​(double position)
      Get the location at a position on the line, with its direction.
      R getLocationExtended​(double position)
      Get the location at a position on the line, with its direction.
      default R getLocationFraction​(double fraction)
      Get the location at a fraction of the line, with its direction.
      default R getLocationFraction​(double fraction, double tolerance)
      Get the location at a fraction of the line, with its direction.
      default R getLocationFractionExtended​(double fraction)
      Get the location at a fraction of the line (or outside the line), with its direction.
      L instantiate​(List<P> pointList)
      Constructor that can be accessed as a method (used to implement default methods in this interface).
      double lengthAtIndex​(int index)
      Access the internal lengthIndexedLine.
      default L reverse()
      Construct a new Line with all points of this Line in reverse order.
      L truncate​(double position)
      Truncate this Line at the given length (less than the length of the line, and larger than zero) and return a new line.
    • Method Detail

      • instantiate

        L instantiate​(List<P> pointList)
               throws NullPointerException,
                      DrawRuntimeException
        Constructor that can be accessed as a method (used to implement default methods in this interface).
        Parameters:
        pointList - List<P>; a list of points
        Returns:
        L; the new line
        Throws:
        NullPointerException - when pointList is null
        DrawRuntimeException - when pointList has fewer than two points or contains successive duplicate points
      • getLength

        double getLength()
        Return the length of this line. This is NOT the number of points; it is the sum of the lengths of the segments.
        Returns:
        double; the length of this line
      • get

        P get​(int index)
        throws IndexOutOfBoundsException
        Return one of the points of this line.
        Parameters:
        index - int; the index of the requested point
        Returns:
        P; the point at the specified index
        Throws:
        IndexOutOfBoundsException - when index < 0 or index >= size
      • getFirst

        default P getFirst()
        Return the first point of this line.
        Returns:
        P; the first point of this line
      • getLast

        default P getLast()
        Return the last point of this line.
        Returns:
        P; the last point of this line
      • lengthAtIndex

        double lengthAtIndex​(int index)
                      throws IndexOutOfBoundsException
        Access the internal lengthIndexedLine. Return the cumulative length up to point index of this line
        Parameters:
        index - int; the index
        Returns:
        double; the cumulative length of this line up to point index
        Throws:
        IndexOutOfBoundsException - when index < 0 or index >= size()
      • reverse

        default L reverse()
        Construct a new Line with all points of this Line in reverse order.
        Returns:
        L; the new Line
      • extractFractional

        default L extractFractional​(double start,
                                    double end)
                             throws DrawException
        Construct a new L covering the indicated fraction of this L.
        Parameters:
        start - double; starting point, valid range [0..end)
        end - double; ending point, valid range (start..1]
        Returns:
        Line3d; the new L
        Throws:
        DrawException - when start >= end, or start < 0, or end > 1
      • extract

        L extract​(double start,
                  double end)
           throws DrawException
        Create a new L that covers a sub-section of this L.
        Parameters:
        start - double; length along this Line3d where the sub-section starts, valid range [0..end)
        end - double; length along this Line3d where the sub-section ends, valid range (start..length (length is the length of this L)
        Returns:
        L; the selected sub-section
        Throws:
        DrawException - when start >= end, or start < 0, or end > length
      • getLocation

        R getLocation​(double position)
               throws DrawException
        Get the location at a position on the line, with its direction. Position should be between 0.0 and line length.
        Parameters:
        position - double; the position on the line for which to calculate the point on the line
        Returns:
        OP; an oriented point
        Throws:
        DrawException - when position less than 0.0 or more than line length.
      • getLocationExtended

        R getLocationExtended​(double position)
        Get the location at a position on the line, with its direction. Position can be below 0 or more than the line length. In that case, the position will be extrapolated in the direction of the line at its start or end.
        Parameters:
        position - double; the position on the line for which to calculate the point on, before, or after the line
        Returns:
        OP; an oriented point
      • getLocationFraction

        default R getLocationFraction​(double fraction)
                               throws DrawException
        Get the location at a fraction of the line, with its direction. Fraction should be between 0.0 and 1.0.
        Parameters:
        fraction - double; the fraction for which to calculate the point on the line
        Returns:
        OP; an oriented point
        Throws:
        DrawException - when fraction less than 0.0 or more than 1.0.
      • getLocationFraction

        default R getLocationFraction​(double fraction,
                                      double tolerance)
                               throws DrawException
        Get the location at a fraction of the line, with its direction. Fraction should be between 0.0 and 1.0.
        Parameters:
        fraction - double; the fraction for which to calculate the point on the line
        tolerance - double; the delta from 0.0 and 1.0 that will be forgiven
        Returns:
        OrientedPoint3d, or OrientedPoint2d (in accordance with OP, P, L and S)
        Throws:
        DrawException - when fraction less than 0.0 or more than 1.0.
      • getLocationFractionExtended

        default R getLocationFractionExtended​(double fraction)
        Get the location at a fraction of the line (or outside the line), with its direction.
        Parameters:
        fraction - double; the fraction for which to calculate the point on the line
        Returns:
        OrientedPoint3d, or OrientedPoint2d (in accordance with OP, P, L and S)
      • truncate

        L truncate​(double position)
            throws DrawException
        Truncate this Line at the given length (less than the length of the line, and larger than zero) and return a new line.
        Parameters:
        position - double; the position along the line where to truncate the line
        Returns:
        L; a new Line that follows this line, but ends at the position where line.getLength() == lengthSI
        Throws:
        DrawException - when position less than 0.0 or more than line length.
      • find

        default int find​(double pos)
                  throws DrawException
        Binary search for a position on the line.
        Parameters:
        pos - double; the position to look for
        Returns:
        the index below the position; the position is between points[index] and points[index+1]
        Throws:
        DrawException - when index could not be found