org.openmali.vecmath2
Class Vector2f

java.lang.Object
  extended by org.openmali.vecmath2.TupleNf<Tuple2f>
      extended by org.openmali.vecmath2.Tuple2f
          extended by org.openmali.vecmath2.Vector2f
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, TupleInterface<Tuple2f>, VectorInterface<Tuple2f,Vector2f>

public class Vector2f
extends Tuple2f
implements java.io.Externalizable, VectorInterface<Tuple2f,Vector2f>

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

See Also:
Serialized Form

Field Summary
static Vector2f NEGATIVE_X_AXIS
           
static Vector2f NEGATIVE_Y_AXIS
           
static Vector2f POSITIVE_X_AXIS
           
static Vector2f POSITIVE_Y_AXIS
           
static Vector2f ZERO
           
 
Fields inherited from class org.openmali.vecmath2.TupleNf
isDirty, roTrick, values
 
Constructor Summary
  Vector2f()
          Constructs and initializes a Vector2f to (0,0).
protected Vector2f(boolean readOnly)
          Constructs and initializes a Vector2f to (0,0).
protected Vector2f(boolean readOnly, float[] values, boolean[] isDirty, boolean copy)
          Constructs and initializes a Vector2f from the specified array.
protected Vector2f(boolean readOnly, float x, float y)
          Constructs and initializes a Vector2f from the specified xy coordinates.
protected Vector2f(boolean readOnly, Tuple2f tuple)
          Constructs and initializes a Vector2f from the specified Tuple2f.
  Vector2f(float[] values)
          Constructs and initializes a Vector2f from the specified array.
  Vector2f(float x, float y)
          Constructs and initializes a Vector2f from the specified xy coordinates.
  Vector2f(Tuple2f tuple)
          Constructs and initializes a Vector2f from the specified Tuple2f.
 
Method Summary
 float angle(Vector2f v2)
          Returns the angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].
 Vector2f asReadOnly()
          
 Vector2f clone()
          Creates and returns a copy of this object.
 Vector2f cross(Vector2f v1, Vector2f v2)
          Sets this vector to be the vector cross product of vectors v1 and v2.
 float dot(Vector2f v2)
          Computes the dot product of the this vector and vector v2.
static Vector2f fromPool()
          Allocates an Vector2f instance from the pool.
static Vector2f fromPool(float x, float y)
          Allocates an Vector2f instance from the pool.
static Vector2f fromPool(Tuple2f tuple)
          Allocates an Vector2f instance from the pool.
 Vector2f getReadOnly()
          
 float length()
          
 float lengthSquared()
          
static Vector2f newReadOnly()
          Constructs and initializes a Vector2f to (0,0).
static Vector2f newReadOnly(float[] values)
          Constructs and initializes a Vector2f from the specified array.
static Vector2f newReadOnly(float x, float y)
          Constructs and initializes a Vector2f from the specified xy coordinates.
static Vector2f newReadOnly(Tuple2f tuple)
          Constructs and initializes a Vector2f from the specified Tuple2f.
 Vector2f normalize()
          Normalizes this vector in place.
 Vector2f normalize(Vector2f vector)
          Sets the value of this vector to the normalization of vector v1.
static void toPool(Vector2f o)
          Stores the given Vector2f instance in the pool.
 
Methods inherited from class org.openmali.vecmath2.Tuple2f
add, addX, addY, 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.TupleNf
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, deserialize, div, divValue, epsilonEquals, equals, fill, get, get, get, getSerializationBufferSize, getSize, getValue, hashCode, interpolate, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, readExternal, readFromBuffer, readFromBuffer, readFromBuffer, readFromBuffer, round, round, scale, scale, scaleAdd, scaleAdd, serialize, set, set, set, setClean, setValue, setZero, sub, sub, subValue, toString, writeExternal, writeToBuffer, writeToBuffer, 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
 
Methods inherited from interface org.openmali.vecmath2.TupleInterface
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, div, divValue, epsilonEquals, fill, get, get, get, getSize, getValue, interpolate, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, round, round, scale, scale, scaleAdd, scaleAdd, set, set, set, setClean, setValue, setZero, sub, sub, subValue
 

Field Detail

ZERO

public static final Vector2f ZERO

POSITIVE_X_AXIS

public static final Vector2f POSITIVE_X_AXIS

NEGATIVE_X_AXIS

public static final Vector2f NEGATIVE_X_AXIS

POSITIVE_Y_AXIS

public static final Vector2f POSITIVE_Y_AXIS

NEGATIVE_Y_AXIS

public static final Vector2f NEGATIVE_Y_AXIS
Constructor Detail

Vector2f

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

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

Vector2f

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

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

Vector2f

protected Vector2f(boolean readOnly,
                   Tuple2f tuple)
Constructs and initializes a Vector2f from the specified Tuple2f.

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

Vector2f

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

Parameters:
readOnly -

Vector2f

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

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

Vector2f

public Vector2f(float[] values)
Constructs and initializes a Vector2f from the specified array.

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

Vector2f

public Vector2f(Tuple2f tuple)
Constructs and initializes a Vector2f from the specified Tuple2f.

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

Vector2f

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

Method Detail

lengthSquared

public final float lengthSquared()

Specified by:
lengthSquared in interface VectorInterface<Tuple2f,Vector2f>
Returns:
the squared length of this vector

length

public final float length()

Specified by:
length in interface VectorInterface<Tuple2f,Vector2f>
Returns:
the length of this vector

normalize

public final Vector2f normalize()
Normalizes this vector in place.

Specified by:
normalize in interface VectorInterface<Tuple2f,Vector2f>
Returns:
itself

normalize

public final Vector2f normalize(Vector2f vector)
Sets the value of this vector to the normalization of vector v1.

Specified by:
normalize in interface VectorInterface<Tuple2f,Vector2f>
Parameters:
vector - the un-normalized vector
Returns:
itself

cross

public final Vector2f cross(Vector2f v1,
                            Vector2f v2)
Sets this vector to be the vector cross product of vectors v1 and v2.

Specified by:
cross in interface VectorInterface<Tuple2f,Vector2f>
Parameters:
v1 - the first vector
v2 - the second vector
Returns:
itself

dot

public final float dot(Vector2f v2)
Computes the dot product of the this vector and vector v2.

Specified by:
dot in interface VectorInterface<Tuple2f,Vector2f>
Parameters:
v2 - the other vector

angle

public final float angle(Vector2f v2)
Returns the angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].

Specified by:
angle in interface VectorInterface<Tuple2f,Vector2f>
Parameters:
v2 - the other vector
Returns:
the angle in radians in the range [0,PI]

clone

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

Overrides:
clone in class Tuple2f
Returns:
a clone of this instance.
See Also:
Cloneable

asReadOnly

public Vector2f asReadOnly()

Overrides:
asReadOnly in class Tuple2f
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:
TupleNf.getReadOnly()

getReadOnly

public Vector2f getReadOnly()

Overrides:
getReadOnly in class Tuple2f
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:
TupleNf.asReadOnly()

newReadOnly

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

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

newReadOnly

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

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

newReadOnly

public static Vector2f newReadOnly(Tuple2f tuple)
Constructs and initializes a Vector2f from the specified Tuple2f.

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

newReadOnly

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


fromPool

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


fromPool

public static Vector2f fromPool(float x,
                                float y)
Allocates an Vector2f instance from the pool.


fromPool

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


toPool

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

Parameters:
o -