org.jrabbit.base.math.vector
Class VectorPath

java.lang.Object
  extended by org.jrabbit.base.math.vector.VectorPath
All Implemented Interfaces:
java.lang.Iterable<Vector2f>, Renderable

public class VectorPath
extends java.lang.Object
implements java.lang.Iterable<Vector2f>, Renderable

VectorPath is a lightweight data structure designed to keep an ordered list of Vector2fs. In doing so, it represents a path. VectorPath is bounded; it has a maximum number of vectors allowed in it. If more Vectors are placed in the list than allowed, they are dynamically streamed out of it.

Author:
Chris Molini

Field Summary
protected  int maxLength
          The maximum number of Vectors allowed in the path.
protected  java.util.LinkedList<Vector2f> path
          The list of Vectors.
 
Constructor Summary
VectorPath()
          Creates a VectorPath that allows Integer.MAX_VALUE number of Vectors.
VectorPath(int maxLength)
          Creates a VectorPath that will hold the indicated number of Vectors.
 
Method Summary
private  void checkPath()
          Checks the path's length to keep it in bounds.
 Vector2f end()
          Accesses the "end" of the path.
 java.util.Iterator<Vector2f> iterator()
          Accesses an iterator that cycles through the path.
 int length()
          Learns the current length of the path.
 int maxLength()
          Learns the max length of the path.
 java.util.LinkedList<Vector2f> pathData()
          Accesses the list of Vectors.
 void push(Vector2f vector)
          Adds another Vector to the end of this path, and checks the size.
 void render()
          Draws the path as a continuous line.
 void setMaxLength(int length)
          Redefines the number of allowed Vectors.
 Vector2f start()
          Accesses the "beginning" of the path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

path

protected java.util.LinkedList<Vector2f> path
The list of Vectors.


maxLength

protected int maxLength
The maximum number of Vectors allowed in the path.

Constructor Detail

VectorPath

public VectorPath()
Creates a VectorPath that allows Integer.MAX_VALUE number of Vectors.


VectorPath

public VectorPath(int maxLength)
Creates a VectorPath that will hold the indicated number of Vectors.

Parameters:
maxLength - The number of Vectors to allow.
Method Detail

length

public int length()
Learns the current length of the path.

Returns:
How many Vectors are contained.

maxLength

public int maxLength()
Learns the max length of the path.

Returns:
The maximum number of Vectors allowed in this path.

setMaxLength

public void setMaxLength(int length)
Redefines the number of allowed Vectors. If the current length is greater than the new max size, the path is cropped to fit.

Parameters:
length - The new max length.

start

public Vector2f start()
Accesses the "beginning" of the path. This is the oldest Vector currently contained.

Returns:
The start of the path.

end

public Vector2f end()
Accesses the "end" of the path. This is the newest Vector currently contained.

Returns:
The end of the path.

push

public void push(Vector2f vector)
Adds another Vector to the end of this path, and checks the size. If more Vectors are contained than allowed, the "start" Vector is removed.

Parameters:
vector - The Vector to add.

checkPath

private void checkPath()
Checks the path's length to keep it in bounds. While more Vectors are contained than allowed, the "start" Vector is removed.


pathData

public java.util.LinkedList<Vector2f> pathData()
Accesses the list of Vectors.

Returns:
The LinkedList used to keep track of path coordinates.

iterator

public java.util.Iterator<Vector2f> iterator()
Accesses an iterator that cycles through the path.

Specified by:
iterator in interface java.lang.Iterable<Vector2f>
Returns:
The Iterator of the list used to contain the Vectors.

render

public void render()
Draws the path as a continuous line. NOTE: This makes no effort to change the currently bound texture, so it's recommended to change the settings on bound textures before this is called.

Specified by:
render in interface Renderable