civquest.util
Class Coordinate

java.lang.Object
  extended bycivquest.util.Coordinate
All Implemented Interfaces:
java.lang.Cloneable

public class Coordinate
extends java.lang.Object
implements java.lang.Cloneable

This class represents one coordinate (x,y) in 2d-space. It uses int-values and supplies functions for comparing coordinates and for performing some basic calculations (like adding another coordinate) on them. The coordinate-values are saved in x,y. These fields are public for convenience (and because you can't do anything wrong with these values). Note that all calculation-functions return NEW Coordinate-objects.


Field Summary
 int x
          The x-coordinate.
 int y
          The y-coordinate.
 
Constructor Summary
Coordinate()
          Constructs a new Coordinate with values (0,0)
Coordinate(java.awt.geom.Dimension2D dimension)
           
Coordinate(double x, double y)
           
Coordinate(int nx, int ny)
          Constructs a new Coordinate with values (nx,ny)
Coordinate(java.awt.geom.Point2D point)
           
 
Method Summary
 Coordinate add(Coordinate oc)
          Returns a new Coordinate-object with coordinates (x+oc.x,y+oc.y)
 Coordinate add(int xv, int yv)
          Returns a new Coordinate-object with coordinates (x+xv,y+yv)
 java.lang.Object clone()
          Returns a new Coordinate-object with the same coordinate-values as this one.
 boolean equals(Coordinate c)
          Returns if this Coordinate has the same values as Coordinate c
 boolean equals(int ox, int oy)
          Returns if this Coordinate has values (ox,oy)
 double getDistanceTo(Coordinate coord)
          Returns the (euklidian) distance between this Coordinate and the given Coordinate.
 Coordinate[] getNeighborCoords()
          Returns an array with all coordinates that adjust this coordinate (including diagonal adjusting coordinates).
 Coordinate mult(Coordinate v)
          Returns a new Coordinate-object w = this * v, where * is the standard scalar product
 Coordinate mult(double v)
           
 Coordinate mult(int v)
          Returns a new Coordinate-object with coordinates (x*v,y*v)
 void set(java.awt.geom.Dimension2D dimension)
           
 void set(int nx, int ny)
          Sets the coordinate to values (nx,ny)
 void set(java.awt.geom.Point2D point)
           
 Coordinate sub(Coordinate oc)
          Returns a new Coordinate-object with coordinates (x-oc.x,y-oc.y)
 Coordinate sub(int xv, int yv)
          Returns a new Coordinate-object with coordinates (x-xv,y-yv)
 java.lang.String toString()
          Returns a String with the coordinate-pair of this Coordinate-object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x
The x-coordinate.


y

public int y
The y-coordinate.

Constructor Detail

Coordinate

public Coordinate()
Constructs a new Coordinate with values (0,0)


Coordinate

public Coordinate(java.awt.geom.Point2D point)

Coordinate

public Coordinate(java.awt.geom.Dimension2D dimension)

Coordinate

public Coordinate(int nx,
                  int ny)
Constructs a new Coordinate with values (nx,ny)

Parameters:
nx - the new x-coordinate
ny - the new y-coordinate

Coordinate

public Coordinate(double x,
                  double y)
Method Detail

set

public void set(int nx,
                int ny)
Sets the coordinate to values (nx,ny)

Parameters:
nx - the new x-coordinate
ny - the new y-coordinate

set

public void set(java.awt.geom.Point2D point)

set

public void set(java.awt.geom.Dimension2D dimension)

equals

public boolean equals(int ox,
                      int oy)
Returns if this Coordinate has values (ox,oy)


equals

public boolean equals(Coordinate c)
Returns if this Coordinate has the same values as Coordinate c


clone

public java.lang.Object clone()
Returns a new Coordinate-object with the same coordinate-values as this one.


sub

public Coordinate sub(Coordinate oc)
Returns a new Coordinate-object with coordinates (x-oc.x,y-oc.y)


sub

public Coordinate sub(int xv,
                      int yv)
Returns a new Coordinate-object with coordinates (x-xv,y-yv)


add

public Coordinate add(Coordinate oc)
Returns a new Coordinate-object with coordinates (x+oc.x,y+oc.y)


add

public Coordinate add(int xv,
                      int yv)
Returns a new Coordinate-object with coordinates (x+xv,y+yv)


mult

public Coordinate mult(int v)
Returns a new Coordinate-object with coordinates (x*v,y*v)


mult

public Coordinate mult(double v)

mult

public Coordinate mult(Coordinate v)
Returns a new Coordinate-object w = this * v, where * is the standard scalar product


toString

public java.lang.String toString()
Returns a String with the coordinate-pair of this Coordinate-object.


getNeighborCoords

public Coordinate[] getNeighborCoords()
Returns an array with all coordinates that adjust this coordinate (including diagonal adjusting coordinates). They are saved in the order NW, N, NE, E, SE, S, SW, W


getDistanceTo

public double getDistanceTo(Coordinate coord)
Returns the (euklidian) distance between this Coordinate and the given Coordinate.