com.jfimagine.jfgraph.geom
Class Rect

java.lang.Object
  |
  +--com.jfimagine.jfgraph.geom.Rect
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Diamond, Ellipse, Hexagon, IsoscelesTriangle, RoundedRect

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

Rect class. A class used to represent a rectangle 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

Field Summary
protected  JFPoint m_leftBottom
          Left-bottom vertex of rectangle.
protected  JFPoint m_leftTop
          Left-top vertex of rectangle.
protected  JFPoint m_rightBottom
          Right-bottom vertex of rectangle.
protected  JFPoint m_rightTop
          Right-top vertex of rectangle.
static int SIDETYPE_BOTTOM
          A const side type represents the bottom side of a rectangle
static int SIDETYPE_LEFT
          A const side type represents the left side of a rectangle
static int SIDETYPE_RIGHT
          A const side type represents the right side of a rectangle
static int SIDETYPE_TOP
          A const side type represents the top side of a rectangle
static int VERTEXMOVETYPE_ISOSCELESTRAPEZOID
          A isosceles trapezoid vertex moving type of rectangle.
static int VERTEXMOVETYPE_PARALLEL
          A parallelogram vertex moving type of rectangle.
static int VERTEXMOVETYPE_RECTANGLE
          A rectangular vertex moving type of rectangle.
static int VERTEXMOVETYPE_SCALE
          A rectangular scale vertex moving type of rectangle.
static int VERTEXMOVETYPE_TRAPEZOID
          A trapezoid vertex moving type of rectangle.
static int VERTEXTYPE_LEFTBOTTOM
          A const vertext type represents the left-bottom vertex of a rectangle
static int VERTEXTYPE_LEFTTOP
          A const vertext type represents the left-top vertex of a rectangle
static int VERTEXTYPE_RIGHTBOTTOM
          A const vertext type represents the right-bottom vertex of a rectangle
static int VERTEXTYPE_RIGHTTOP
          A const vertext type represents the right-top vertex of a rectangle
 
Constructor Summary
Rect()
          Constructor for Rect.
Rect(double x, double y, double w, double h)
          Constructor for Rect.
Rect(JFPoint startPoint, JFPoint endPoint)
          Constructor for Rect.
Rect(Rect rect)
          Constructor for Rect.
 
Method Summary
 boolean canAddPort(double x, double y, JFPoint startPoint, JFPoint endPoint, JFPoint portPoint)
          Test if current rectangle can add a port according to the position x,y.
 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)
          Test if a point(x, y coordinates for instead) is within this rectangle.
 boolean contains(JFPoint pnt)
          Test if a point is within this rectangle.
 boolean equals(java.lang.Object obj)
          Determines whether or not two objects are equal.
 void flipBy()
          Reverse this rectangle by a central y coordinate of this rectangle.
 void flipBy(double baseY)
          Reverse this rectangle by a y coordinate.
 Rect getBounds()
          Get the bounds of this rectangle.
 JFPoint getCenter()
          Get a center point of this rectangle.
 double getHeight()
          Get height of this rectangle.
 LineSeg getSide(int sideType)
          Get a side line of this rectangle.
 JFPoint getVertex(int vertexType)
          Get a vertex point of this rectangle.
 double getWidth()
          Get width of this rectangle.
 double getX()
          Get x coordiate of this rectangle.
 double getY()
          Get y coordiate of this rectangle.
 int hashCode()
          Returns the hashcode for this Object.
 boolean intersects(double x1, double y1, double x2, double y2)
          Tests if the specified line segment intersects the interior of this Rect.
 boolean intersects(double x1, double y1, int pickOffset)
          Tests if the specified point intersects any side of this rectangle.
 boolean intersects(JFPoint pnt, int pickOffset)
          Tests if the specified point intersects any side of this rectangle.
 boolean intersects(LineSeg line)
          Tests if the specified line segment intersects the interior of this Rect.
 boolean intersects(Rect rect)
          Tests if the specified rectangle intersects the interior of this Rect.
 void mirrorBy()
          Mirror this rectangle by a central x coordinate of this rectangle.
 void mirrorBy(double baseX)
          Mirror this rectangle by a x coordinate.
 void moveBy(double x, double y)
          Move this rectangle by specific x and y coordinates.
 void moveVertex(int vertexType, double x, double y, int moveType)
          Move a vertex of a rectangle.
