com.mapinfo.midev.util

## Class DoubleRect

- java.lang.Object
- - com.mapinfo.midev.util.DoubleRect

All Implemented Interfaces:
  Serializable

    public class DoubleRect
    extends Object
    implements Serializable

This class is a double precision rectangle. A rectangle can be defined by two of its opposing corners.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`DoubleRect(DirectPosition p1, DirectPosition p2)` Constructs a rectangle.
`DoubleRect(double x1, double y1, double x2, double y2)` Constructs a rectangle.
`DoubleRect(DoubleRect r)` Constructs a rectangle.

### Method Summary

All Methods Instance Methods Concrete Methods
`double` `area()` Returns the area of a rectangle.
`DirectPosition` `center()` Returns the center of a rectangle.
`boolean` `contains(DirectPosition p)` Test whether a rectangle contains a point.
`boolean` `contains(DirectPosition p, boolean includeEdges)` Test whether this rectangle completely contains a point.
`boolean` `contains(double x, double y)` Test whether a rectangle contains a point.
`boolean` `contains(double x, double y, boolean includeEdges)` Test whether a rectangle contains a point.
`boolean` `contains(DoubleRect r)` Test whether this rectangle completely contains another rectangle.
`boolean` `contains(DoubleRect r, boolean includeEdges)` Test whether this rectangle completely contains another rectangle.
`boolean` `equals(DoubleRect r)` Test whether a rectangle is identical to another rectangle.
`boolean` `equals(Object o)`
`void` `expand(double dx, double dy)` Expand a rectangle by a given X and Y amount about the center.
`DoubleRect` `getCopy(AffineTransform affineTransform)` Get a copy of this rectangle such that all the points in this rectangle, after being transformed, are contained by the resulting rectangle.
`double` `getMaxX()`
`double` `getMaxY()`
`double` `getMinX()`
`double` `getMinY()`
`int` `hashCode()`
`double` `height()` Returns the height of a rectangle.
`void` `initBounds()` Initialize a bounding rectangle for merging with points or other rectangles.
`DoubleRect` `intersection(DoubleRect r)` Return the intersection of this rectangle with another one.
`boolean` `intersects(DirectPosition p)` Test whether a rectangle intersects a point.
`boolean` `intersects(double x, double y)` Test whether a rectangle intersects a point.
`boolean` `intersects(DoubleRect r)` Test whether a rectangle intersects another rectangle.
`boolean` `isEmpty()` Test whether a rectangle is empty.
`void` `merge(DirectPosition p)` Merge a point into a rectangle.
`void` `merge(double x, double y)` Merge a point into a rectangle.
`void` `merge(DoubleRect r)` Expands this DoubleRect so that it represents the minimum bounding rectangle of this DoubleRect, and the supplied DoubleRect.
`String` `toString()` Return a string representing the coordinates of the object.
`DoubleRect` `union(DoubleRect r)` Returns a new DoubleRect that represents the minimum bounding rectangle of this DoubleRect, and the supplied DoubleRect.
`double` `width()` Returns the width of a rectangle.
`boolean` `within(DoubleRect r)` Test whether a rectangle is completely within another rectangle.
`boolean` `within(DoubleRect r, boolean includeEdges)` Test whether a rectangle is completely within another rectangle.

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### DoubleRect

    public DoubleRect(double x1,
                      double y1,
                      double x2,
                      double y2)

Constructs a rectangle.

Parameters:
  `x1` - The X coordinate of the first corner of the rectangle.
  `y1` - The Y coordinate of the first corner of the rectangle.
  `x2` - The X coordinate of the second corner of the rectangle.
  `y2` - The Y coordinate of the second corner of the rectangle.

#### DoubleRect

    public DoubleRect(DirectPosition p1,
                      DirectPosition p2)

Constructs a rectangle.

Parameters:
  `p1` - The first corner of the rectangle.
  `p2` - The second corner of the rectangle.

#### DoubleRect

    public DoubleRect(DoubleRect r)

Constructs a rectangle.

Parameters:
  `r` - The rectangle to copy.

### Method Detail

#### getMinX

    public double getMinX()

#### getMinY

    public double getMinY()

#### getMaxX

    public double getMaxX()

#### getMaxY

    public double getMaxY()

#### expand

    public void expand(double dx,
                       double dy)

Expand a rectangle by a given X and Y amount about the center.

Parameters:
  `dx` - The horizontal distance to expand the rectangle.
  `dy` - The vertical distance to expand the rectangle.

#### isEmpty

    public boolean isEmpty()

Test whether a rectangle is empty. An empty rectangle may also be referred to as a collapsed or degenerate rectangle.

Returns:
  Returns true if the rectangle is empty.

#### equals

    public boolean equals(DoubleRect r)

Test whether a rectangle is identical to another rectangle.

Parameters:
  `r` - The rectangle to compare.
Returns:
  Returns true if the two rectangles are identical.

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### width

    public double width()

