org.openmali.vecmath2
Class Point2f

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

public class Point2f
extends Tuple2f
implements java.io.Externalizable, PointInterface<Tuple2f,Point2f>

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

See Also:
Serialized Form

Field Summary
static Point2f ZERO
           
 
Fields inherited from class org.openmali.vecmath2.TupleNf
isDirty, roTrick, values
 
Constructor Summary
  Point2f()
          Creates a new Point2f instance.
protected Point2f(boolean readOnly)
          Creates a new Point2f instance.
protected Point2f(boolean readOnly, float[] values, boolean[] isDirty, boolean copy)
          Creates a new Point2f instance.
protected Point2f(boolean readOnly, float x, float y)
          Creates a new Point2f instance.
protected Point2f(boolean readOnly, Tuple2f tuple)
          Creates a new Point2f instance.
  Point2f(float[] values)
          Creates a new Point2f instance.
  Point2f(float x, float y)
          Creates a new Point2f instance.
  Point2f(Tuple2f tuple)
          Creates a new Point2f instance.
 
Method Summary
 Point2f asReadOnly()
          
 Point2f clone()
          Creates and returns a copy of this object.
 float distance(float p2x, float p2y)
           
 float distance(Point2f point2)
          
 float distanceL1(Point2f point2)
          Computes the L-1 (Manhattan) distance between this point and point p1.
 float distanceLinf(Point2f point2)
          Computes the L-infinite distance between this point and point p1.
 float distanceSquared(float p2x, float p2y)
           
 float distanceSquared(Point2f point2)
          
 float distanceToOrigin()
          
 float distanceToOriginSquared()
          
static Point2f fromPool()
          Allocates an Point2f instance from the pool.
static Point2f fromPool(float x, float y)
          Allocates an Point2f instance from the pool.
static Point2f fromPool(Tuple2f tuple)
          Allocates an Point2f instance from the pool.
 Point2f getReadOnly()
          
static Point2f newReadOnly()
          Creates a new Point2f instance.
static Point2f newReadOnly(float[] values)
          Creates a new Point2f instance.
static Point2f newReadOnly(float x, float y)
          Creates a new Point2f instance.
static Point2f newReadOnly(Tuple2f tuple)
          Creates a new Point2f instance.
static void toPool(Point2f o)
          Stores the given Point2f 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 Point2f ZERO
Constructor Detail

Point2f

protected Point2f(boolean readOnly,
                  float x,
                  float y)
Creates a new Point2f instance.

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

Point2f

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

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

Point2f

protected Point2f(boolean readOnly,
                  Tuple2f tuple)
Creates a new Point2f instance.

Parameters:
readOnly -
tuple - the Tuple2f to copy the values from

Point2f

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

Parameters:
readOnly -

Point2f

public Point2f(float x,
               float y)
Creates a new Point2f instance.

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

Point2f

public Point2f(float[] values)
Creates a new Point2f instance.

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

Point2f

public Point2f(Tuple2f tuple)
Creates a new Point2f instance.

Parameters:
tuple - the Tuple2f to copy the values from

Point2f

public Point2f()
Creates a new Point2f instance.

Method Detail

distanceSquared

public final float distanceSquared(Point2f point2)

Specified by:
distanceSquared in interface PointInterface<Tuple2f,Point2f>
Returns:
the squared distance betweeen this point and the other one

distance

public final float distance(Point2f point2)

Specified by:
distance in interface PointInterface<Tuple2f,Point2f>
Returns:
the distance betweeen this point and the other one

distanceSquared

public final float distanceSquared(float p2x,
                                   float p2y)

distance

public final float distance(float p2x,
                            float p2y)

distanceToOriginSquared

public final float distanceToOriginSquared()

Specified by:
distanceToOriginSquared in interface PointInterface<Tuple2f,Point2f>
Returns:
the squared distance betweeen this point and the origin

distanceToOrigin

public float distanceToOrigin()

Specified by:
distanceToOrigin in interface PointInterface<Tuple2f,Point2f>
Returns:
the distance betweeen this point and the origin

distanceL1

public final float distanceL1(Point2f point2)
Computes the L-1 (Manhattan) distance between this point and point p1. The L-1 distance is equal to abs(x1-x2) + abs(y1-y2).

Parameters:
point2 - the other point

distanceLinf

public final float distanceLinf(Point2f point2)
Computes the L-infinite distance between this point and point p1. The L-infinite distance is equal to MAX[abs(x1-x2), abs(y1-y2)].

Parameters:
point2 - the other point

clone

public Point2f 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 Point2f 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 Point2f 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 Point2f newReadOnly(float x,
                                  float y)
Creates a new Point2f instance.

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

newReadOnly

public static Point2f newReadOnly(float[] values)
Creates a new Point2f instance.

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

newReadOnly

public static Point2f newReadOnly(Tuple2f tuple)
Creates a new Point2f instance.

Parameters:
tuple - the Tuple2f to copy the values from

newReadOnly

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


fromPool

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


fromPool

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


fromPool

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


toPool

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

Parameters:
o -