static JFPoint newScaleCenter(JFPoint center, JFPoint basePoint, JFPoint refPoint1, JFPoint refPoint2, double scale)
          When a shape is scaled, its location center will be changed probably.
 LineSeg pickLine(double x, double y, double pickOffset)
          Pick a line segment of this rectangle by a point with a pickoffset.
 void rotateBy(double theta)
          Rotate this rectangle by an angle theta.
 void rotateBy(double baseX, double baseY, double theta)
          Rotate this line by a specified point and an angle theta.
 void rotateBy(JFPoint pnt, double theta)
          Rotate this rectangle by a specified point and an angle theta.
 void scaleBy(JFPoint basePoint, double xScale, double yScale)
          Scale current object by a specified x and y scale.
 void scaleBy(JFPoint basePoint, JFPoint refPoint1, JFPoint refPoint2, double scale)
          Scale current rectangle by specified points and scale percent.
 void setValue(double x, double y, double w, double h)
          Set the bounds of current rectangle.
 void setValue(Rect rect)
          Set the value of current rectangle.
 void setVertex(int vertexType, double x, double y)
          Set a vertex point of this rectangle.
 void setVertex(int vertexType, JFPoint pnt)
          Set a vertex point of this rectangle.
 java.lang.String toString()
          Convert this object to String
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

VERTEXTYPE_LEFTTOP

public static final int VERTEXTYPE_LEFTTOP
A const vertext type represents the left-top vertex of a rectangle

See Also:
Constant Field Values

VERTEXTYPE_RIGHTTOP

public static final int VERTEXTYPE_RIGHTTOP
A const vertext type represents the right-top vertex of a rectangle

See Also:
Constant Field Values

VERTEXTYPE_LEFTBOTTOM

public static final int VERTEXTYPE_LEFTBOTTOM
A const vertext type represents the left-bottom vertex of a rectangle

See Also:
Constant Field Values

VERTEXTYPE_RIGHTBOTTOM

public static final int VERTEXTYPE_RIGHTBOTTOM
A const vertext type represents the right-bottom vertex of a rectangle

See Also:
Constant Field Values

SIDETYPE_LEFT

public static final int SIDETYPE_LEFT
A const side type represents the left side of a rectangle

See Also:
Constant Field Values

SIDETYPE_TOP

public static final int SIDETYPE_TOP
A const side type represents the top side of a rectangle

See Also:
Constant Field Values

SIDETYPE_RIGHT

public static final int SIDETYPE_RIGHT
A const side type represents the right side of a rectangle

See Also:
Constant Field Values

SIDETYPE_BOTTOM

public static final int SIDETYPE_BOTTOM
A const side type represents the bottom side of a rectangle

See Also:
Constant Field Values

VERTEXMOVETYPE_SCALE

public static final int VERTEXMOVETYPE_SCALE
A rectangular scale vertex moving type of rectangle.

See Also:
Constant Field Values

VERTEXMOVETYPE_RECTANGLE

public static final int VERTEXMOVETYPE_RECTANGLE
A rectangular vertex moving type of rectangle.

See Also:
Constant Field Values

VERTEXMOVETYPE_PARALLEL

public static final int VERTEXMOVETYPE_PARALLEL
A parallelogram vertex moving type of rectangle.

See Also:
Constant Field Values

VERTEXMOVETYPE_TRAPEZOID

public static final int VERTEXMOVETYPE_TRAPEZOID
A trapezoid vertex moving type of rectangle.

See Also:
Constant Field Values

VERTEXMOVETYPE_ISOSCELESTRAPEZOID

public static final int VERTEXMOVETYPE_ISOSCELESTRAPEZOID
A isosceles trapezoid vertex moving type of rectangle.

See Also:
Constant Field Values

m_leftTop

protected JFPoint m_leftTop
Left-top vertex of rectangle.


m_rightTop

protected JFPoint m_rightTop
Right-top vertex of rectangle.


m_leftBottom

protected JFPoint m_leftBottom
Left-bottom vertex of rectangle.


m_rightBottom

