com.graphbuilder.curve
Class MultiPath

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

public class MultiPath
extends java.lang.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:
Curve, ShapeMultiPath

Field Summary
static java.lang.Object LINE_TO
           
static java.lang.Object MOVE_TO
           
 
Constructor Summary
MultiPath(int dimension)
          Constructs a multi-path specifying the minimum required dimension of each point appended to this multi-path.
 
Method Summary
 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 getCapacity()
          Returns the capacity of the internal point array.
 int getDimension()
          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 getFlatness()
          Returns the flatness.
 int getNumPoints()
          Returns the size counter.
 java.lang.Object 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, java.lang.Object type)
          Sets the type of the point at the specified index.
 void trimArray()
          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 Detail

MOVE_TO

public static final java.lang.Object MOVE_TO

LINE_TO

public static final java.lang.Object LINE_TO
Constructor Detail

MultiPath

public MultiPath(int dimension)
Constructs a multi-path specifying the minimum required dimension of each point appended to this multi-path.

Throws:
java.lang.IllegalArgumentException - If dimension <= 0.
Method Detail

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(double)

setFlatness

public void setFlatness(double f)
Sets the flatness. As the flatness value gets closer to zero, the BinaryCurveApproximationAlgorithm generates more points.

Throws:
java.lang.IllegalArgumentException - If the flatness is <= 0.
See Also:
getFlatness()

get

public double[] get(int index)
Returns a reference to the point at the specified index.

See Also:
set(int, double[])

set

public void set(int index,
                double[] p)
Sets the point at the specified index.

Throws:
java.lang.IllegalArgumentException - If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.
See Also:
get(int)

getType

public java.lang.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(int, Object)

setType

public void setType(int index,
                    java.lang.Object type)
Sets the type of the point at the specified index. The first point must always be MOVE_TO.

Throws:
java.lang.IllegalArgumentException - If the specified type unknown or the specified index is 0 and type is not MOVE_TO.
See Also:
getType(int)

getNumPoints

public int getNumPoints()
Returns the size counter.

See Also:
setNumPoints(int)

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:
getNumPoints()

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:
java.lang.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(double[])

moveTo

public void moveTo(double[] p)
Appends a point of type MOVE_TO.

Throws:
java.lang.IllegalArgumentException - If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.
See Also:
lineTo(double[])

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:
java.lang.IllegalArgumentException - If the point is null or the length of the point is less than the dimension specified in the constructor.