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

java.lang.Object
  extended by org.starhope.appius.geometry.Tuple3D<T>
Type Parameters:
T - the subclass for hacky type-safety things
All Implemented Interfaces:
Serializable, CastsToJSON
Direct Known Subclasses:
Coord3D

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

Base coordinate triplet 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
protected  double z
          Z
 
Constructor Summary
Tuple3D(double x0, double y0, double z0)
          Create a new coördinate triplet
Tuple3D(org.json.JSONObject o)
          Instantiate from JSON data
Tuple3D(T t)
          Create a new coordinate triplet from an existing coordinate triplet
 
Method Summary
 T add(double x0, double y0, double z0)
          Adds the coördinate triplet to the tuple together
 T add(T p)
          Adds two tuples together
protected  Object clone()
           
 T divide(double dividend)
          Divides the tuple by the value
 boolean equals(Object obj)
           
 double getX()
          Gets the X ordinate
 double getY()
          Gets the Y abscissa
 double getZ()
          Gets the Z ordinate
 int hashCode()
           
 T multiply(double factor)
          Multiplies the tuple by the value
protected abstract  T newInstance(double x0, double y0, double z0)
          Method used to create a new object of the child's type while getting around down-casting problems in Java
 T subtract(double x2, double y2, double z2)
          Subtracts the coordinate triplet 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


z

protected final double z
Z

Constructor Detail

Tuple3D

public Tuple3D(double x0,
               double y0,
               double z0)
Create a new coördinate triplet

Parameters:
x0 - x ordinate
y0 - y abscissa
z0 - z ordinate

Tuple3D

public Tuple3D(org.json.JSONObject o)
        throws org.json.JSONException
Instantiate from JSON data

Parameters:
o - JSON coordinate object
Throws:
org.json.JSONException - if the data is malformed

Tuple3D

public Tuple3D(T t)
Create a new coordinate triplet from an existing coordinate triplet

Parameters:
t - tuple
Method Detail

add

public T add(double x0,
             double y0,
             double z0)
Adds the coördinate triplet to the tuple together

Parameters:
x0 - x ordinate
y0 - y abscissa
z0 - z ordinate
Returns:
a new tuple

add

public T add(T p)
Adds two tuples together

Parameters:
p - tuple
Returns:
the sum of the coördinates

clone

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

divide

public T divide(double dividend)

Divides the tuple by the value

Note: Will happily try to divide by zero if assertions are disabled!

Parameters:
dividend - Amount by which to divide the tuple
Returns:
the tuple divided by the scaling factor

equals

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

getX

public double getX()
Gets the X ordinate

Returns:
x ordinate

getY

public double getY()
Gets the Y abscissa

Returns:
y abscissa

getZ

public double getZ()
Gets the Z ordinate

Returns:
z ordinate

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

multiply

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

Parameters:
factor - Amount by which to multiply the tuple
Returns:
the tuple scaled by the given factor

newInstance

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

Parameters:
x0 - x ordinate
y0 - y abscissa
z0 - z ordinate
Returns:
a new instance of the same type, with the given values

subtract

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

Parameters:
x2 - Coordinate triplet to subtract from this tuple
y2 - Coordinate triplet to subtract from this tuple
z2 - Coordinate triplet to subtract from this tuple
Returns:
the difference

subtract

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

Parameters:
p - Tuple to subtract from this tuple
Returns:
the difference

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
See Also:
Object.toString()