colony.common
Class MapPoint

java.lang.Object
  |
  +--colony.common.MapPoint
All Implemented Interfaces:
Serializable

public class MapPoint
extends Object
implements Serializable

Two-dimensional point on a map.

See Also:
Serialized Form

Field Summary
 double x
          x-coordinate of a two-dimensional map point.
 double y
          y-coordinate of a two-dimensional map point.
 
Constructor Summary
MapPoint()
          No-arg constructor.
MapPoint(double x, double y)
          The constructor from parameters.
MapPoint(MapPoint p)
          Copy constructor.
 
Method Summary
 double distanceTo(MapPoint p)
           
 boolean equals(MapPoint p, double tolerance)
           
 void init()
          Initialises map point back to the origin.
 boolean isWithin(MapPoint p1, MapPoint p2)
          Determines if this is in the rectangle marked by the parameter p1 and p2.
static MapPoint parse(String string)
          Creates a MapPoint from a String representation following the format in toString().
 MapPoint subtract(MapPoint p)
          Returns a new MapPoint which is the difference between this and the parameter.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 

Field Detail

x

public double x
x-coordinate of a two-dimensional map point.

y

public double y
y-coordinate of a two-dimensional map point.
Constructor Detail

MapPoint

public MapPoint()
No-arg constructor.
Parameters:
x - initial x-coordinate of this map point.
y - initial y-coordinate of this map point.

MapPoint

public MapPoint(double x,
                double y)
The constructor from parameters.
Parameters:
x - initial x-coordinate of this map point.
y - initial y-coordinate of this map point.

MapPoint

public MapPoint(MapPoint p)
Copy constructor.
Parameters:
p - MapPoint with coordinates to copy.
Method Detail

distanceTo

public double distanceTo(MapPoint p)
Returns:
the straight-line distance between the parameter p and this.

equals

public boolean equals(MapPoint p,
                      double tolerance)
Returns:
true if p.x == this.x && p.y == this.y within the given tolerance. false otherwise.

init

public void init()
Initialises map point back to the origin.

isWithin

public boolean isWithin(MapPoint p1,
                        MapPoint p2)
Determines if this is in the rectangle marked by the parameter p1 and p2.
Returns:
true if (this.x > p1.x) && (this.x < p2.x) && (this.y > p1.y) && (this.y < p2.y) false otherwise.

parse

public static MapPoint parse(String string)
Creates a MapPoint from a String representation following the format in toString().
Returns:
a new MapPoint if the format is valid, null otherwise.

subtract

public MapPoint subtract(MapPoint p)
Returns a new MapPoint which is the difference between this and the parameter.
Parameters:
MapPoint - to subtract from this.

toString

public String toString()
Description copied from class: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
Overrides:
toString in class Object
Returns:
String representation of this.