Returns the width of a rectangle.

#### height

    public double height()

Returns the height of a rectangle.

#### area

    public double area()

Returns the area of a rectangle.

#### center

    public DirectPosition center()

Returns the center of a rectangle.

#### intersects

    public boolean intersects(DoubleRect r)

Test whether a rectangle intersects another rectangle. If the rectangles overlap at even a single corner, they are considered to intersect.

Parameters:
  `r` - The rectangle to test for intersection.

#### intersects

    public boolean intersects(DirectPosition p)

Test whether a rectangle intersects a point.

Parameters:
  `p` - The point to test for intersection.

#### intersects

    public boolean intersects(double x,
                              double y)

Test whether a rectangle intersects a point.

Parameters:
  `x` - The x coordinate of the point.
  `y` - The y coordinate of the point.

#### contains

    public boolean contains(DoubleRect r)

Test whether this rectangle completely contains another rectangle. By default, the edges of the rectangle are included.

Parameters:
  `r` - The rectangle to test for containment.

#### contains

    public boolean contains(DoubleRect r,
                            boolean includeEdges)

Test whether this rectangle completely contains another rectangle.

Parameters:
  `r` - The rectangle to test for containment.
  `includeEdges` - True if you want to include the edges of this rectangle.

#### contains

    public boolean contains(DirectPosition p)

Test whether a rectangle contains a point.

Parameters:
  `p` - The point to test containment of.

#### contains

    public boolean contains(DirectPosition p,
                            boolean includeEdges)

Test whether this rectangle completely contains a point.

Parameters:
  `p` - The point to test for containment.
  `includeEdges` - True if you want to include edges of this rectangle.

#### contains

    public boolean contains(double x,
                            double y)

Test whether a rectangle contains a point.

Parameters:
  `x` - The x coordinate of the point.
  `y` - The y coordinate of the point.

#### contains

    public boolean contains(double x,
                            double y,
                            boolean includeEdges)

Test whether a rectangle contains a point.

Parameters:
  `x` - The x coordinate of the point.
  `y` - The y coordinate of the point.
  `includeEdges` - True if you want containment to include edges.

#### within

    public boolean within(DoubleRect r)

Test whether a rectangle is completely within another rectangle.

Parameters:
  `r` - The rectangle to test for this rectangle to be in.

#### within

    public boolean within(DoubleRect r,
                          boolean includeEdges)

Test whether a rectangle is completely within another rectangle.

Parameters:
  `r` - The rectangle to test for this rectangle to be in.
  `includeEdges` - True if you want containment to include edges.

#### merge

    public void merge(DirectPosition p)

Merge a point into a rectangle. The rectangle will expand to include the point. The initBounds method must be called before using this method.

Parameters:
  `p` - The point to merge into this rectangle.
See Also:
  `DoubleRect.initBounds()`

#### merge

    public void merge(double x,
                      double y)

Merge a point into a rectangle. The rectangle will expand to include the point. The initBounds method must be called before using this method.

Parameters:
  `x` - The x coordinate of the point to merge into the rectangle.
  `y` - The y coordinate of the point to merge into the rectangle.
See Also:
  `DoubleRect.initBounds()`

#### merge

    public void merge(DoubleRect r)

Expands this DoubleRect so that it represents the minimum bounding rectangle of this DoubleRect, and the supplied DoubleRect. The initBounds method must be called before using this method.

Parameters:
  `r` - The rectangle to merge into this rectangle.
See Also:
  `DoubleRect.initBounds()`

#### initBounds

    public void initBounds()

Initialize a bounding rectangle for merging with points or other rectangles. Example:

`DoubleRect totalRect = new DoubleRect();

totalRect.initBounds();

for (each rect to merge) {

totalRect.merge(rect);

}`

See Also:
  `DoubleRect.merge(DirectPosition)`, `DoubleRect.merge(double,double)`, `DoubleRect.merge(DoubleRect)`

#### intersection

    public DoubleRect intersection(DoubleRect r)

Return the intersection of this rectangle with another one. If the rectangles do not intersect, the resulting rectangle is empty (isEmpty returns true).

Returns:
  A DoubleRect representing the intersection.

#### union

    public DoubleRect union(DoubleRect r)

Returns a new DoubleRect that represents the minimum bounding rectangle of this DoubleRect, and the supplied DoubleRect.

Returns:
  A DoubleRect representing the union.

#### getCopy

    public DoubleRect getCopy(AffineTransform affineTransform)

Get a copy of this rectangle such that all the points in this rectangle, after being transformed, are contained by the resulting rectangle.

Parameters:
  `affineTransform` - The transform to apply to the resulting rectangle.
Returns:
  A transformed rectangle.

#### toString

    public String toString()

Return a string representing the coordinates of the object. The resulting string will list the bounds in the order of xmin, ymin, xmax, ymax.

Overrides:
  `toString` in class `Object`
Returns:
  A string of the bounding coordinates.