gishur.graph.gui
Class FloatPoint

java.lang.Object
  |
  +--gishur.graph.gui.FloatPoint
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, ControlledCloneable, java.io.Serializable

public class FloatPoint
extends java.lang.Object
implements java.io.Serializable, ControlledCloneable

Class representing a point with float coordinates.

Version:
1.0
Author:
Christoph Sachse
See Also:
Serialized Form

Field Summary
static float IDENTICAL
          The minimal distance between two points which allows to say that they are 'different'.
 float x
          The coordinates.
 float y
          The coordinates.
 
Fields inherited from interface gishur.core.ControlledCloneable
DEEP, FLAT
 
Constructor Summary
FloatPoint()
          Empty constructor setting the coordinate to 0,0.
FloatPoint(double x, double y)
          Constructor accepting two double numbers as coordinates.
FloatPoint(float x, float y)
          Constructor accepting two float numbers as coordinates.
FloatPoint(FloatPoint fp1, FloatPoint fp2)
          Creates a new FloatPoint which lies on the middle point of the line between fp1 and fp2.
FloatPoint(int xc, int yc)
          Constructor accepting two int numbers as coordinates.
FloatPoint(java.awt.Point p)
          Constructor accepting a java.awt.Point as argument.
 
Method Summary
 java.lang.Object clone()
          Creates a new object of the same class as this object.
 java.lang.Object clone(java.util.Hashtable h, int level)
          Clones this object.
static FloatPoint copy(FloatPoint fp)
          Creates a new FloatPoint with fp's coordinates.
 boolean equals(float x, float y)
          Interprets x and y as coordinates and checks, if they differ less than IDENTICAL from this points coordinates.
 boolean equals(java.lang.Object o)
          Checks, if two FloatPoints are equal, i.e.
 float norm()
          Returns the length of this point's coordinate vector as a float number.
 void normalize()
          Normalizes the coordinate vector.
 java.awt.Point point()
          Returns this FloatPoint's coordinates casted to a java.awt.Point.
 void set(float x, float y)
          Sets this FloatPoint's coordinates to the specified values.
 void setLength(float length)
          Sets the length of the coordinate vector (keeping the angle unchanged), e.g.
 void setPolar(float angle, float length)
          Sets the point to the specified polar coordinates.
 java.lang.String toString()
          Overrides the java.lang.Object.toString()-method.
 java.lang.String toString(boolean brackets)
          Same as toString(), but with optional brackets around.
 void transform(double m00, double m01, double m02, double m10, double m11, double m12)
          Transforms this FloatPoint by the given affine transformation matrix.
 void translatePolar(float angle, float length)
          Translates the point by the vector represeted by angle and length.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTICAL

public static final float IDENTICAL
The minimal distance between two points which allows to say that they are 'different'. Often used for rounding.

x

public float x
The coordinates.

y

public float y
The coordinates.
Constructor Detail

FloatPoint

public FloatPoint()
Empty constructor setting the coordinate to 0,0.

FloatPoint

public FloatPoint(float x,
                  float y)
Constructor accepting two float numbers as coordinates.
Parameters:
x - the x-coordinate
y - the y-coordinate

FloatPoint

public FloatPoint(double x,
                  double y)
Constructor accepting two double numbers as coordinates. Note that the doubles will be casted down to floats, which will cause a possible loss of data.
Parameters:
x - the x-coordinate
y - the y-coordinate

FloatPoint

public FloatPoint(int xc,
                  int yc)
Constructor accepting two int numbers as coordinates. The ints will be casted up to floats, that is possible without a loss of data.
Parameters:
x - the x-coordinate
y - the y-coordinate

FloatPoint

public FloatPoint(java.awt.Point p)
Constructor accepting a java.awt.Point as argument. The Point's (int) coordinates will be casted to floats and will become the FloatPoint's new coordinates.
Parameters:
x - the x-coordinate
y - the y-coordinate

FloatPoint

public FloatPoint(FloatPoint fp1,
                  FloatPoint fp2)
Creates a new FloatPoint which lies on the middle point of the line between fp1 and fp2.
Parameters:
fp1,fp2 - two FloatPoints
Method Detail

copy

