org.openmali.vecmath2
Class Vector2d

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

public class Vector2d
extends Tuple2d
implements java.io.Externalizable

A 2 element vector that is represented by single precision doubleing point x, y coordinates. Inspired by Kenji Hiranabe's Vector2d implementation

See Also:
Serialized Form

Field Summary
static Vector2d NEGATIVE_X_AXIS
           
static Vector2d NEGATIVE_Y_AXIS
           
static Vector2d POSITIVE_X_AXIS
           
static Vector2d POSITIVE_Y_AXIS
           
static Vector2d ZERO
           
 
Fields inherited from class org.openmali.vecmath2.TupleNd
isDirty, roTrick, values
 
Constructor Summary
  Vector2d()
          Constructs and initializes a Vector2d to (0,0).
protected Vector2d(boolean readOnly)
          Constructs and initializes a Vector2d to (0,0).
protected Vector2d(boolean readOnly, double[] values, boolean[] isDirty, boolean copy)
          Constructs and initializes a Vector2d from the specified array.
protected Vector2d(boolean readOnly, double x, double y)
          Constructs and initializes a Vector2d from the specified xy coordinates.
protected Vector2d(boolean readOnly, Tuple2d tuple)
          Constructs and initializes a Vector2d from the specified Tuple2d.
  Vector2d(double[] values)
          Constructs and initializes a Vector2d from the specified array.
  Vector2d(double x, double y)
          Constructs and initializes a Vector2d from the specified xy coordinates.
  Vector2d(Tuple2d tuple)
          Constructs and initializes a Vector2d from the specified Tuple2d.
 
Method Summary
 double angle(Vector2d v2)
          
 Vector2d asReadOnly()
          
 Vector2d cross(Vector2d v1, Vector2d v2)
          
 double dot(Vector2d v2)
          
static Vector2d fromPool()
          Allocates an Vector2d instance from the pool.
static Vector2d fromPool(double x, double y)
          Allocates an Vector2d instance from the pool.
static Vector2d fromPool(Tuple2d tuple)
          Allocates an Vector2d instance from the pool.
 Tuple2d getReadOnly()
          
 double length()
          
 double lengthSquared()
          
static Vector2d newReadOnly()
          Constructs and initializes a Vector2d to (0,0).
static Vector2d newReadOnly(double[] values)
          Constructs and initializes a Vector2d from the specified array.
static Vector2d newReadOnly(double x, double y)
          Constructs and initializes a Vector2d from the specified xy coordinates.
static Vector2d newReadOnly(Tuple2d tuple)
          Constructs and initializes a Vector2d from the specified Tuple2d.
 Vector2d normalize()
          
 Vector2d normalize(Vector2d vector)
          
static void toPool(Vector2d o)
          Stores the given Vector2d instance in the pool.
 
Methods inherited from class org.openmali.vecmath2.Tuple2d
add, addX, addY, clone, div, divX, divY, equals, getX, getY, mul, mulX, mulY, scale, set, setX, setY, sub, subX, subY, toPool, x, x, y, y
 
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
 

Field Detail

ZERO

public static final Vector2d ZERO

POSITIVE_X_AXIS

public static final Vector2d POSITIVE_X_AXIS

NEGATIVE_X_AXIS

public static final Vector2d NEGATIVE_X_AXIS

POSITIVE_Y_AXIS

public static final Vector2d POSITIVE_Y_AXIS

NEGATIVE_Y_AXIS

public static final Vector2d NEGATIVE_Y_AXIS
Constructor Detail

Vector2d

protected Vector2d(boolean readOnly,
                   double x,
                   double y)
Constructs and initializes a Vector2d from the specified xy coordinates.

Parameters:
readOnly -
x - the x coordinate
y - the y coordinate

Vector2d

protected Vector2d(boolean readOnly,
                   double[] values,
                   boolean[] isDirty,
                   boolean copy)
Constructs and initializes a Vector2d from the specified array.

Parameters:
readOnly -
values - the array of length 2 containing xy in order
isDirty - the isDirty-value
copy - copy the array?

Vector2d

protected Vector2d(boolean readOnly,
                   Tuple2d tuple)
Constructs and initializes a Vector2d from the specified Tuple2d.

Parameters:
readOnly -
tuple - the Tuple2d containing the initialization x y data

Vector2d

protected Vector2d(boolean readOnly)
Constructs and initializes a Vector2d to (0,0).

Parameters:
readOnly -

Vector2d

public Vector2d(double x,
                double y)
Constructs and initializes a Vector2d from the specified xy coordinates.

Parameters:
x - the x coordinate
y - the y coordinate

Vector2d

public Vector2d(double[] values)
Constructs and initializes a Vector2d from the specified array.

Parameters:
values - the array of length 2 containing xy in order

Vector2d

public Vector2d(Tuple2d tuple)
Constructs and initializes a Vector2d from the specified Tuple2d.

Parameters:
tuple - the Tuple2d containing the initialization x y data

Vector2d

public Vector2d()
Constructs and initializes a Vector2d to (0,0).

Method Detail

lengthSquared

public final double lengthSquared()


length

public final double length()


normalize

public final Vector2d normalize()


normalize

public final Vector2d normalize(Vector2d vector)


cross

public final Vector2d cross(Vector2d v1,
                            Vector2d v2)


dot

public final double dot(Vector2d v2)


angle

public final double angle(Vector2d v2)


asReadOnly

public Vector2d asReadOnly()

Overrides:
asReadOnly in class 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()

Overrides:
getReadOnly in class 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()

newReadOnly

public static Vector2d newReadOnly(double x,
                                   double y)
Constructs and initializes a Vector2d from the specified xy coordinates.

Parameters:
x - the x coordinate
y - the y coordinate

newReadOnly

public static Vector2d newReadOnly(double[] values)
Constructs and initializes a Vector2d from the specified array.

Parameters:
values - the array of length 2 containing xy in order

newReadOnly

public static Vector2d newReadOnly(Tuple2d tuple)
Constructs and initializes a Vector2d from the specified Tuple2d.

Parameters:
tuple - the Tuple2d containing the initialization x y data

newReadOnly

public static Vector2d newReadOnly()
Constructs and initializes a Vector2d to (0,0).


fromPool

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


fromPool

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


fromPool

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


toPool

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

Parameters:
o -