com.partnersoft.v3x.graphics
Class Coord

java.lang.Object
  extended by com.partnersoft.v3x.graphics.Coord
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Coord2D, TurnVector

public class Coord
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A Coord is an n-dimensional coordinate or offset.

See Also:
Serialized Form

Field Summary
protected  double[] coords
           
 
Constructor Summary
Coord()
          Default constructor.
Coord(double[] newCoords)
          Creates a new Coord from an array of double.
 
Method Summary
 double at(int dimension)
          Returns the magnitude of a dimension.
 java.lang.Object clone()
          Clones the Coord.
protected  void copyState(Coord from)
          Copies contents from another Coord.
 double distance(Coord base)
          Returns distance from another coord.
 boolean equals(java.lang.Object nother)
           
protected  java.util.ArrayList getCoords()
          Get the coordinate vector for this coord.
 int getDimensions()
          Number of dimensions in the Coord
 int hashCode()
          Hash value for the object.
 Coord round()
          Rounds off each magnitude to the nearest integer.
protected  void setCoords(java.util.ArrayList coordVec)
          Set the coordinate vector for this coord.
 Coord stretch(double factor)
          Stretch is a uniform expansion or compression by a single factor.
 java.lang.String toString()
          Returns a formatted string representation of the coordinate in (x, y, z, ...) style.
 Coord translate(Coord offset)
          Translates a coordinate by an offset.
 Coord truncate()
          Truncates each magnitude to the next lower integer.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

coords

protected double[] coords
Constructor Detail

Coord

public Coord()
Default constructor.


Coord

public Coord(double[] newCoords)
Creates a new Coord from an array of double.

Method Detail

getDimensions

public int getDimensions()
Number of dimensions in the Coord


at

public double at(int dimension)
Returns the magnitude of a dimension. Dimensions begin with zero.


clone

public java.lang.Object clone()
Clones the Coord.

Overrides:
clone in class java.lang.Object

copyState

protected void copyState(Coord from)
Copies contents from another Coord. Used to make subclass cloning easier. Subclasses should call this from their clone() routine.


translate

public Coord translate(Coord offset)
Translates a coordinate by an offset. If the coordinate and the offset have a different number of dimensions, a coordinate is returned that has a number of dimensions that is the greater of the two. Each dimension of the coordinate is added to the same dimension in the offset; zero is assumed for nonpresent dimensions (those dimensions available in one and not the other).


stretch

public Coord stretch(double factor)
Stretch is a uniform expansion or compression by a single factor. Each dimension is multiplied by this factor. Negative and fractional values are allowed (even zero, though that's a pretty degenerate case).


round

public Coord round()
Rounds off each magnitude to the nearest integer.


truncate

public Coord truncate()
Truncates each magnitude to the next lower integer.


toString

public java.lang.String toString()
Returns a formatted string representation of the coordinate in (x, y, z, ...) style.

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Hash value for the object.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object

distance

public double distance(Coord base)
Returns distance from another coord.


getCoords

protected java.util.ArrayList getCoords()
Get the coordinate vector for this coord.


setCoords

protected void setCoords(java.util.ArrayList coordVec)
Set the coordinate vector for this coord.