org.openmali.vecmath2
Class Point2d

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

public class Point2d
extends Tuple2d
implements java.io.Externalizable

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

See Also:
Serialized Form

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

Point2d

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

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

Point2d

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

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

Point2d

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

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

Point2d

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

Parameters:
readOnly -

Point2d

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

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

Point2d

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

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

Point2d

public Point2d(Tuple2d tuple)
Creates a new Point2d instance.

Parameters:
tuple - the Tuple2d to copy the values from

Point2d

public Point2d()
Creates a new Point2d instance.

Method Detail

distanceSquared

public final double distanceSquared(Point2d point2)


distance

public final double distance(Point2d point2)


distanceSquared

public final double distanceSquared(double p2x,
                                    double p2y)

distance

public final double distance(double p2x,
                             double p2y)

distanceToOriginSquared

public final double distanceToOriginSquared()


distanceToOrigin

public double distanceToOrigin()


distanceL1

public final double distanceL1(Point2d 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 double distanceLinf(Point2d 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

asReadOnly

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

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

newReadOnly

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

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

newReadOnly

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

Parameters:
tuple - the Tuple2d to copy the values from

newReadOnly

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


fromPool

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


fromPool

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


fromPool

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


toPool

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

Parameters:
o -