edu.neu.ccs.gui
Class PathListFunction

java.lang.Object
  extended byedu.neu.ccs.gui.PathListFunction

public class PathListFunction
extends Object

Class PathListFunction contains methods to compute one or more points on a path that is defined by a PathList given a parameter t. The class constructor examines the PathList and builds auxiliary data that will make the computations efficient. All such data is created internally so that later changes to the PathList cannot affect the function computations.

In parallel to the generalizations introduced to the PathList class in 2.6.0a, this class will compute points even if the path is not valid, that is, even if the path does not start with a MOVE. Here is a sketch of how the computation is done.

If the PathList used in the constructor of this class is null, of size 0, or has path nodes only of type CLOSE, then the point functions will return the point 0,0 for any value of the parameter t.

Otherwise, let A denote the index of the first path node in the path list which is not of type CLOSE and let B denote the last index in the path list, that is, the size minus 1. Then, the point functions will be constant for t<=A and for B<=t.

For the purposes of computing points when A<=t<=B, we make an internal array of PathNode objects that extract and sometimes alter the information in the original path list. For index A, we create a new path of type MOVE with the same endpoint as the corresponding node in the path list. If i is an index with A<i<=B, we clone the corresponding node in the path list except when the node is of type CLOSE. In the latter case, we create instead a new node of type LINE whose endpoint is the same as the endpoint of the last previous MOVE in the part of the array constructed so far. In this way, the resulting array has no CLOSE operations but nevertheless has the same geometry as the original path.

The point computation for A<=t<=B then proceeds as follows. If t is an integer, return the endpoint of the corresponding node in the path node array. Otherwise let t=i+s where i is an integer and 0<s<1. Then, utilize the tools in class Bezier to construct the interpolated point for parameter t using the endpoint of node i, the full node data of node i+1, and the parameter s as the interpolation parameter.

Since:
2.6.0a
Version:
2.6.0a

Field Summary
private  int A
          If N > 0, then A is the index of the first node in the original path list that is not a CLOSE.
private  int B
          If N > 0, then B = N - 1.
static int CLOSE
          Shorthand constant for PathIterator.SEG_CLOSE.
static int CUBIC
          Shorthand constant for PathIterator.SEG_CUBICTO.
static int LINE
          Shorthand constant for PathIterator.SEG_LINETO.
static int MOVE
          Shorthand constant for PathIterator.SEG_MOVETO.
private  int N
          The number N of nodes unless all nodes are of type CLOSE in which case N is set to 0.
private  PathNode[] nodes
          The cloned or adjusted path nodes or null if there is no reason to construct path nodes because N is 0.
static int QUAD
          Shorthand constant for PathIterator.SEG_QUADTO.
private  WindingRule rule
          The winding rule of the original path list.
 
Constructor Summary
PathListFunction(PathList pathList)
           Utilizes the given path list to construct the internal data structures that will be used for the computation of the point functions related to the path list.
 
Method Summary
 int getLower()
          Returns the lower bound of the range of the parameter t on which the point function varies.
 float[] getShapePoint(float t)
          Returns the point on the path as float[2] corresponding to the parameter t.
 XPoint2D getShapePoint2D(double t)
          Returns the point on the path as XPoint2D corresponding to the parameter t.
 XPoint2D[] getShapePoint2DArray(int divisions)
          Returns an array XPoint2D[] of objects representing points on the path.
 float[][] getShapePointArray(int divisions)
          Returns an array float[][] of objects representing points on the path.
 int getUpper()
          Returns the upper bound of the range of the parameter t on which the point function varies.
 double getX(double t)
          Returns the x-coordinate of a point on the path corresponding to the parameter t.
 double getY(double t)
          Returns the y-coordinate of a point on the path corresponding to the parameter t.
 boolean isEmpty()
          Returns true if this path is empty, that is, the initializing path list provided no point data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOVE

public static final int MOVE
Shorthand constant for PathIterator.SEG_MOVETO.

See Also:
Constant Field Values

LINE

public static final int LINE
Shorthand constant for PathIterator.SEG_LINETO.

See Also:
Constant Field Values

QUAD

public static final int QUAD
Shorthand constant for PathIterator.SEG_QUADTO.

See Also:
Constant Field Values

CUBIC

public static final int CUBIC
Shorthand constant for PathIterator.SEG_CUBICTO.

See Also:
Constant Field Values

CLOSE

public static final int CLOSE
Shorthand constant for PathIterator.SEG_CLOSE.

See Also:
Constant Field Values

N

private int N
The number N of nodes unless all nodes are of type CLOSE in which case N is set to 0.


A

private int A
If N > 0, then A is the index of the first node in the original path list that is not a CLOSE.


B

private int B
If N > 0, then B = N - 1.


nodes

private PathNode[] nodes
The cloned or adjusted path nodes or null if there is no reason to construct path nodes because N is 0.


rule

private WindingRule rule
The winding rule of the original path list.

Constructor Detail

PathListFunction

public PathListFunction(PathList pathList)

Utilizes the given path list to construct the internal data structures that will be used for the computation of the point functions related to the path list.

Once built, the internal data structures have no connection to the original path list and are immutable.

Method Detail

getX

public final double getX(double t)

Returns the x-coordinate of a point on the path corresponding to the parameter t.

Parameters:
t - the point function parameter as a double

getY

public final double getY(double t)

Returns the y-coordinate of a point on the path corresponding to the parameter t.

Parameters:
t - the point function parameter as a double

getShapePoint2D

public final XPoint2D getShapePoint2D(double t)

Returns the point on the path as XPoint2D corresponding to the parameter t.

Parameters:
t - the point function parameter as a double

getShapePoint

public final float[] getShapePoint(float t)

Returns the point on the path as float[2] corresponding to the parameter t.

Parameters:
t - the point function parameter as a float

isEmpty

public final boolean isEmpty()
Returns true if this path is empty, that is, the initializing path list provided no point data.


getLower

public final int getLower()

Returns the lower bound of the range of the parameter t on which the point function varies.


getUpper

public final int getUpper()

Returns the upper bound of the range of the parameter t on which the point function varies.


getShapePoint2DArray

public final XPoint2D[] getShapePoint2DArray(int divisions)

Returns an array XPoint2D[] of objects representing points on the path.

If the path is empty, then this method returns an empty array.

Otherwise, the given integer divisions represents the number of divisions in each unit interval along which the path changes.

Furthermore, if A and B represent the lower and upper bounds of the range on which the path changes, then this method returns an array with

    1 + (B - A) * divisions

points of type XPoint2D.

These points correspond to a parameter t of the form

    t = A + i * delta

where i is an integer such that

   0 <= i <= (B - A) * divisions

and

    delta = 1.0 / divisions

Parameters:
divisions - the number of divisions of each unit interval

getShapePointArray

public final float[][] getShapePointArray(int divisions)

Returns an array float[][] of objects representing points on the path.

If the path is empty, then this method returns an empty array.

Otherwise, the given integer divisions represents the number of divisions in each unit interval along which the path changes.

Furthermore, if A and B represent the lower and upper bounds of the range on which the path changes, then this method returns an array with

    1 + (B - A) * divisions

points of type float[2].

These points correspond to a parameter t of the form

    t = A + i * delta

where i is an integer such that

   0 <= i <= (B - A) * divisions

and

    delta = 1.0f / divisions

Parameters:
divisions - the number of divisions of each unit interval