Class MultiPath

java.lang.Object
com.graphbuilder.curve.MultiPath
Direct Known Subclasses:
ShapeMultiPath

public class MultiPath extends Object
A multi-path is a series of paths (sequence of connected points) in n-dimensions. The points and move types (MOVE_TO or LINE_TO) are stored using arrays.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Object
     
    static final Object
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MultiPath(int dimension)
    Constructs a multi-path specifying the minimum required dimension of each point appended to this multi-path.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    ensureCapacity(int capacity)
    Checks that the point array has the specified capacity, otherwise the capacity of the point array is increased to be the maximum between twice the current capacity and the specified capacity.
    double[]
    get(int index)
    Returns a reference to the point at the specified index.
    int
    Returns the capacity of the internal point array.
    int
    Returns the dimension.
    double
    getDistSq(double[] p)
    Computes the minimum distance^2 from the specified point to the line segments formed by the points of this multi-path.
    double
    Returns the flatness.
    int
    Returns the size counter.
    getType(int index)
    Returns the type of the point at the specified index.
    void
    lineTo(double[] p)
    Appends a point of type LINE_TO.
    void
    moveTo(double[] p)
    Appends a point of type MOVE_TO.
    void
    set(int index, double[] p)
    Sets the point at the specified index.
    void
    setFlatness(double f)
    Sets the flatness.
    void
    setNumPoints(int n)
    Sets the size counter.
    void
    setType(int index, Object type)
    Sets the type of the point at the specified index.
    void
    Creates a new point array of exact size, copying the points from the old array into the new one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MOVE_TO

      public static final Object MOVE_TO
    • LINE_TO

      public static final Object LINE_TO
  • Constructor Details

    • MultiPath

      public MultiPath(int dimension)
      Constructs a multi-path specifying the minimum required dimension of each point appended to this multi-path.
      Throws:
      IllegalArgumentException - If dimension <= 0.
  • Method Details

    • getDimension

      public int getDimension()
      Returns the dimension. The dimension is used by the BinaryCurveApproximationAlgorithm to know what dimension of points to create. If the dimension of the multi-path is greater than the dimension of the control points for a curve, then an ArrayIndexOutOfBoundsException will occur when the curve is appended to the MultiPath.
    • getFlatness

      public double getFlatness()
      Returns the flatness. The flatness is used by the BinaryCurveApproximationAlgorithm to determine how closely the line segements formed by the points of this multi-path should approximate a given curve. The default flatness value is 1.0. When using curves in a graphics environment, the flatness usually inversely proportional to the scale.
      See Also:
    • setFlatness

      public void setFlatness(double f)
      Sets the flatness. As the flatness value gets closer to zero, the BinaryCurveApproximationAlgorithm generates more points.
      Throws:
      IllegalArgumentException - If the flatness is <= 0.
      See Also:
    • get

      public double[] get(int index)
      Returns a reference to the point at the specified index.
      See Also:
    • set

      public void set(int index, double[] p)
      Sets the point at the specified index.
      Throws:
      IllegalArgumentException - If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.
      See Also:
    • getType

      public Object getType(int index)
      Returns the type of the point at the specified index. The type can other be MultiPath.MOVE_TO or MultiPath.LINE_TO.
      See Also:
    • setType

      public void setType(int index, Object type)
      Sets the type of the point at the specified index. The first point must always be MOVE_TO.
      Throws:
      IllegalArgumentException - If the specified type unknown or the specified index is 0 and type is not MOVE_TO.
      See Also:
    • getNumPoints

      public int getNumPoints()
      Returns the size counter.
      See Also:
    • setNumPoints

      public void setNumPoints(int n)
      Sets the size counter. The size counter can be changed to any value as long as all points from index location 0 (inclusive) to n (exclusive) are non-null. Thus, the maximum value the size counter can be is the first null index location. Changing the size counter does not remove any of the points.
      See Also:
    • getCapacity

      public int getCapacity()
      Returns the capacity of the internal point array.
    • ensureCapacity

      public void ensureCapacity(int capacity)
      Checks that the point array has the specified capacity, otherwise the capacity of the point array is increased to be the maximum between twice the current capacity and the specified capacity.
    • trimArray

      public void trimArray()
      Creates a new point array of exact size, copying the points from the old array into the new one.
    • lineTo

      public void lineTo(double[] p)
      Appends a point of type LINE_TO. If the size counter is 0 then the request is interpretted as a MOVE_TO request.
      Throws:
      IllegalArgumentException - If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.
      See Also:
    • moveTo

      public void moveTo(double[] p)
      Appends a point of type MOVE_TO.
      Throws:
      IllegalArgumentException - If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.
      See Also:
    • getDistSq

      public double getDistSq(double[] p)
      Computes the minimum distance^2 from the specified point to the line segments formed by the points of this multi-path. If the size counter is 0 then the value returned is Double.MAX_VALUE.
      Throws:
      IllegalArgumentException - If the point is null or the length of the point is less than the dimension specified in the constructor.