Class Rectangle

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Shape>

    public final class Rectangle
    extends AbstractPolygon
    Defines a rectangle.

    WARNING: this API is experimental and will likely change in the near future.

    See Also:
    Serialized Form
    • Constructor Detail

      • Rectangle

        public Rectangle()
      • Rectangle

        public Rectangle​(Point min,
                         Point max)
        Constructs a rectangle with specified dimensions.
      • Rectangle

        public Rectangle​(double minX,
                         double minY,
                         double maxX,
                         double maxY)
        Constructs a rectangle with specified dimensions.
    • Method Detail

      • getTypeName

        public java.lang.String getTypeName()
        Specified by:
        getTypeName in class Shape
      • getWidth

        public double getWidth()
        Get the width of this shape's bounding box.
        Specified by:
        getWidth in class Shape
      • getHeight

        public double getHeight()
        Get the height of this shape's bounding box.
        Specified by:
        getHeight in class Shape
      • size

        public int size()
        Return the number of vertices in this polygon.
        Specified by:
        size in class AbstractPolygon
      • fastGetX

        public double fastGetX​(int index)
        Get the X coordinate of the Point at index.

        WARNING: this method assumes that index is positive and less than AbstractPolygon.size().

        Specified by:
        fastGetX in class AbstractPolygon
      • fastGetY

        public double fastGetY​(int index)
        Get the Y coordinate of the Point at index.

        WARNING: this method assumes that index is positive and less than AbstractPolygon.size().

        Specified by:
        fastGetY in class AbstractPolygon
      • getMinimum

        public Point getMinimum()
      • setMinimum

        public void setMinimum​(Point value)
      • getMinimumX

        public double getMinimumX()
      • setMinimumX

        public void setMinimumX​(double value)
      • getMinimumY

        public double getMinimumY()
      • setMinimumY

        public void setMinimumY​(double value)
      • getMaximum

        public Point getMaximum()
      • setMaximum

        public void setMaximum​(Point value)
      • getMaximumX

        public double getMaximumX()
      • setMaximumX

        public void setMaximumX​(double value)
      • getMaximumY

        public double getMaximumY()
      • setMaximumY

        public void setMaximumY​(double value)
      • getBoundingBox

        public Rectangle getBoundingBox()
        Get the rectangle that represents the bounding box that fully contains this shape.
        Specified by:
        getBoundingBox in class Shape
      • contains

        public boolean contains​(double x,
                                double y)
        Return true if this shape contains the point defined by (x, y).
        Specified by:
        contains in class Shape
      • fastIntersects

        public boolean fastIntersects​(Rectangle box)
        Check if this shape's bounding box intersects with box.
        Specified by:
        fastIntersects in class Shape
      • intersects

        public boolean intersects​(double minX,
                                  double minY,
                                  double maxX,
                                  double maxY)
        Check if this rectangle intersects with rectangle defined by (minX, minY), (maxX, maxY).
      • intersects

        protected static boolean intersects​(double minX1,
                                            double minY1,
                                            double maxX1,
                                            double maxY1,
                                            double minX2,
                                            double minY2,
                                            double maxX2,
                                            double maxY2)
        Check if 2 bounding boxes intersect.
      • lineIntersects

        public boolean lineIntersects​(double x1,
                                      double y1,
                                      double x2,
                                      double y2)
        Check if the line (x1, y1), (x2, y2) intersects with this polygon.
        Specified by:
        lineIntersects in class AbstractPolygon
      • addArguments

        public void addArguments​(java.lang.StringBuilder buffer)
        Specified by:
        addArguments in class Shape
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Description copied from class: Shape
        Overrides:
        hashCode in class Shape
      • getBoundingBox

        public static Rectangle getBoundingBox​(Shape a,
                                               Shape b)
        Get a bounding box that contains both a and b.
      • writeExternal

        public void writeExternal​(java.io.DataOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in class Shape
        Throws:
        java.io.IOException
      • readExternal

        public Rectangle readExternal​(java.io.DataInput in)
                               throws java.io.IOException
        Specified by:
        readExternal in class Shape
        Throws:
        java.io.IOException