com.jfimagine.jfgraph.geom
Class JFPoint

java.lang.Object
  |
  +--com.jfimagine.jfgraph.geom.JFPoint
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
JFArcPoint, JFCurvePoint, JFEllipsePoint, JFPointNode

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

JFPoint class. A class used to represent a point in the plane with double coordinates.

Attention: Here we used a clockwise quadrant system. And the first quadrant is under right bottom corner.

Version:
$Revision: 1.1 $
Author:
CookieMaker

Constructor Summary
JFPoint()
          Constructor for JFPoint.
JFPoint(double x, double y)
          Constructor for JFPoint.
JFPoint(JFPoint pnt)
          Constructor for JFPoint.
 
Method Summary
 java.lang.Object clone()
          Creates a new object of the same class and with the same contents as this object.
 boolean contains(double x, double y, double pickOffset)
          Test if a point is close to this point.
 boolean contains(JFPoint pnt, double pickOffset)
          Test if a point is close to this point.
 double distance(double x, double y)
          Get the distance from this point to a specific point(use x & y coordiates for instead).
 double distance(JFPoint pnt)
          Get the distance from this point to a specific point.
 boolean equals(double x, double y, boolean analog)
          Determines whether or not this point equals the coordinates given.
 boolean equals(java.lang.Object obj)
          Determines whether or not two objects are equal.
 boolean equals(java.lang.Object obj, boolean analog)
          Determines whether or not two objects are equal.
 void flipBy(double baseY)
          Reverse this point by a y coordinate.
static JFPoint getMiddleUprightPoint(JFPoint startPoint, JFPoint endPoint, double offset, boolean clockwise)
          Get a point that is on the middle upright line of the line from start point to end point, the point will has a specified offset according to upright foot,and according to clockwise term.
 double getSlope(double x, double y)
          Get the slope of the line from this point to specified point.
 double getSlope(JFPoint pnt)
          Get the slope of the line from this point to specified point.
 double getX()
          Get x coordiate of this point.
 double getY()
          Get y coordiate of this point.
 int hashCode()
          Returns the hashcode for this Object.
 boolean isValid()
          Test if this point has valid values.
 boolean middleOf(double x1, double y1, double x2, double y2)
          Test if current point is at the position between other two points.
 boolean middleOf(JFPoint point1, JFPoint point2)
          Test if current point is at the position between other two points.
 JFPoint midPoint(double x, double y)
          Get the middle point between this point and a specific point(use x & y coordiates for instead).
 JFPoint midPoint(JFPoint pnt)
          Get the middle point between this point and a specific point
 void mirrorBy(double baseX)
          Mirror this point by a x coordinate.
 void moveBy(double x, double y)
          Move this point by specific x and y coordinates.
 JFPoint nearPoint(double slope, double dist, JFPoint refPoint, boolean direction)
          Get a point on the line with specified slope, and with specified distance to this point, and also under same direction with specified reference point.
 JFPoint nearPoint(JFPoint pnt, double dist)
          Get a point on the line from this point to specified point, close to this point and with the given distance.
 JFPoint nearPoint(JFPoint pnt, double dist, boolean allowExtend)
          Get a point on the line from this point to specified point, close to this point and with the given distance.
 void rotateBy(double baseX, double baseY, double theta)
          Rotate this point by a specified point and an angle theta.
 void rotateBy(JFPoint pnt, double theta)
          Rotate this point by a specified point and an angle theta.
 void scaleBy(double baseX, double baseY, double scale)
          Scale this point by a point, and specified scale.
 void scaleBy(double baseX, double baseY, double xScale, double yScale)
          Scale this point by a point, and specified scale.
 void scaleBy(JFPoint pnt, double scale)
          Scale this point by a point, and specified scale.
 void setValue(double x, double y)
          Set value of current JFPoint.
 void setValue(JFPoint pnt)
          Set value of current JFPoint.
 void setX(double val)
          Set x coordiate of this point.
 void setY(double val)
          Set y coordiate of this point.
 java.lang.String toString()
          Convert this object to String
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JFPoint

