colony.common
Class MapPoint

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

public class MapPoint
extends Object
implements java.io.Serializable

Two-dimensional point on a map.

See Also:
Serialized Form
Specification Fields

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().
 void scale(double scale)
          Multiplies both the x and y coordinates by the scalar parameter.
 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.

Modifies:
x, y

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.
Modifies:
x, y

MapPoint

public MapPoint(MapPoint p)
Copy constructor.

Parameters:
p - MapPoint with coordinates to copy.
Requires:
p != null
Modifies:
x, y
Method Detail

distanceTo

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

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.
Requires:
p != null

init

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

Modifies:
x,y

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.
Requires:
p1,p2 != null, p1.x < p2.x, p1.y < p2.y

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.
Requires:
string != null

scale

public void scale(double scale)
Multiplies both the x and y coordinates by the scalar parameter.


subtract

public MapPoint subtract(MapPoint p)
Returns a new MapPoint which is the difference between this and the parameter.

Requires:
p != null

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.