de.cau.cs.kieler.core.math
Class KVectorChain

java.lang.Object
  extended by java.util.AbstractSequentialList<E>
      extended by java.util.LinkedList<KVector>
          extended by de.cau.cs.kieler.core.math.KVectorChain
All Implemented Interfaces:
IDataObject, Serializable, Cloneable, Iterable<KVector>, Collection<KVector>, Deque<KVector>, List<KVector>, Queue

public class KVectorChain
extends LinkedList<KVector>
implements IDataObject

A chain of vectors. Can be used to describe polylines or similar constructs.

See Also:
Serialized Form
Rating proposed yellow
(2011-01-13) msp

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Constructor Summary
KVectorChain()
          Creates an empty vector chain.
KVectorChain(Collection<KVector> collection)
          Creates a vector chain from a given collection of vectors.
KVectorChain(KVector[] vectors)
          Creates a vector chain from a given vector array.
 
Method Summary
 void add()
          Adds a (0,0) vector to the vector chain.
 void add(double x, double y)
          Adds the vector (x,y) to the vector chain.
 void addAll(KVector[] vectors)
          Add all the vectors in the given array to the end of this vector chain.
 void addFirst()
          Adds a (0,0) vector to the beginning of the vector chain.
 void addFirst(double x, double y)
          Adds the vector (x,y) to the beginning of the vector chain.
 void addLast()
          Adds a (0,0) vector to the end of the vector chain.
 void addLast(double x, double y)
          Adds the vector (x,y) to the end of the vector chain.
 boolean containsAll(Collection<?> c)
           
 boolean equals(Object o)
           
 double getLength()
          Calculate the total length of this vector chain.
 KVector getPointOnLine(double dist)
          Calculate a point on this vector chain with given distance.
 boolean isEmpty()
           
 ListIterator<E> listIterator()
           
 void parse(String string)
          Parse the given string and set the content of this data object.
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
static KVectorChain reverse(KVectorChain chain)
          Returns a new vector chain that is the reverse of the given vector chain.
 String toString()
          
 void translate(double dx, double dy)
          Iterates through all vectors and adds the offset to them.
 void translate(KVector offset)
          Iterates through all vectors and adds the offset to them.
 
Methods inherited from class java.util.LinkedList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, toArray, toArray
 
Methods inherited from class java.util.Queue
empty, peek, pop, push
 
Methods inherited from class java.util.Vector
addElement, capacity, clear, elementAt, elements, ensureCapacity, equals, indexOf, indexOf, insertElementAt, isEmpty, lastIndexOf, lastIndexOf, removeAllElements, removeElement, removeElementAt, setElementAt, setSize, size, toArray, trimToSize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from class java.util.AbstractSequentialList
iterator
 
Methods inherited from interface java.util.List
listIterator, subList
 
Methods inherited from interface java.util.Collection
containsAll, equals, hashCode, isEmpty, iterator, removeAll, retainAll
 
Methods inherited from interface java.util.Deque
iterator
 

Constructor Detail

KVectorChain

public KVectorChain()
Creates an empty vector chain.


KVectorChain

public KVectorChain(Collection<KVector> collection)
Creates a vector chain from a given collection of vectors.

Parameters:
collection - a collection of vectors

KVectorChain

public KVectorChain(KVector[] vectors)
Creates a vector chain from a given vector array.

Parameters:
vectors - an array of vectors
Method Detail

toString

public String toString()

Overrides:
toString in class Object

parse

public void parse(String string)
Parse the given string and set the content of this data object.

Specified by:
parse in interface IDataObject
Parameters:
string - a string

add

public void add()
Adds a (0,0) vector to the vector chain.


add

public void add(double x,
                double y)
Adds the vector (x,y) to the vector chain.

Parameters:
x - x coordinate
y - y coordinate

addFirst

public void addFirst()
Adds a (0,0) vector to the beginning of the vector chain.


addFirst

public void addFirst(double x,
                     double y)
Adds the vector (x,y) to the beginning of the vector chain.

Parameters:
x - x coordinate
y - y coordinate

addLast

public void addLast()
Adds a (0,0) vector to the end of the vector chain.


addLast

public void addLast(double x,
                    double y)
Adds the vector (x,y) to the end of the vector chain.

Parameters:
x - x coordinate
y - y coordinate

addAll

public void addAll(KVector[] vectors)
Add all the vectors in the given array to the end of this vector chain.

Parameters:
vectors - a vector array

translate

public void translate(KVector offset)
Iterates through all vectors and adds the offset to them.

Parameters:
offset - the offset to add to the vectors.

translate

public void translate(double dx,
                      double dy)
Iterates through all vectors and adds the offset to them.

Parameters:
dx - x value to add.
dy - y value to add.

getLength

public double getLength()
Calculate the total length of this vector chain.

Returns:
the total length

getPointOnLine

public KVector getPointOnLine(double dist)
Calculate a point on this vector chain with given distance. The result is a point whose distance from the first point on the chain equals the given distance. If the parameter is negative, the result is mirrored, i.e. the distance is seen from the last point on the chain.

Parameters:
dist - the distance from the first point (if positive) or the last point (if negative)
Returns:
a point on the vector chain

reverse

public static KVectorChain reverse(KVectorChain chain)
Returns a new vector chain that is the reverse of the given vector chain. The returned vector chain is a deep copy in the sense that a change to a KVector instance in the old chain doesn't affect any vectors in the new chain.

Parameters:
chain - the chain to be reversed.
Returns:
a new vector chain that is the reverse of the old one.

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<E>
Overrides:
equals in class Object

listIterator

public ListIterator<E> listIterator()
Specified by:
listIterator in interface List<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<E>