public JFPoint()
Constructor for JFPoint. Default to 0 for x and y coordinates.


JFPoint

public JFPoint(double x,
               double y)
Constructor for JFPoint.

Parameters:
x - X coordiate.
y - Y coordiate.

JFPoint

public JFPoint(JFPoint pnt)
Constructor for JFPoint.

Parameters:
pnt - A JFPoint.
Method Detail

getX

public double getX()
Get x coordiate of this point.

Returns:
The x coordiate.

setX

public void setX(double val)
Set x coordiate of this point.

Parameters:
val - A new x coordiate.

getY

public double getY()
Get y coordiate of this point.

Returns:
The y coordiate.

setY

public void setY(double val)
Set y coordiate of this point.

Parameters:
val - A new y coordiate.

setValue

public void setValue(JFPoint pnt)
Set value of current JFPoint.


setValue

public void setValue(double x,
                     double y)
Set value of current JFPoint.


isValid

public boolean isValid()
Test if this point has valid values. We set an invalid point at GeomConst.LARGE_VALUE,GeomConst.LARGE_VALUE.


contains

public boolean contains(JFPoint pnt,
                        double pickOffset)
Test if a point is close to this point. Here we used an analog offset for 'pick' this line.

Parameters:
pnt - A point to be measured.
pickOffset - An analog offset for 'pick' this line.
Returns:
True if the point is close to this line, false otherwise.

contains

public boolean contains(double x,
                        double y,
                        double pickOffset)
Test if a point is close to this point. Here we used an analog offset for 'pick' this line.

Parameters:
pickOffset - An analog offset for 'pick' this line.
Returns:
True if the point is close to this line, false otherwise.

distance

public double distance(JFPoint pnt)
Get the distance from this point to a specific point.

Parameters:
pnt - An end point to measure distance.
Returns:
the distance.

distance

public double distance(double x,
                       double y)
Get the distance from this point to a specific point(use x & y coordiates for instead).

Parameters:
x - X coordiate of an end point to measure distance.
y - Y coordiate of an end point to measure distance.
Returns:
the distance.

midPoint

public JFPoint midPoint(JFPoint pnt)
Get the middle point between this point and a specific point

Parameters:
pnt - An end point to get middle point.
Returns:
the middle point.

midPoint

public JFPoint midPoint(double x,
                        double y)
Get the middle point between this point and a specific point(use x & y coordiates for instead).

Parameters:
x - X coordiate of an end point to measure distance.
y - Y coordiate of an end point to measure distance.
Returns:
the middle point.

middleOf

public boolean middleOf(JFPoint point1,
                        JFPoint point2)
Test if current point is at the position between other two points. Assume that the three points are on a same line.

Parameters:
point1 - First point.
point2 - Second point.
Returns:
If current point is at middle of other ones, return true, otherwise false.

middleOf

public boolean middleOf(double x1,
                        double y1,
                        double x2,
                        double y2)
Test if current point is at the position between other two points. Assume that the three points are on a same line.

Returns:
If current point is at middle of other ones, return true, otherwise false.

nearPoint

public JFPoint nearPoint(JFPoint pnt,
                         double dist)
Get a point on the line from this point to specified point, close to this point and with the given distance.

Parameters:
pnt - An end point to decide a line.
dist - A distance from the wanted point to this point.
Returns:
the point.

nearPoint

public JFPoint nearPoint(JFPoint pnt,
                         double dist,
                         boolean allowExtend)
Get a point on the line from this point to specified point, close to this point and with the given distance.

Parameters:
pnt - An end point to decide a line.
dist - A distance from the wanted point to this point.
allowExtend - Allow extend the line to get a near point.
Returns:
the point.

nearPoint

public JFPoint nearPoint(double slope,
                         double dist,
                         JFPoint refPoint,
                         boolean direction)
