org.openmali.vecmath2
Class Tuple2d

java.lang.Object
  extended by org.openmali.vecmath2.TupleNd<Tuple2d>
      extended by org.openmali.vecmath2.Tuple2d
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
Point2d, Vector2d

public class Tuple2d
extends TupleNd<Tuple2d>
implements java.io.Externalizable

A simple three-dimensional tuple implementation. Inspired by Kenji Hiranabe's Tuple2d implementation

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.openmali.vecmath2.TupleNd
isDirty, roTrick, values
 
Constructor Summary
  Tuple2d()
          Creates a new Tuple2d instance.
protected Tuple2d(boolean readOnly)
          Creates a new Tuple2d instance.
protected Tuple2d(boolean readOnly, double[] values, boolean[] isDirty, boolean copy)
          Creates a new Tuple2d instance.
protected Tuple2d(boolean readOnly, double x, double y)
          Creates a new Tuple2d instance.
protected Tuple2d(boolean readOnly, Tuple2d that)
          Creates a new Tuple2d instance.
  Tuple2d(double[] values)
          Creates a new Tuple2d instance.
  Tuple2d(double x, double y)
          Creates a new Tuple2d instance.
  Tuple2d(Tuple2d that)
          Creates a new Tuple2d instance.
 
Method Summary
 Tuple2d add(double x, double y)
          Adds the given parameters to this tuple's values.
 Tuple2d addX(double v)
          Adds v to this tuple's x value.
 Tuple2d addY(double v)
          Adds v to this tuple's y value.
 Tuple2d asReadOnly()
          
 Tuple2d clone()
          Creates and returns a copy of this object.
 Tuple2d div(double vx, double vy)
          Divides this tuple's values by vx, vy, vz.
 Tuple2d divX(double v)
          Divides this tuple's x value by v.
 Tuple2d divY(double v)
          Divides this tuple's y value by v.
 boolean equals(java.lang.Object tuple2)
          Returns true if the Object t1 is of type Tuple3d and all of the data members of t1 are equal to the corresponding data members in this Tuple2d.
static Tuple2d fromPool()
          Allocates an Tuple2d instance from the pool.
static Tuple2d fromPool(double x, double y)
          Allocates an Tuple2d instance from the pool.
static Tuple2d fromPool(Tuple2d tuple)
          Allocates an Tuple2d instance from the pool.
 Tuple2d getReadOnly()
          
 double getX()
           
 double getY()
           
 Tuple2d mul(double vx, double vy)
          Multiplies this tuple's values with vx, vy.
 Tuple2d mulX(double v)
          Multiplies this tuple's x value with v.
 Tuple2d mulY(double v)
          Multiplies this tuple's y value with v.
static Tuple2d newReadOnly()
          Creates a new Tuple2d instance.
static Tuple2d newReadOnly(double[] values)
          Creates a new Tuple2d instance.
static Tuple2d newReadOnly(double x, double y)
          Creates a new Tuple2d instance.
static Tuple2d newReadOnly(Tuple2d tuple)
          Creates a new Tuple2d instance.
 Tuple2d scale(double factorX, double factorY)
          Sets the value of this tuple to the scalar multiplication of tuple t1.
 Tuple2d set(double x, double y)
          Sets all three values of this Tuple to the specified ones.
 Tuple2d setX(double x)
          Sets the value of the x-element of this tuple.
 Tuple2d setY(double y)
          Sets the value of the y-element of this tuple.
 Tuple2d sub(double x, double y)
          Subtracts the given parameters from this tuple's values.
 Tuple2d subX(double v)
          Subtracts v from this tuple's x value.
 Tuple2d subY(double v)
          Subtracts v from this tuple's y value.
static void toPool(Tuple2d o)
          Stores the given Tuple2d instance in the pool.
 double x()
           
 Tuple2d x(double x)
          Sets the value of the x-element of this tuple.
 double y()
           
 Tuple2d y(double y)
          Sets the value of the y-element of this tuple.
 
Methods inherited from class org.openmali.vecmath2.TupleNd
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, deserialize, div, divValue, epsilonEquals, equals, fill, get, get, getSerializationBufferSize, getSize, getValue, hashCode, interpolate, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, readExternal, round, round, scale, scale, scaleAdd, scaleAdd, serialize, set, set, setClean, setValue, setZero, sub, sub, subValue, toString, writeExternal, writeToBuffer, writeToBuffer
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 

Constructor Detail

Tuple2d

protected Tuple2d(boolean readOnly,
                  double x,
                  double y)
Creates a new Tuple2d instance.

Parameters:
readOnly -
x - the x element to use
y - the y element to use

Tuple2d

protected Tuple2d(boolean readOnly,
                  double[] values,
                  boolean[] isDirty,
                  boolean copy)
Creates a new Tuple2d instance.

Parameters:
readOnly -
values - the values array (must be at least size 2)

Tuple2d

protected Tuple2d(boolean readOnly,
                  Tuple2d that)
Creates a new Tuple2d instance.

Parameters:
readOnly -
that - the Tuple2d to copy the values from

Tuple2d

protected Tuple2d(boolean readOnly)
Creates a new Tuple2d instance.

Parameters:
readOnly -

Tuple2d

public Tuple2d(double x,
               double y)
Creates a new Tuple2d instance.

Parameters:
x - the x element to use
y - the y element to use

