acm.graphics
Class GPoint

java.lang.Object
  extended by acm.graphics.GPoint
All Implemented Interfaces:
Serializable

public class GPoint
extends Object
implements Serializable

This class is a double-precision version of the Point class in java.awt.

See Also:
Serialized Form

Constructor Summary
GPoint()
          Constructs a new GPoint at the origin (0, 0).
GPoint(double x, double y)
          Constructs a new GPoint with the specified coordinates.
GPoint(GPoint p)
          Constructs a new GPoint from an existing one.
GPoint(Point p)
          Constructs a new GPoint from an existing AWT Point.
 
Method Summary
 boolean equals(Object obj)
          Tests whether two GPoint objects are equal.
 GPoint getLocation()
          Returns a new GPoint whose coordinates are the same as this one.
 double getX()
          Returns the x coordinate of this GPoint.
 double getY()
          Returns the y coordinate of this GPoint.
 int hashCode()
          Returns an integer hash code for the point.
 void setLocation(double x, double y)
          Sets the location of the GPoint to the specified x and y values.
 void setLocation(GPoint p)
          Sets the location of the GPoint to that of an existing one.
 Point toPoint()
          Converts this GPoint to the nearest integer-based Point.
 String toString()
          Converts this GPoint to its string representation.
 void translate(double dx, double dy)
          Adjusts the coordinates of a point by the specified dx and dy offsets.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GPoint

public GPoint()
Constructs a new GPoint at the origin (0, 0).


GPoint

public GPoint(double x,
              double y)
Constructs a new GPoint with the specified coordinates.

Parameters:
x - The x-coordinate of the point
y - The y-coordinate of the point

GPoint

public GPoint(GPoint p)
Constructs a new GPoint from an existing one.

Parameters:
p - The original point

GPoint

public GPoint(Point p)
Constructs a new GPoint from an existing AWT Point.

Parameters:
p - An AWT Point
Method Detail

equals

public boolean equals(Object obj)
Tests whether two GPoint objects are equal. Because floating-point values are inexact, this method checks for equality by comparing the float values (rather than the double values) of the coordinates.

Overrides:
equals in class Object
Parameters:
obj - Any object
Returns:
true if the obj is a GPoint equal to this one, and false otherwise

getLocation

public GPoint getLocation()
Returns a new GPoint whose coordinates are the same as this one.

Returns:
A new point with the same coordinates

getX

public double getX()
Returns the x coordinate of this GPoint.

Returns:
The x coordinate of this GPoint

getY

public double getY()
Returns the y coordinate of this GPoint.

Returns:
The y coordinate of this GPoint

hashCode

public int hashCode()
Returns an integer hash code for the point. The hash code for a GPoint is constructed from the hash codes from the float values of the coordinates, which are the ones used in the equals method.

Overrides:
hashCode in class Object
Returns:
The hash code for this pt

setLocation

public void setLocation(double x,
                        double y)
Sets the location of the GPoint to the specified x and y values.

Parameters:
x - The new x-coordinate for the point
y - The new y-coordinate for the point

setLocation

public void setLocation(GPoint p)
Sets the location of the GPoint to that of an existing one.

Parameters:
p - An existing GPoint specifying the new location

toPoint

public Point toPoint()
Converts this GPoint to the nearest integer-based Point.

Returns:
The closest integer-based Point

toString

public String toString()
Converts this GPoint to its string representation.

Overrides:
toString in class Object
Returns:
A string representation of this point

translate

public void translate(double dx,
                      double dy)
Adjusts the coordinates of a point by the specified dx and dy offsets.

Parameters:
dx - The change in the x direction (positive is rightward)
dy - The change in the y direction (positive is downward)