Get a point on the line with specified slope, and with specified distance to this point, and also under same direction with specified reference point.

Parameters:
slope - A slope of specified line that accross this point.
dist - A distance from the wanted point to this point.
refPoint - A reference point.
direction - Direction that the vector from this point to wanted point according to the vector from this point to reference point.
Returns:
the point.

getMiddleUprightPoint

public static JFPoint getMiddleUprightPoint(JFPoint startPoint,
                                            JFPoint endPoint,
                                            double offset,
                                            boolean clockwise)
Get a point that is on the middle upright line of the line from start point to end point, the point will has a specified offset according to upright foot,and according to clockwise term.

Parameters:
startPoint - The start point of this arc.
endPoint - The end point of this arc.
offset - The distance of the point shifts from upright foot.
clockwise - if the result point is on clockwise side of the vector from start pointn to end point. False default.
Returns:
The result point.

getSlope

public double getSlope(JFPoint pnt)
Get the slope of the line from this point to specified point.

Parameters:
pnt - An end point of line to get slope.
Returns:
the slope.

getSlope

public double getSlope(double x,
                       double y)
Get the slope of the line from this point to specified point.

Returns:
the slope.

moveBy

public void moveBy(double x,
                   double y)
Move this point by specific x and y coordinates.

Parameters:
x - X coordiate to moveby.
y - Y coordiate to moveby.

rotateBy

public void rotateBy(JFPoint pnt,
                     double theta)
Rotate this point by a specified point and an angle theta.

Parameters:
pnt - A rotate center point.
theta - A rotate angle.

rotateBy

public void rotateBy(double baseX,
                     double baseY,
                     double theta)
Rotate this point by a specified point and an angle theta.

Parameters:
theta - A rotate angle.

mirrorBy

public void mirrorBy(double baseX)
Mirror this point by a x coordinate. We make a left-right mirror here.

Parameters:
baseX - A mirror base x coordinate.

flipBy

public void flipBy(double baseY)
Reverse this point by a y coordinate. We make a up-down flip here.

Parameters:
baseY - A flip base y coordinate.

scaleBy

public void scaleBy(JFPoint pnt,
                    double scale)
Scale this point by a point, and specified scale.

Parameters:
pnt - A scale reference point.
scale - A scale value.

scaleBy

public void scaleBy(double baseX,
                    double baseY,
                    double scale)
Scale this point by a point, and specified scale.

Parameters:
scale - A scale value.

scaleBy

public void scaleBy(double baseX,
                    double baseY,
                    double xScale,
                    double yScale)
Scale this point by a point, and specified scale.

Parameters:
xScale - A scale value in x coordinate.
yScale - A scale value in y coordinate.

toString

public java.lang.String toString()
Convert this object to String

Overrides:
toString in class java.lang.Object
Returns:
An string represents the content of the object

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a new object of the same class and with the same contents as this object.

Overrides:
clone in class java.lang.Object
Returns:
A clone of this instance.
java.lang.CloneNotSupportedException

hashCode

public int hashCode()
Returns the hashcode for this Object.

Overrides:
hashCode in class java.lang.Object
Returns:
hash code for this Point2D.

equals

public boolean equals(java.lang.Object obj)
Determines whether or not two objects are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - an object to be compared with this object
Returns:
true if the object to be compared is an instance of Port and has the same values; false otherwise.

equals

public boolean equals(java.lang.Object obj,
                      boolean analog)
Determines whether or not two objects are equal.

Parameters:
obj - an object to be compared with this object
analog - True if use integer type to compare two points,False use double.
Returns:
true if the object to be compared is an instance of Port and has the same values; false otherwise.

equals

public boolean equals(double x,
                      double y,
                      boolean analog)
Determines whether or not this point equals the coordinates given.

Parameters:
analog - True if use integer type to compare two points,False use double.
Returns:
true if equal ,false otherwise.


Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All Rights Reserved.