public static FloatPoint copy(FloatPoint fp)
Creates a new FloatPoint with fp's coordinates.
Parameters:
fp - the FloatPoint to copy
Returns:
a new FloatPoint with the same coordinates

toString

public java.lang.String toString()
Overrides the java.lang.Object.toString()-method.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the form x,y

toString

public java.lang.String toString(boolean brackets)
Same as toString(), but with optional brackets around.
Parameters:
brackets - if true a String of the form (x,y) will be returned, otherwise a String like x,y
Returns:
a string representation of the point

equals

public boolean equals(java.lang.Object o)
Checks, if two FloatPoints are equal, i.e. o==this, or their coordinates differ less than IDENTICAL. If o==null, or o is no FloatPoint, false will be returned. Overrides java.lang.Object.equals(Object).
Overrides:
equals in class java.lang.Object
Parameters:
o - the object to check for equality with this
Returns:
true, if o==this, or their coordinates differ less than IDENTICAL

equals

public boolean equals(float x,
                      float y)
Interprets x and y as coordinates and checks, if they differ less than IDENTICAL from this points coordinates.
Parameters:
x,y - two float coordinates
Returns:
true, if they differ less than IDENTICAL from this points coordinates, false otherwise

point

public java.awt.Point point()
Returns this FloatPoint's coordinates casted to a java.awt.Point. Note that this causes a loss of precision, as a Point's coordinates are ints.
Returns:
the coordinates as a java.awt.Point

set

public void set(float x,
                float y)
Sets this FloatPoint's coordinates to the specified values.
Parameters:
x,y - the new coordinate values

setPolar

public void setPolar(float angle,
                     float length)
Sets the point to the specified polar coordinates.
Parameters:
angle - the angle between polar coordinates vector and the x-axis
the - length of the polar coordinates vector

setLength

public void setLength(float length)
Sets the length of the coordinate vector (keeping the angle unchanged), e.g. setLength(1) normalizes the vector. If the coordinates are 0,0, the method returns effectiveless.
Parameters:
length - the new length of the coordinates vector

translatePolar

public void translatePolar(float angle,
                           float length)
Translates the point by the vector represeted by angle and length.
Parameters:
angle - the angle of the translation vector
length - the length of the translation vector

normalize

public void normalize()
Normalizes the coordinate vector.

norm

public float norm()
Returns the length of this point's coordinate vector as a float number.
Returns:
the length of the coordinate vector

transform

public void transform(double m00,
                      double m01,
                      double m02,
                      double m10,
                      double m11,
                      double m12)
Transforms this FloatPoint by the given affine transformation matrix.
Parameters:
m00,m01,m02 - first row of the transformation matrix
m10,m11,m12 - second row of the transformation matrix

clone

public java.lang.Object clone()
Creates a new object of the same class as this object. It then initializes each of the new object's fields by assigning it the same value as the corresponding field in this object. No constructor is called. In some Implementations, the fields are cloned, if possible (deep clone).
Specified by:
clone in interface Cloneable
Overrides:
clone in class java.lang.Object
Returns:
a clone of this object.

clone

public java.lang.Object clone(java.util.Hashtable h,
                              int level)
Clones this object. According to the parameter level, this object will be cloned down to level levels. That means, the object will be cloned. If level==-1(==DEEP), every object, which can be reached by traversing the references beginning with /this object will be cloned if possible. This recursion stopps, if there are no more object to clone, or no reachable object implements Cloneable. If level==0(==FLAT), no object contained by this object will be cloned. Only the references will be maintained. If level>=1, the recursion will stopp after cloning level generations (or earlier if e.g. no more contained objects are cloneable).
The recursive cloning stopps, if there's a ring structure. In this case, all Objects implementing Cloneable are cloned, and connected proper, so that even ring structures are cloned as rings.
Specified by:
clone in interface ControlledCloneable
Parameters:
h - Hastable which containes all objects already cloned (with their original objects as keys), to avoid multiple cloning of the same object (if h==null a new Hashtable will be created - you can use null to start a clone recursion)
level - indicates how many generations should be cloned recursive at most
Returns:
the cloned Object
Throws:
InternalError - - if the Object could not be cloned properly