Class Rectangle


  • public class Rectangle
    extends java.lang.Object
    A rectangle on a plane.
    Author:
    Garret Wilson
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Rectangle EMPTY_RECTANGLE
      A predefined rectangle with zero size on the zero plane.
    • Constructor Summary

      Constructors 
      Constructor Description
      Rectangle​(double x, double y, double width, double height)
      Two-dimensional primitive pixel coordinates and dimensions constructor.
      Rectangle​(double x, double y, double z, double width, double height)
      Primitive pixel coordinates and dimensions constructor.
      Rectangle​(double x, double y, double z, double width, double height, Unit unit)
      Primitive coordinates, dimensions, and unit constructor.
      Rectangle​(double x, double y, double width, double height, Unit unit)
      Two-dimensional primitive coordinates, dimensions, and unit constructor.
      Rectangle​(Extent x, Extent y, Extent width, Extent height)
      Two-dimensional coordinates and dimensions constructor.
      Rectangle​(Extent x, Extent y, Extent z, Extent width, Extent height)
      Coordinates and dimensions constructor.
      Rectangle​(Point position, Dimensions size)
      Position and size constructor.
    • Field Detail

      • EMPTY_RECTANGLE

        public static final Rectangle EMPTY_RECTANGLE
        A predefined rectangle with zero size on the zero plane.
    • Constructor Detail

      • Rectangle

        public Rectangle​(double x,
                         double y,
                         double width,
                         double height)
        Two-dimensional primitive pixel coordinates and dimensions constructor.
        Parameters:
        x - The X coordinate.
        y - The Y coordinate.
        width - The width of the rectangle
        height - The height of the rectangle.
      • Rectangle

        public Rectangle​(double x,
                         double y,
                         double z,
                         double width,
                         double height)
        Primitive pixel coordinates and dimensions constructor.
        Parameters:
        x - The X coordinate.
        y - The Y coordinate.
        z - The Z coordinate.
        width - The width of the rectangle
        height - The height of the rectangle.
      • Rectangle

        public Rectangle​(double x,
                         double y,
                         double width,
                         double height,
                         Unit unit)
        Two-dimensional primitive coordinates, dimensions, and unit constructor.
        Parameters:
        x - The X coordinate.
        y - The Y coordinate.
        width - The width of the rectangle
        height - The height of the rectangle.
        unit - The unit in which the point is measured.
      • Rectangle

        public Rectangle​(double x,
                         double y,
                         double z,
                         double width,
                         double height,
                         Unit unit)
        Primitive coordinates, dimensions, and unit constructor.
        Parameters:
        x - The X coordinate.
        y - The Y coordinate.
        z - The Z coordinate.
        width - The width of the rectangle
        height - The height of the rectangle.
        unit - The unit in which the point is measured.
      • Rectangle

        public Rectangle​(Extent x,
                         Extent y,
                         Extent width,
                         Extent height)
        Two-dimensional coordinates and dimensions constructor.
        Parameters:
        x - The X coordinate.
        y - The Y coordinate.
        width - The width of the rectangle
        height - The height of the rectangle.
      • Rectangle

        public Rectangle​(Extent x,
                         Extent y,
                         Extent z,
                         Extent width,
                         Extent height)
        Coordinates and dimensions constructor.
        Parameters:
        x - The X coordinate.
        y - The Y coordinate.
        z - The Z coordinate.
        width - The width of the rectangle
        height - The height of the rectangle.
      • Rectangle

        public Rectangle​(Point position,
                         Dimensions size)
        Position and size constructor.
        Parameters:
        position - The position of the upper-left corner of the rectangle.
        size - The size of the rectangle, which is guaranteed to have zero depth.
        Throws:
        java.lang.NullPointerException - if the position and/or size is null.
        java.lang.IllegalArgumentException - if the size has a non-zero depth.
    • Method Detail

      • getPosition

        public Point getPosition()
        Returns:
        The position of the upper-left corner of the rectangle.
      • getSize

        public Dimensions getSize()
        Returns:
        The size of the rectangle, which is guaranteed to have zero depth.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object object)

        This implementation returns whether the object is another rectangle with equivalent position and size.

        Overrides:
        equals in class java.lang.Object
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object