Package cs2110

Class BoundingBox

java.lang.Object
cs2110.BoundingBox

public class BoundingBox extends Object
An immutable, axis-aligned, closed rectangle in the 2D coordinate plane.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs 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 Type
    Method
    Description
    double
    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
    equals(Object other)
    Returns whether this BoundingBox is equal to another, which is true when they have the same dimensions and upper left corners.
    double
    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
    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
    Returns the width of this bounding box (in units of the coordinate system).

    Methods inherited from class java.lang.Object

    getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BoundingBox

      public BoundingBox()
      Constructs an empty bounding box that contains no points.
    • BoundingBox

      public BoundingBox(Point corner, double width, double height)
      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

      public Point 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

      public boolean containsPoint(Point p)
      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

      public boolean containsBox(BoundingBox b)
      Returns whether every point of the given bounding box `b` is contained within this bounding box.
    • intersectWith

      public BoundingBox intersectWith(BoundingBox b)
      Returns the intersection of this bounding box with the given bounding box `b`.
    • equals

      public boolean equals(Object other)
      Returns whether this BoundingBox is equal to another, which is true when they have the same dimensions and upper left corners.
      Overrides:
      equals in class Object