org.starhope.appius.geometry
Class Tuple2D<T extends Tuple2D<T>>

java.lang.Object
  extended by org.starhope.appius.geometry.Tuple2D<T>
Type Parameters:
T - WRITEME
All Implemented Interfaces:
Serializable, CastsToJSON
Direct Known Subclasses:
Coord2D, Vector2D

public abstract class Tuple2D<T extends Tuple2D<T>>
extends Object
implements CastsToJSON

Base coordinate pair type

Author:
ewinkelman
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          Java serialisation unique ID
protected  double x
          X
protected  double y
          Y
 
Constructor Summary
Tuple2D(double x0, double y0)
          Create a new coordinate pair
Tuple2D(T t)
          Create a new coordinate pair from an existing coordinate pair
 
Method Summary
 T add(double x0, double y0)
          Adds the coordinate pair to the tuple together
 T add(T p)
          Adds two tuples together
protected  Object clone()
           
 T divide(double factor)
          Divides the tuple by the value NOTE: Will happily try to divide by zero!
 boolean equals(Object o)
           
 double getX()
          Gets the X coordinate
 double getY()
          Gets the Y coordinate
 int hashCode()
           
 T multiply(double factor)
          Multiplies the tuple by the value
protected abstract  T newInstance(double x0, double y0)
          Method used to create a new object of the child's type while getting around downcasting problems in Java
 T subtract(double x2, double y2)
          Subtracts the coordinate pair from this tuple
 T subtract(T p)
          Subtracts a tuple from this tuple
 org.json.JSONObject toJSON()
          This returns a copy of the object's data cast into a JSON form.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Java serialisation unique ID

See Also:
Constant Field Values

x

protected final double x
X


y

protected final double y
Y

Constructor Detail

Tuple2D

public Tuple2D(double x0,
               double y0)
Create a new coordinate pair

Parameters:
x0 - WRITEME
y0 - WRITEME

Tuple2D

public Tuple2D(T t)
Create a new coordinate pair from an existing coordinate pair

Parameters:
t - WRITEME
Method Detail

add

public T add(double x0,
             double y0)
Adds the coordinate pair to the tuple together

Parameters:
x0 - WRITEME
y0 - WRITEME
Returns:
WRITEME

add

public T add(T p)
Adds two tuples together

Parameters:
p - WRITEME
Returns:
WRITEME

clone

protected Object clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException
See Also:
Object.clone()

divide

public T divide(double factor)
Divides the tuple by the value NOTE: Will happily try to divide by zero!

Parameters:
factor - Amount to divide the tuple by
Returns:
WRITEME

equals

public boolean equals(Object o)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getX

public double getX()
Gets the X coordinate

Returns:
WRITEME

getY

public double getY()
Gets the Y coordinate

Returns:
WRITEME

hashCode

public int hashCode()
Overrides:
hashCode in class Object

multiply

public T multiply(double factor)
Multiplies the tuple by the value

Parameters:
factor - Amount to multiply the tuple by
Returns:
WRITEME

newInstance

protected abstract T newInstance(double x0,
                                 double y0)
Method used to create a new object of the child's type while getting around downcasting problems in Java

Parameters:
x0 - x
y0 - y
Returns:
(x,y)

subtract

public T subtract(double x2,
                  double y2)
Subtracts the coordinate pair from this tuple

Parameters:
x2 - Coordinate pair to subtract from this tuple
y2 - Coordinate pair to subtract from this tuple
Returns:
WRITEME

subtract

public T subtract(T p)
Subtracts a tuple from this tuple

Parameters:
p - Tuple to subtract from this tuple
Returns:
WRITEME

toJSON

public org.json.JSONObject toJSON()
Description copied from interface: CastsToJSON
This returns a copy of the object's data cast into a JSON form.

Specified by:
toJSON in interface CastsToJSON
Returns:
The string representing this object in JSON format
See Also:
CastsToJSON.toJSON()

toString

public String toString()
Overrides:
toString in class Object