protected JFPoint m_rightBottom
Right-bottom vertex of rectangle.

Constructor Detail

Rect

public Rect()
Constructor for Rect.


Rect

public Rect(Rect rect)
Constructor for Rect.

Parameters:
rect - A rectangle object.

Rect

public Rect(double x,
            double y,
            double w,
            double h)
Constructor for Rect.

Parameters:
x - X coordiate.
y - Y coordiate.
w - Width of this rectangle.
h - Height of this rectangle.

Rect

public Rect(JFPoint startPoint,
            JFPoint endPoint)
Constructor for Rect.

Parameters:
startPoint - A startPoint for one endpoint of this rectangle.
endPoint - An endPoint for another endpoint of this rectangle.
Method Detail

getX

public double getX()
Get x coordiate of this rectangle. Consider this rectangle should be scaled or rotated, so return a minimum x coordinate of all vertexs here.

Returns:
The x coordiate.

getY

public double getY()
Get y coordiate of this rectangle. Consider this rectangle should be scaled or rotated, so return a minimum y coordinate of all vertexs here.

Returns:
The y coordiate.

getWidth

public double getWidth()
Get width of this rectangle. Consider this rectangle should be scaled or rotated, so return a maxmum width of this rectangle.

Returns:
Width of this rectangle.

getHeight

public double getHeight()
Get height of this rectangle. Consider this rectangle should be scaled or rotated, so return a maxmum height of this rectangle.

Returns:
Height of this rectangle.

setValue

public void setValue(double x,
                     double y,
                     double w,
                     double h)
Set the bounds of current rectangle.

Parameters:
x - X coordiate.
y - Y coordiate.
w - Width of this rectangle.
h - Height of this rectangle.

setValue

public void setValue(Rect rect)
Set the value of current rectangle.

Parameters:
rect - A new rectangle.

getBounds

public Rect getBounds()
Get the bounds of this rectangle.

Returns:
The bounds rectangle.

getVertex

public JFPoint getVertex(int vertexType)
Get a vertex point of this rectangle.

Returns:
A vertex point.

setVertex

public void setVertex(int vertexType,
                      JFPoint pnt)
Set a vertex point of this rectangle.

Parameters:
vertexType - An vertex type of a rectangle.
pnt - A new vertex point.

setVertex

public void setVertex(int vertexType,
                      double x,
                      double y)
Set a vertex point of this rectangle.

Parameters:
vertexType - An vertex type of a rectangle.

moveVertex

public void moveVertex(int vertexType,
                       double x,
                       double y,
                       int moveType)
Move a vertex of a rectangle. This will occurr under different requirements. One is for moving a vertex of a rectangle, so we get a parallelogram or trapezoid; the other is for scaling the rectangle but not change it's shape.

Parameters:
vertexType - An vertex type of a rectangle.
moveType - scale, rectangular, parallel or trapezoid vertex moving type.

getSide

public LineSeg getSide(int sideType)
Get a side line of this rectangle.

Returns:
A side line.

getCenter

public JFPoint getCenter()
Get a center point of this rectangle.

Returns:
The center point.

scaleBy

public void scaleBy(JFPoint basePoint,
                    JFPoint refPoint1,
                    JFPoint refPoint2,
                    double scale)
Scale current rectangle by specified points and scale percent. We only support a concurrent width-height scale here, suppose width as the length from basePoint to refPoint1, height as the length from basePoint to refPoint2, and one scale percent acts on both width and height.

Parameters:
basePoint - A base point that is unmovable.
refPoint1 - A 'width' reference point.
refPoint2 - A 'height' reference point.
scale - A reference scale percent.

scaleBy

public void scaleBy(JFPoint basePoint,
                    double xScale,
                    double yScale)
Scale current object by a specified x and y scale.
This is a special scale method used to scale a shape in arbitrary x and y scale.
Please see AbstractShape.scaleBy for detailed description.

Parameters:
basePoint - A base scale point for scaling reference.
xScale - A scale percentage in x coordinate, default to 1.0
yScale - A scale percentage in y coordinate, default to 1.0

newScaleCenter

public static JFPoint newScaleCenter(JFPoint center,
                                     JFPoint basePoint,
                                     JFPoint refPoint1,
                                     JFPoint refPoint2,
                                     double scale)
