Class TGPoint

java.lang.Object
  extended by TGPoint
All Implemented Interfaces:
java.lang.Cloneable

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

A TGPoint is a virtual point, a point in TurtleSpace. In TurtleSpace, 0.0,0.0 is at the center of the graphics canvas, like the way coordinate spaces are represented in Algebra. Likewise, TGPoints have appoximated real number coordinates. TGPoints may or may not be visible based upon the current size of the graphics canvas window of TG. Methods are provided to map the point's coordinates from TurtleSpace to an Image's x and y indicies.

TurtleGraphics now works entirely with TGPoints - points in TurtleSpace. Early versions of TG used int primitive values for X and Y coordinates. This approach led to too many visual problems caused by the propagation of rounding off values. TGPoint isolates actual implementation of points to one place which can thus be more easily controlled.


Field Summary
 double x
          This TGPoint's X coordinate.
 double y
          This TGPoint's Y coordinate.
 
Constructor Summary
TGPoint()
          Default TGPoint is [0,0] which is the center of TurtleSpace.
TGPoint(double x, double y)
          Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided double values for x and y coordinates.
TGPoint(float x, float y)
          Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided float values for x and y coordinates.
TGPoint(int x, int y)
          Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided int values for x and y coordinates.
TGPoint(long x, long y)
          Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided long values for x and y coordinates.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this TGPoint.
 boolean equals(java.lang.Object obj)
          Override Object.equals(Object) so that comparison is based on the x and y fields.
 double imageX(double imageWidth)
          Return an Image's index equivilent for this point's X coordinate.
 int imageX(double offset, int imageWidth)
          Return an Image's index equivilent for this point's X coordinate combined with a provided offset.
 int imageX(int imageWidth)
          Return an Image's index equivilent for this point's X coordinate.
 double imageY(double imageHeight)
          Return an Image's index equivilent for this point's Y coordinate.
 int imageY(double offset, int imageHeight)
          Return an Image's index equivilent for this point's Y coordinate combined with a provided offset.
 int imageY(int imageHeight)
          Return an Image's index equivilent for this point's Y coordinate.
 TGPoint otherEndPoint(double radians, double length)
          Given one end point of a line, its length and heading (in radians), return its other end point.
 java.lang.String toString()
          Returns the String representation of this point.
 double xDoubleValue()
          Returns the X coordinate of this point in double precision.
 long xLongValue()
          Returns the X coordinate of this point as a long int.
 double yDoubleValue()
          Returns the Y coordinate of this point in double precision.
 long yLongValue()
          Returns the Y coordinate of this point as a long int.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public final double x
This TGPoint's X coordinate.


y

public final double y
This TGPoint's Y coordinate.

Constructor Detail

TGPoint

public TGPoint()
Default TGPoint is [0,0] which is the center of TurtleSpace.


TGPoint

public TGPoint(double x,
               double y)
Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided double values for x and y coordinates.


TGPoint

public TGPoint(float x,
               float y)
Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided float values for x and y coordinates.


TGPoint

public TGPoint(int x,
               int y)
Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided int values for x and y coordinates.


TGPoint

public TGPoint(long x,
               long y)
Constructs a new TGPoint (a virtual point in TurtleSpace) based upon provided long values for x and y coordinates.

Method Detail

equals

public boolean equals(java.lang.Object obj)
Override Object.equals(Object) so that comparison is based on the x and y fields.

Overrides:
equals in class java.lang.Object

imageX

public double imageX(double imageWidth)
Return an Image's index equivilent for this point's X coordinate. The index reflects a mapping based on a provided Image width.


imageX

public int imageX(int imageWidth)
Return an Image's index equivilent for this point's X coordinate. The index reflects a mapping based on a provided Image width.


imageX

public int imageX(double offset,
                  int imageWidth)
Return an Image's index equivilent for this point's X coordinate combined with a provided offset. The index reflects a mapping based on a provided Image width.


imageY

public double imageY(double imageHeight)
Return an Image's index equivilent for this point's Y coordinate. The index reflects a mapping based on a provided Image height.


imageY

public int imageY(int imageHeight)
Return an Image's index equivilent for this point's Y coordinate. The index reflects a mapping based on a provided Image height.


imageY

public int imageY(double offset,
                  int imageHeight)
Return an Image's index equivilent for this point's Y coordinate combined with a provided offset. The index reflects a mapping based on a provided Image height.


clone

public java.lang.Object clone()
Creates and returns a copy of this TGPoint.

Overrides:
clone in class java.lang.Object

otherEndPoint

public TGPoint otherEndPoint(double radians,
                             double length)
Given one end point of a line, its length and heading (in radians), return its other end point. The idea of rounding deltaX and deltaY to zero when close came from Berkeley Logo - absolutely necessary to make graphics look pretty


xDoubleValue

public double xDoubleValue()
Returns the X coordinate of this point in double precision.


xLongValue

public long xLongValue()
Returns the X coordinate of this point as a long int.


yDoubleValue

public double yDoubleValue()
Returns the Y coordinate of this point in double precision.


yLongValue

public long yLongValue()
Returns the Y coordinate of this point as a long int.


toString

public java.lang.String toString()
Returns the String representation of this point. The coordinates are enclosed in eliptical brackets and separated with a comma.

Overrides:
toString in class java.lang.Object