core
Class Coord

java.lang.Object
  extended by core.Coord
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Coord>

public class Coord
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable<Coord>

Class to hold 2D coordinates and perform simple arithmetics and transformations


Constructor Summary
Coord(double x, double y)
          Constructor.
 
Method Summary
 Coord clone()
          Returns a clone of this coordinate
 int compareTo(Coord other)
          Compares this coordinate to other coordinate.
 double distance(Coord other)
          Returns the distance to another coordinate
 boolean equals(Coord c)
          Checks if this coordinate's location is equal to other coordinate's
 boolean equals(java.lang.Object o)
           
 double getX()
          Returns the x coordinate
 double getY()
          Returns the y coordinate
 int hashCode()
          Returns a hash code for this coordinate (actually a hash of the String made of the coordinates)
 void setLocation(Coord c)
          Sets this coordinate's location to be equal to other coordinates location
 void setLocation(double x, double y)
          Sets the location of this coordinate object
 java.lang.String toString()
          Returns a text representation of the coordinate (rounded to 2 decimals)
 void translate(double dx, double dy)
          Moves the point by dx and dy
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Coord

public Coord(double x,
             double y)
Constructor.

Parameters:
x - Initial X-coordinate
y - Initial Y-coordinate
Method Detail

setLocation

public void setLocation(double x,
                        double y)
Sets the location of this coordinate object

Parameters:
x - The x coordinate to set
y - The y coordinate to set

setLocation

public void setLocation(Coord c)
Sets this coordinate's location to be equal to other coordinates location

Parameters:
c - The other coordinate

translate

public void translate(double dx,
                      double dy)
Moves the point by dx and dy

Parameters:
dx - How much to move the point in X-direction
dy - How much to move the point in Y-direction

distance

public double distance(Coord other)
Returns the distance to another coordinate

Parameters:
other - The other coordinate
Returns:
The distance between this and another coordinate

getX

public double getX()
Returns the x coordinate

Returns:
x coordinate

getY

public double getY()
Returns the y coordinate

Returns:
y coordinate

toString

public java.lang.String toString()
Returns a text representation of the coordinate (rounded to 2 decimals)

Overrides:
toString in class java.lang.Object
Returns:
a text representation of the coordinate

clone

public Coord clone()
Returns a clone of this coordinate

Overrides:
clone in class java.lang.Object

equals

public boolean equals(Coord c)
Checks if this coordinate's location is equal to other coordinate's

Parameters:
c - The other coordinate
Returns:
True if locations are the same

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code for this coordinate (actually a hash of the String made of the coordinates)

Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(Coord other)
Compares this coordinate to other coordinate. Coordinate whose y value is smaller comes first and if y values are equal, the one with smaller x value comes first.

Specified by:
compareTo in interface java.lang.Comparable<Coord>
Returns:
-1, 0 or 1 if this node is before, in the same place or after the other coordinate