When a shape is scaled, its location center will be changed probably. so we need to canculate its new center acorrding to these scale parameters.

Parameters:
center - An old center of the scaled object.
basePoint - A base point that is unmovable.
refPoint1 - A 'width' reference point.
refPoint2 - A 'height' reference point.
scale - A reference scale percent.

moveBy

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

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

rotateBy

public void rotateBy(double theta)
Rotate this rectangle by an angle theta.

Parameters:
theta - A rotate angle.

rotateBy

public void rotateBy(JFPoint pnt,
                     double theta)
Rotate this rectangle by a specified point and an angle theta. If rotate by a point, it's same as move this rectangle to a new position, and simultaneously rotate this rectangle under proper angle. Certainly this angle is also equal to theta.

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

rotateBy

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

Parameters:
theta - A rotate angle.

mirrorBy

public void mirrorBy()
Mirror this rectangle by a central x coordinate of this rectangle. We make a up-down flip here.


mirrorBy

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

Parameters:
baseX - A mirror base x coordinate.

flipBy

public void flipBy()
Reverse this rectangle by a central y coordinate of this rectangle. We make a up-down flip here.


flipBy

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

Parameters:
baseY - A flip base y coordinate.

contains

public boolean contains(JFPoint pnt)
Test if a point is within this rectangle.

Parameters:
pnt - A point.
Returns:
True if the point is inside rectangle, false if not.

contains

public boolean contains(double x,
                        double y)
Test if a point(x, y coordinates for instead) is within this rectangle.

The algorithm for testing if a point is within this rectangle is at below.

count = 0; [start at endpoint P, make an radial line L from right to left] for [each side S of this rectangle] do if [P is on one side S] then return true; if [side S is not a horizontal line] then if [one endpoint of S is on L] if [this endpoint is the max y coordinate of the two endpoints of S] then count = count+1 else if [S interacts L] then count=count+1; if count mod 2 = 1 then return true; else return false;

Parameters:
x - X coordinate of this point.
y - Y coordinate of this point.
Returns:
True if the point is inside this rectangle, false otherwise.

pickLine

public LineSeg pickLine(double x,
                        double y,
                        double pickOffset)
Pick a line segment of this rectangle by a point with a pickoffset.

Parameters:
x - X coordinate of this point.
y - Y coordinate of this point.
pickOffset - An analog pick offset that great equal than 0.
Returns:
A line segment picked.

canAddPort

public boolean canAddPort(double x,
                          double y,
                          JFPoint startPoint,
                          JFPoint endPoint,
                          JFPoint portPoint)
Test if current rectangle can add a port according to the position x,y.

Parameters:
x - X coordinate of the port.
y - Y coordinate of the port.
Returns:
True if can add a new port, false otherwise.

intersects

public boolean intersects(JFPoint pnt,
                          int pickOffset)
Tests if the specified point intersects any side of this rectangle.

Parameters:
pnt - the specified point.
pickOffset - An analog offset for 'pick' this line.
Returns:
true if the specified point intersects one side of this rectangle. false otherwise.

intersects

public boolean intersects(double x1,
                          double y1,
                          int pickOffset)
Tests if the specified point intersects any side of this rectangle.

Parameters:
pickOffset - An analog offset for 'pick' this line.
Returns:
true if the specified point intersects one side of this rectangle. false otherwise.

intersects

public boolean intersects(double x1,
                          double y1,
                          double x2,
                          double y2)
Tests if the specified line segment intersects the interior of this Rect.

Returns:
true if the specified line segment intersects the interior of this Rect; false otherwise.

intersects

public boolean intersects(LineSeg line)
Tests if the specified line segment intersects the interior of this Rect.

Parameters:
line - the specified LineSeg to test for intersection with the interior of this Rect
Returns:
true if the specified LineSeg intersects the interior of this Rect; false otherwise.

intersects

public boolean intersects(Rect rect)
Tests if the specified rectangle intersects the interior of this Rect.

Parameters:
rect - the specified Rect to test for intersection with the interior of this Rect
Returns:
true if the specified Rect intersects the interior of this Rect; false otherwise.

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.


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