Package cs2110
Class BoundingBox
java.lang.Object
cs2110.BoundingBox
An immutable, axis-aligned, closed rectangle in the 2D coordinate plane.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty bounding box that contains no points.BoundingBox
(Point corner, double width, double height) Constructs a (non-empty) bounding box with the given upper left `corner`, `width` and `height`. -
Method Summary
Modifier and TypeMethodDescriptiondouble
area()
Returns the area of this bounding box (in squared units of the coordinate system).boolean
Returns whether every point of the given bounding box `b` is contained within this bounding box.boolean
Returns whether the given point `p` is contained within this bounding box, either in its *interior* or incident to one of its edges or corners.boolean
Returns whether this BoundingBox is equal to another, which is true when they have the same dimensions and upper left corners.double
height()
Returns the height of this bounding box (in units of the coordinate system).Returns the intersection of this bounding box with the given bounding box `b`.boolean
isEmpty()
Returns `true` if this bounding box is empty, so contains no points, otherwise returns `false`.Returns the upper left corner this bounding box, or returns null if this bounding box is empty.double
width()
Returns the width of this bounding box (in units of the coordinate system).
-
Constructor Details
-
BoundingBox
public BoundingBox()Constructs an empty bounding box that contains no points. -
BoundingBox
Constructs a (non-empty) bounding box with the given upper left `corner`, `width` and `height`. Requires that `corner != null`, `width >= 0`, and `height >= 0`.
-
-
Method Details
-
upperLeftCorner
Returns the upper left corner this bounding box, or returns null if this bounding box is empty. -
width
public double width()Returns the width of this bounding box (in units of the coordinate system). Returns 0 if this bounding box is empty. -
height
public double height()Returns the height of this bounding box (in units of the coordinate system). Returns 0 if this bounding box is empty. -
area
public double area()Returns the area of this bounding box (in squared units of the coordinate system). -
isEmpty
public boolean isEmpty()Returns `true` if this bounding box is empty, so contains no points, otherwise returns `false`. -
containsPoint
Returns whether the given point `p` is contained within this bounding box, either in its *interior* or incident to one of its edges or corners. -
containsBox
Returns whether every point of the given bounding box `b` is contained within this bounding box. -
intersectWith
Returns the intersection of this bounding box with the given bounding box `b`. -
equals
Returns whether this BoundingBox is equal to another, which is true when they have the same dimensions and upper left corners.
-