Tuple2d

public Tuple2d(double[] values)
Creates a new Tuple2d instance.

Parameters:
values - the values array (must be at least size 2)

Tuple2d

public Tuple2d(Tuple2d that)
Creates a new Tuple2d instance.

Parameters:
that - the Tuple2d to copy the values from

Tuple2d

public Tuple2d()
Creates a new Tuple2d instance.

Method Detail

set

public final Tuple2d set(double x,
                         double y)
Sets all three values of this Tuple to the specified ones.

Parameters:
x - the x element to use
y - the y element to use
Returns:
itself

setX

public final Tuple2d setX(double x)
Sets the value of the x-element of this tuple.

Parameters:
x -
Returns:
itself

setY

public final Tuple2d setY(double y)
Sets the value of the y-element of this tuple.

Parameters:
y -
Returns:
itself

getX

public final double getX()
Returns:
the value of the x-element of this tuple.

getY

public final double getY()
Returns:
the value of the y-element of this tuple.

x

public final Tuple2d x(double x)
Sets the value of the x-element of this tuple.

Parameters:
x -
Returns:
itself

y

public final Tuple2d y(double y)
Sets the value of the y-element of this tuple.

Parameters:
y -
Returns:
itself

x

public final double x()
Returns:
the value of the x-element of this tuple.

y

public final double y()
Returns:
the value of the y-element of this tuple.

addX

public final Tuple2d addX(double v)
Adds v to this tuple's x value.

Parameters:
v -
Returns:
itself

addY

public final Tuple2d addY(double v)
Adds v to this tuple's y value.

Parameters:
v -
Returns:
itself

add

public final Tuple2d add(double x,
                         double y)
Adds the given parameters to this tuple's values.

Parameters:
x -
y -
Returns:
itself

subX

public final Tuple2d subX(double v)
Subtracts v from this tuple's x value.

Parameters:
v -
Returns:
itself

subY

public final Tuple2d subY(double v)
Subtracts v from this tuple's y value.

Parameters:
v -
Returns:
itself

sub

public final Tuple2d sub(double x,
                         double y)
Subtracts the given parameters from this tuple's values.

Parameters:
x -
y -
Returns:
itself

mulX

public final Tuple2d mulX(double v)
Multiplies this tuple's x value with v.

Parameters:
v -
Returns:
itself

mulY

public final Tuple2d mulY(double v)
Multiplies this tuple's y value with v.

Parameters:
v -
Returns:
itself

mul

public final Tuple2d mul(double vx,
                         double vy)
Multiplies this tuple's values with vx, vy.

Parameters:
vx -
vy -
Returns:
itself

divX

public final Tuple2d divX(double v)
Divides this tuple's x value by v.

Parameters:
v -
Returns:
itself

divY

public final Tuple2d divY(double v)
Divides this tuple's y value by v.

Parameters:
v -
Returns:
itself

div

public final Tuple2d div(double vx,
                         double vy)
Divides this tuple's values by vx, vy, vz.

Parameters:
vx -
vy -
Returns:
itself

scale

public final Tuple2d scale(double factorX,
                           double factorY)
Sets the value of this tuple to the scalar multiplication of tuple t1.

Parameters:
factorX -
factorY -
Returns:
itself

asReadOnly

public Tuple2d asReadOnly()

Specified by:
asReadOnly in class TupleNd<Tuple2d>
Returns:
a new instance sharing the values array with this instance. The new instance is read-only. Changes to this instance will be reflected in the new read-only-instance.
See Also:
TupleNd.getReadOnly()

getReadOnly

public Tuple2d getReadOnly()

Specified by:
getReadOnly in class TupleNd<Tuple2d>
Returns:
a single instance sharing the values array with this instance (one unique instance per 'master-instance'). The instance is read-only. Changes to this instance will be reflected in the read-only-instance.
See Also:
TupleNd.asReadOnly()

equals

public boolean equals(java.lang.Object tuple2)
Returns true if the Object t1 is of type Tuple3d and all of the data members of t1 are equal to the corresponding data members in this Tuple2d.

Overrides:
equals in class TupleNd<Tuple2d>
Parameters:
tuple2 - the Object with which the comparison is made
Returns:
true or false

clone

public Tuple2d clone()
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

newReadOnly

public static Tuple2d newReadOnly(double x,
                                  double y)
Creates a new Tuple2d instance.

Parameters:
x - the x element to use
y - the y element to use

newReadOnly

public static Tuple2d newReadOnly(double[] values)
Creates a new Tuple2d instance.

Parameters:
values - the values array (must be at least size 2)

newReadOnly

public static Tuple2d newReadOnly(Tuple2d tuple)
Creates a new Tuple2d instance.

Parameters:
tuple - the Tuple2d to copy the values from

newReadOnly

public static Tuple2d newReadOnly()
Creates a new Tuple2d instance.


fromPool

public static Tuple2d fromPool()
Allocates an Tuple2d instance from the pool.


fromPool

public static Tuple2d fromPool(double x,
                               double y)
Allocates an Tuple2d instance from the pool.


fromPool

public static Tuple2d fromPool(Tuple2d tuple)
Allocates an Tuple2d instance from the pool.


toPool

public static void toPool(Tuple2d o)
Stores the given Tuple2d instance in the pool.

Parameters:
o -