All Packages Class Hierarchy This Package Previous Next Index
Class att.grappa.DoubleRectangle
java.lang.Object
|
+----att.grappa.DoubleRectangle
- public class DoubleRectangle
- extends Object
- implements Shape, Serializable
An re-implementation of java.awt.Rectangle
using doubles instead of ints.
- Version:
- 1.1, 30 Sep 1999; Copyright 1996 - 1999 by AT&T Corp.
- Author:
- John Mocenigo, Research @ AT&T Labs
-
height
- The height of the rectangle.
-
width
- The width of the rectangle.
-
x
- The x coordinate of the rectangle.
-
y
- The y coordinate of the rectangle.
-
DoubleRectangle()
- Constructs a new rectangle whose top-left corner is at (0, 0)
in the coordinate space, and whose width and height are zero.
-
DoubleRectangle(double, double)
- Constructs a new rectangle whose top-left corner is at (0, 0)
in the coordinate space, and whose width and height are specified
by the arguments of the same name.
-
DoubleRectangle(double, double, double, double)
- Constructs a new rectangle whose top-left corner is specified as
(
x
, y
) and whose width and height
are specified by the arguments of the same name.
-
DoubleRectangle(DoubleDimension)
- Constructs a new rectangle whose top left corner is
(0, 0) and whose width and height are specified
by the
dimension
argument.
-
DoubleRectangle(DoublePoint)
- Constructs a new rectangle whose top-left corner is the
specified point, and whose width and height are zero.
-
DoubleRectangle(DoublePoint, DoubleDimension)
- Constructs a new rectangle whose top-left corner is specified
by the
point
argument, and whose width and height
are specified by the dimension
argument.
-
DoubleRectangle(DoubleRectangle)
- Constructs a new rectangle, initialized to match the values of
the specificed rectangle.
-
DoubleRectangle(Rectangle)
- Constructs a new rectangle, initialized to match the values of
the specificed (integer) rectangle.
-
add(double, double)
- Adds a point, specified by the arguments
newx
and newy
, to this rectangle.
-
add(DoublePoint)
- Adds the point
pt
to this rectangle.
-
add(DoubleRectangle)
- Adds a rectangle to this rectangle.
-
contains(double, double)
- Checks whether this rectangle contains the point
at the specified location (x, y).
-
contains(DoublePoint)
- Checks whether this rectangle contains the specified point.
-
equals(Object)
- Checks whether two rectangles are equal.
-
getApproximation()
- Gets the closest (using
Math.round()
) Rectangle
to this rectangle.
-
getBounds()
- Gets the bounding rectangle of this rectangle.
-
getLocation()
- Gets the location of this rectangle.
-
getSize()
- Gets the size (width and height) of this rectangle.
-
grow(double, double)
- Grows the rectangle both horizontally and vertically.
-
hashCode()
- Returns the hashcode for this rectangle.
-
intersection(DoubleRectangle)
- Computes the intersection of this rectangle with the
specified rectangle.
-
intersects(DoubleRectangle)
- Determines whether this rectangle and the specified rectangle
intersect.
-
isEmpty()
- Determines whether this rectangle is empty.
-
setBounds(double, double, double, double)
- Sets this rectangle to the specified
values for
x
, y
, width
,
and height
.
-
setBounds(DoubleRectangle)
- Sets this rectangle to match the specified rectangle.
-
setBounds(Rectangle)
- Sets the bounding rectangle of this rectangle to match
the specified rectangle.
-
setLocation(double, double)
- Moves the rectangle to the specified location.
-
setLocation(DoublePoint)
- Moves the rectangle to the specified location.
-
setSize(double, double)
- Sets the size of this rectangle to the specified width and height.
-
setSize(DoubleDimension)
- Sets the size of this rectangle to match the specified dimension.
-
toString()
- Returns a string representation of this rectangle
and its values.
-
translate(double, double)
- Translates the rectangle the indicated distance,
to the right along the x coordinate axis, and
downward along the y coordinate axis.
-
union(DoubleRectangle)
- Computes the union of this rectangle with the
specified rectangle.
x
public double x
- The x coordinate of the rectangle.
y
public double y
- The y coordinate of the rectangle.
width
public double width
- The width of the rectangle.
height
public double height
- The height of the rectangle.
DoubleRectangle
public DoubleRectangle()
- Constructs a new rectangle whose top-left corner is at (0, 0)
in the coordinate space, and whose width and height are zero.
DoubleRectangle
public DoubleRectangle(DoubleRectangle r)
- Constructs a new rectangle, initialized to match the values of
the specificed rectangle.
- Parameters:
- r - a DoubleRectangle from which to copy initial values.
DoubleRectangle
public DoubleRectangle(Rectangle r)
- Constructs a new rectangle, initialized to match the values of
the specificed (integer) rectangle.
- Parameters:
- r - a rectangle from which to copy initial values.
DoubleRectangle
public DoubleRectangle(double x,
double y,
double width,
double height)
- Constructs a new rectangle whose top-left corner is specified as
(
x
, y
) and whose width and height
are specified by the arguments of the same name.
- Parameters:
- x - the x coordinate.
- y - the y coordinate.
- width - the width of the rectangle.
- height - the height of the rectangle.
DoubleRectangle
public DoubleRectangle(double width,
double height)
- Constructs a new rectangle whose top-left corner is at (0, 0)
in the coordinate space, and whose width and height are specified
by the arguments of the same name.
- Parameters:
- width - the width of the rectangle.
- height - the height of the rectangle.
DoubleRectangle
public DoubleRectangle(DoublePoint p,
DoubleDimension d)
- Constructs a new rectangle whose top-left corner is specified
by the
point
argument, and whose width and height
are specified by the dimension
argument.
- Parameters:
- p - a DoublePoint, the top-left corner of the rectangle.
- d - a DoubleDimension, representing the width and height.
DoubleRectangle
public DoubleRectangle(DoublePoint p)
- Constructs a new rectangle whose top-left corner is the
specified point, and whose width and height are zero.
- Parameters:
- p - the top left corner of the rectangle.
DoubleRectangle
public DoubleRectangle(DoubleDimension d)
- Constructs a new rectangle whose top left corner is
(0, 0) and whose width and height are specified
by the
dimension
argument.
- Parameters:
- d - a dimension, specifying width and height.
getApproximation
public Rectangle getApproximation()
- Gets the closest (using
Math.round()
) Rectangle
to this rectangle.
- Returns:
- a standard (integer) rectangle, that approximates this one
getBounds
public Rectangle getBounds()
- Gets the bounding rectangle of this rectangle.
This method is included for completeness, to parallel the
getBounds
method of Component
.
- Returns:
- a new rectangle, equal to the bounding rectangle
for this rectangle.
- See Also:
- getBounds
setBounds
public void setBounds(Rectangle r)
- Sets the bounding rectangle of this rectangle to match
the specified rectangle.
This method is included for completeness, to parallel the
setBounds
method of Component
.
- Parameters:
- r - a rectangle.
setBounds
public void setBounds(DoubleRectangle r)
- Sets this rectangle to match the specified rectangle.
- Parameters:
- r - a DoubleRectangle.
setBounds
public void setBounds(double x,
double y,
double width,
double height)
- Sets this rectangle to the specified
values for
x
, y
, width
,
and height
.
This method is included for completeness, to parallel the
setBounds
method of Component
.
- Parameters:
- x - the new x coordinate for the top-left
corner of this rectangle.
- y - the new y coordinate for the top-left
corner of this rectangle.
- width - the new width for this rectangle.
- height - the new height for this rectangle.
getLocation
public DoublePoint getLocation()
- Gets the location of this rectangle.
- Returns:
- the top-left point of this rectangle
setLocation
public void setLocation(DoublePoint p)
- Moves the rectangle to the specified location.
This method is included for completeness, to parallel the
setLocation
method of Component
.
- Parameters:
- p - the new location for the point.
setLocation
public void setLocation(double x,
double y)
- Moves the rectangle to the specified location.
This method is included for completeness, to parallel the
setLocation
method of Component
.
- Parameters:
- x - the x coordinate of the new location.
- y - the y coordinate of the new location.
- See Also:
- setLocation
translate
public void translate(double x,
double y)
- Translates the rectangle the indicated distance,
to the right along the x coordinate axis, and
downward along the y coordinate axis.
- Parameters:
- dx - the distance to move the rectangle
along the x axis.
- dy - the distance to move the rectangle
along the y axis.
getSize
public DoubleDimension getSize()
- Gets the size (width and height) of this rectangle.
This method is included for completeness, to parallel the
getSize
method of Component
.
- Returns:
- a DoubleDimension, representing the size.
setSize
public void setSize(DoubleDimension d)
- Sets the size of this rectangle to match the specified dimension.
- Parameters:
- d - the new size for the Dimension object
setSize
public void setSize(double width,
double height)
- Sets the size of this rectangle to the specified width and height.
- Parameters:
- width - the new width for this rectangle object.
- height - the new height for this rectangle object.
contains
public boolean contains(DoublePoint p)
- Checks whether this rectangle contains the specified point.
- Parameters:
- p - the point (location) to test.
- Returns:
-
true
if the point
(x, y) is inside this rectangle;
false
otherwise.
contains
public boolean contains(double x,
double y)
- Checks whether this rectangle contains the point
at the specified location (x, y).
- Parameters:
- x - the x coordinate.
- y - the y coordinate.
- Returns:
-
true
if the point
(x, y) is inside this rectangle;
false
otherwise.
intersects
public boolean intersects(DoubleRectangle r)
- Determines whether this rectangle and the specified rectangle
intersect. Two rectangles intersect if their intersection is
nonempty.
- Parameters:
- r - a DoubleRectangle.
- Returns:
-
true
if the specified rectangle
and this rectangle insersect;
false
otherwise.
intersection
public DoubleRectangle intersection(DoubleRectangle r)
- Computes the intersection of this rectangle with the
specified rectangle. Returns a new rectangle that
represents the intersection of the two rectangles.
- Parameters:
- r - a DoubleRectangle.
- Returns:
- the largest rectangle contained in both the
specified rectangle and in this rectangle.
union
public DoubleRectangle union(DoubleRectangle r)
- Computes the union of this rectangle with the
specified rectangle. Returns a new rectangle that
represents the union of the two rectangles.
- Parameters:
- r - a rectangle.
- Returns:
- the smallest rectangle containing both the specified
rectangle and this rectangle.
add
public void add(double newx,
double newy)
- Adds a point, specified by the arguments
newx
and newy
, to this rectangle. The resulting rectangle is
the smallest rectangle that contains both the original rectangle
and the specified point.
After adding a point, a call to contains with the
added point as an argument will not necessarily return
true
. The contains
method does not
return true
for points on the right or bottom
edges of a rectangle. Therefore if the added point falls on
the left or bottom edge of the enlarged rectangle,
contains
will return false
for that point.
- Parameters:
- newx - the x coordinate of the new point.
- newy - the y coordinate of the new point.
add
public void add(DoublePoint pt)
- Adds the point
pt
to this rectangle. The resulting
rectangle is the smallest rectangle that contains both the
original rectangle and the specified point.
After adding a point, a call to contains with the
added point as an argument will not necessarily return
true
. The contains
method does not
return true
for points on the right or bottom
edges of a rectangle. Therefore if the added point falls on
the left or bottom edge of the enlarged rectangle,
contains
will return false
for that point.
- Parameters:
- pt - the new point to add to the rectangle.
add
public void add(DoubleRectangle r)
- Adds a rectangle to this rectangle. The resulting rectangle is
the union of the two rectangles.
- Parameters:
- a - rectangle.
grow
public void grow(double h,
double v)
- Grows the rectangle both horizontally and vertically.
This method modifies the rectangle so that it is
h
units larger on both the left and right side,
and v
units larger at both the top and bottom.
The new rectangle has (x - h
,
y - v
) as its top-left corner, a
width of
width
+
2h
,
and a height of
height
+
2v
.
If negative values are supplied for h
and
v
, the size of the rectangle decreases accordingly.
The grow
method does not check whether the resulting
values of width
and height
are
non-negative.
- Parameters:
- h - the horizontal expansion.
- v - the vertical expansion.
isEmpty
public boolean isEmpty()
- Determines whether this rectangle is empty. A rectangle is empty if
its width or its height is less than or equal to zero.
- Returns:
-
true
if this rectangle is empty;
false
otherwise.
hashCode
public int hashCode()
- Returns the hashcode for this rectangle.
- Returns:
- the hashcode for this rectangle.
- Overrides:
- hashCode in class Object
equals
public boolean equals(Object obj)
- Checks whether two rectangles are equal.
The result is true if and only if the argument is not
null and is a DoubleRectangle object that has the
same top-left corner, width, and height as this rectangle.
- Parameters:
- obj - the object to compare with.
- Returns:
-
true
if the objects are equal;
false
otherwise.
- Overrides:
- equals in class Object
toString
public String toString()
- Returns a string representation of this rectangle
and its values.
- Returns:
- a string representation of this rectangle.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index