edu.colorado.geometry
Class Location

java.lang.Object
  |
  +--edu.colorado.geometry.Location

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

A Location object keeps track of a location on a two-dimensional plane.

Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/geometry/Location.java


Constructor Summary
Location(double xInitial, double yInitial)
          Construct a Location with specified coordinates.
 
Method Summary
 java.lang.Object clone()
          Generate a copy of this Location.
static double distance(Location p1, Location p2)
          Compute the distance between two Locations.
 boolean equals(java.lang.Object obj)
          Compare this Location to another object for equality.
 double getX()
          Get the x coordinate of this Location.
 double getY()
          Get the y coordinate of this Location.
static Location midpoint(Location p1, Location p2)
          Generate and return a Location halfway between two others.
 void rotate90()
          Rotate this Location 90 degrees in a clockwise direction.
 void shift(double xAmount, double yAmount)
          Move this Location by given amounts along the x and y axes.
 java.lang.String toString()
          Generate a String representation of this Location.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Location

public Location(double xInitial,
                double yInitial)
Construct a Location with specified coordinates.
Parameters:
xInitial - the initial x coordinate of this Location
yInitial - the initial y coordinate of this Location
Postcondition:
This Location has been initialized at the given coordinates.
Method Detail

clone

public java.lang.Object clone()
Generate a copy of this Location.
Parameters:
- - none
Returns:
The return value is a copy of this Location. Subsequent changes to the copy will not affect the original, nor vice versa. Note that the return value must be typecast to a Location before it can be used.
Overrides:
clone in class java.lang.Object

distance

public static double distance(Location p1,
                              Location p2)
Compute the distance between two Locations.
Parameters:
p1 - the first Location
p2 - the second Location
Returns:
the distance between p1 and p2
Note:
The answer is Double.POSITIVE_INFINITY if the distance calculation overflows. The answer is Double.NaN if either Location is null.

equals

public boolean equals(java.lang.Object obj)
Compare this Location to another object for equality.
Parameters:
obj - an object with which this Location will be compared
Returns:
A return value of true indicates that obj refers to a Location object with the same value as this Location. Otherwise the return value is false.
Note:
If obj is null or does not refer to a Location object, then the answer is false.
Overrides:
equals in class java.lang.Object

getX

public double getX()
Get the x coordinate of this Location.
Parameters:
- - none
Returns:
the x coordinate of this Location.

getY

public double getY()
Get the y coordinate of this Location.
Parameters:
- - none
Returns:
the y coordinate of this Location.

midpoint

public static Location midpoint(Location p1,
                                Location p2)
Generate and return a Location halfway between two others.
Parameters:
p1 - the first Location
p2 - the second Location
Returns:
a Location that is halfway between p1 and p2.
Note:
The answer is null if either p1 or p2 is null.

rotate90

public void rotate90()
Rotate this Location 90 degrees in a clockwise direction.
Parameters:
- - none
Postcondition:
This Location has been rotated clockwise 90 degrees around the origin.

shift

public void shift(double xAmount,
                  double yAmount)
Move this Location by given amounts along the x and y axes.
Parameters:
xAmount - the amount to move this Location along the x axis
yAmount - the amount to move this Location along the y axis
Postcondition:
This Location has been moved by the given amounts along the two axes.
Note:
The shift may cause a coordinate to go above Double.MAX_VALUE or below -Double.MAX_VALUE. In these cases, subsequent activations of getX or getY will return Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY.

toString

public java.lang.String toString()
Generate a String representation of this Location.
Parameters:
- - none
Returns:
a String representation of this Location
Overrides:
toString in class java.lang.Object