Class Bounds2d

    • Constructor Summary

      Constructors 
      Constructor Description
      Bounds2d​(double deltaX, double deltaY)
      Constructs a new Bounds2d around the origin (0, 0).
      Bounds2d​(double minX, double maxX, double minY, double maxY)
      Construct a Bounds2d by providing its lower and upper bounds in both dimensions.
      Bounds2d​(Collection<Point2d> points)
      Construct a Bounds2d from a collection of Point2d, finding the lowest and highest x and y coordinates.
      Bounds2d​(Iterator<? extends Point2d> points)
      Construct a Bounds2d from some collection of points, finding the lowest and highest x and y coordinates.
      Bounds2d​(Drawable2d drawable2d)
      Construct a Bounds2d for a Drawable2d.
      Bounds2d​(Point2d[] points)
      Construct a Bounds2d from an array of Point2d, finding the lowest and highest x and y coordinates.
    • Constructor Detail

      • Bounds2d

        public Bounds2d​(double minX,
                        double maxX,
                        double minY,
                        double maxY)
                 throws IllegalArgumentException
        Construct a Bounds2d by providing its lower and upper bounds in both dimensions.
        Parameters:
        minX - double; the lower bound for x
        maxX - double; the upper bound for x
        minY - double; the lower bound for y
        maxY - double; the upper bound for y
        Throws:
        IllegalArgumentException - when a lower bound is larger than the corresponding upper bound, or any of the bounds is NaN
      • Bounds2d

        public Bounds2d​(double deltaX,
                        double deltaY)
        Constructs a new Bounds2d around the origin (0, 0).
        Parameters:
        deltaX - double; the deltaX value around the origin
        deltaY - double; the deltaY value around the origin
        Throws:
        IllegalArgumentException - when one of the delta values is less than zero
      • Bounds2d

        public Bounds2d​(Iterator<? extends Point2d> points)
        Construct a Bounds2d from some collection of points, finding the lowest and highest x and y coordinates.
        Parameters:
        points - Iterator<? extends Point2d>; Iterator that will generate all the points for which to construct a Bounds2d
        Throws:
        NullPointerException - when points is null
        IllegalArgumentException - when the iterator provides zero points
      • Bounds2d

        public Bounds2d​(Drawable2d drawable2d)
                 throws NullPointerException
        Construct a Bounds2d for a Drawable2d.
        Parameters:
        drawable2d - Drawable2d; any object that implements the Drawable2d interface
        Throws:
        NullPointerException - when drawable2d is null
      • Bounds2d

        public Bounds2d​(Collection<Point2d> points)
        Construct a Bounds2d from a collection of Point2d, finding the lowest and highest x and y coordinates.
        Parameters:
        points - Collection<Point2d>; the collection of points to construct a Bounds2d from
        Throws:
        NullPointerException - when points is null
        IllegalArgumentException - when the collection is empty
    • Method Detail

      • getPoints

        public Iterator<Point2d> getPoints()
        Retrieve, or generate all points that make up the object.
        Specified by:
        getPoints in interface Drawable<Point2d,​Space2d>
        Returns:
        Iterable<Point2d>; an iterator that generates all points that make up the object
      • size

        public int size()
        Retrieve the number of points that make up the object.
        Specified by:
        size in interface Drawable<Point2d,​Space2d>
        Returns:
        int; the number of points that make up the object
      • contains

        public boolean contains​(Point2d point)
        Check if this Bounds2d contains a given point. Contains considers a point on the border of this Bounds2d to be outside.
        Parameters:
        point - Point2d; the point
        Returns:
        boolean; true this Bounds2d contains the point; false if this Bounds2d does not contain the point
        Throws:
        NullPointerException - when point is null
      • contains

        public boolean contains​(double x,
                                double y)
                         throws IllegalArgumentException
        Check if this Bounds2d contains a point. Contains considers a point on the border of this Bounds2d to be outside.
        Parameters:
        x - double; the x-coordinate of the point
        y - double; the y-coordinate of the point
        Returns:
        boolean; whether this Bounds2d contains the point
        Throws:
        IllegalArgumentException - when any of the coordinates is NaN
      • contains

        public boolean contains​(Drawable2d drawable)
                         throws NullPointerException
        Check if this Bounds2d completely contains a Drawable2d.
        Parameters:
        drawable - Drawable2d; the object for which to check if it is completely contained within this Bounds2d.
        Returns:
        boolean; false if any point of the Drawable2d is on or outside one of the borders of this Bounds2d; true when all points of the Drawable2d are contained within this Bounds2d.
        Throws:
        NullPointerException - when drawable2d is null
      • covers

        public boolean covers​(double x,
                              double y)
        Check if this Bounds2d contains a point. Covers returns true when the point is on, or within the border of this Bounds2d.
        Parameters:
        x - double; the x-coordinate of the point
        y - double; the y-coordinate of the point
        Returns:
        boolean; whether this Bounds2d, including its borders, contains the point
      • covers

        public boolean covers​(Point2d point)
        Check if this Bounds2d contains a point. Covers returns true when the point is on, or within the border of this Bounds2d.
        Parameters:
        point - Point2d; the point
        Returns:
        boolean; whether this Bounds2d, including its borders, contains the point
        Throws:
        NullPointerException - when point is null
      • covers

        public boolean covers​(Bounds2d otherBounds2d)
                       throws NullPointerException
        Check if this Bounds contains another Bounds. Covers returns true when one of the edges of the other Bounds (partly) overlaps a border of this Bounds.
        Specified by:
        covers in interface Bounds<Bounds2d,​Space2d>
        Parameters:
        otherBounds2d - B; the Bounds for which to check if it is contained within this Bounds
        Returns:
        boolean; whether this Bounds contains the provided Bounds, including overlapping borders
        Throws:
        NullPointerException - when otherBounds is null
      • disjoint

        public boolean disjoint​(Bounds2d otherBounds2d)
                         throws NullPointerException
        Return whether this Bounds is disjoint from another Bounds. Only touching at an edge is considered disjoint.
        Specified by:
        disjoint in interface Bounds<Bounds2d,​Space2d>
        Parameters:
        otherBounds2d - B; the other Bounds
        Returns:
        boolean; whether this Bounds is disjoint from another Bounds
        Throws:
        NullPointerException - when bounds is null
      • intersects

        public boolean intersects​(Bounds2d otherBounds2d)
                           throws NullPointerException
        Return whether this Bounds intersects another Bounds. Only touching at an edge is not seen as intersecting.
        Specified by:
        intersects in interface Bounds<Bounds2d,​Space2d>
        Parameters:
        otherBounds2d - B; the other Bounds
        Returns:
        boolean; whether this bounding rectangle intersects the other Bounds
        Throws:
        NullPointerException - when otherBounds is null
      • intersection

        public Bounds2d intersection​(Bounds2d otherBounds2d)
        Return the intersecting Bounds of this Bounds and another Bounds. Touching at the edge is not seen as intersecting. In case there is no intersection, null is returned.
        Specified by:
        intersection in interface Bounds<Bounds2d,​Space2d>
        Parameters:
        otherBounds2d - B; the other Bounds
        Returns:
        Bounds; the intersecting Bounds of this Bounds and another Bounds. Touching at the edge is not seen as intersecting. If not intersecting; null is returned
      • toRectangle2D

        public Rectangle2D toRectangle2D()
        Return an AWT Rectangle2D that covers the same area as this Bounds2d.
        Returns:
        Rectangle2D; the rectangle that covers the same area as this Bounds2d
      • getMinX

        public double getMinX()
        Return the lower bound for x.
        Specified by:
        getMinX in interface Bounds<Bounds2d,​Space2d>
        Returns:
        double; the lower bound for x
      • getMaxX

        public double getMaxX()
        Return the upper bound for x.
        Specified by:
        getMaxX in interface Bounds<Bounds2d,​Space2d>
        Returns:
        double; the upper bound for x
      • getMinY

        public double getMinY()
        Return the lower bound for y.
        Specified by:
        getMinY in interface Bounds<Bounds2d,​Space2d>
        Returns:
        double; the lower bound for y
      • getMaxY

        public double getMaxY()
        Return the upper bound for y.
        Specified by:
        getMaxY in interface Bounds<Bounds2d,​Space2d>
        Returns:
        double; the upper bound for y
      • midPoint

        public Point2d midPoint()
        Return the mid point of this Bounds2d.
        Returns:
        Point2d; the mid point of this Bounds2d
      • getArea

        public double getArea()
        Return the area of this Bounds2d.
        Returns:
        double; the area of this Bounds2d
      • getBounds

        public Bounds2d getBounds()
        Retrieve the bounding rectangle of the object.
        Specified by:
        getBounds in interface Drawable2d
        Returns:
        Bounds2d; the bounding box of the object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object