Algorithm
Development Kit 1.0

algs.model.twod
Class TwoDRectangle

java.lang.Object
  extended by algs.model.twod.TwoDRectangle
All Implemented Interfaces:
IRectangle

public class TwoDRectangle
extends java.lang.Object
implements IRectangle

Represents a rectangular region in the Cartesian plane.

Note that the rectangle could be infinite in none, one, or two of these dimensions by having any of its coordinates set to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY. A rectangle could be one-dimensional (if either x1==x2 or y1==y2) or zero-dimensional (if both x1==x2 and y1==y2).

RectangularRegion is (slightly) incompatible with IHypercube because rectangles are commonly referred to as (left, bottom, right, top). As you can see, the dimensions are intermixed. IHypercube expects a number of dimensions, and to keep things straight they are reported in order: here this means it would be (left, right) (bottom, top). In order to avoid confusion, we make no attempt to have this class conform to both IRectangle and IHypercube.

Note that for convenience, there is a method in Hypercube that will create a two-dimensional Hypercube counterpart given a RectangularRegion.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman
See Also:
IHypercube

Constructor Summary
TwoDRectangle(double left, double bottom, double right, double top)
          Construct a rectangle from the given cartesian coordinates.
TwoDRectangle(IRectangle d)
          Copy constructor.
 
Method Summary
 boolean contains(IRectangle r)
          Determines containment of the given rectangle within the closed Rectangular region.
 boolean equals(java.lang.Object o)
          Extend to cover .equals() to any object that implements IRectangle.
 double getBottom()
          Return bottom of rectangle.
 double getLeft()
          Return left of rectangle.
 double getRight()
          Return right of rectangle.
 double getTop()
          Return top of rectangle.
 boolean intersects(IPoint p)
          Determines intersection of the given point within the closed Rectangular region.
 void setBottom(double d)
          Update bottom of rectangle.
 void setLeft(double d)
          Update left of rectangle.
 void setRight(double d)
          Update right of rectangle.
 void setTop(double d)
          Update top of rectangle.
 java.lang.String toString()
          Reasonable representation of this rectangular region.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TwoDRectangle

public TwoDRectangle(double left,
                     double bottom,
                     double right,
                     double top)
Construct a rectangle from the given cartesian coordinates.

Parameters:
left -
bottom -
right -
top -

TwoDRectangle

public TwoDRectangle(IRectangle d)
Copy constructor.

Method Detail

getBottom

public double getBottom()
Return bottom of rectangle.

Specified by:
getBottom in interface IRectangle

getLeft

public double getLeft()
Return left of rectangle.

Specified by:
getLeft in interface IRectangle

getRight

public double getRight()
Return right of rectangle.

Specified by:
getRight in interface IRectangle

getTop

public double getTop()
Return top of rectangle.

Specified by:
getTop in interface IRectangle

setTop

public void setTop(double d)
Update top of rectangle.


setBottom

public void setBottom(double d)
Update bottom of rectangle.


setLeft

public void setLeft(double d)
Update left of rectangle.


setRight

public void setRight(double d)
Update right of rectangle.


intersects

public boolean intersects(IPoint p)
Determines intersection of the given point within the closed Rectangular region.

Specified by:
intersects in interface IRectangle
Parameters:
p - IPoint to be inspected.

contains

public boolean contains(IRectangle r)
Determines containment of the given rectangle within the closed Rectangular region.

Handle -INF and +INF equitably.

Specified by:
contains in interface IRectangle
Parameters:
r - Rectangle to be checked for containment within self.

toString

public java.lang.String toString()
Reasonable representation of this rectangular region.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Extend to cover .equals() to any object that implements IRectangle. Perform comparison on (left,bottom,right,top) values.

Specified by:
equals in interface IRectangle
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(Object)

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.