Class Rect2D


  • public class Rect2D
    extends Object
    Represents a 2D axis-aligned immutable rectangle.
    Author:
    Eduardo Ramos
    • Field Summary

      Fields 
      Modifier and Type Field Description
      float maxX  
      float maxY  
      float minX  
      float minY  
    • Constructor Summary

      Constructors 
      Constructor Description
      Rect2D​(float minX, float minY, float maxX, float maxY)
      Create a new Rect2D with the given minimum and maximum corner coordinates.
      Rect2D​(Rect2D source)
      Create a new Rect2D as a copy of the given source .
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float[] center()
      Return the rectangle's center, as an array where the first element is the x coordinate and the second element is the y coordinate.
      boolean contains​(float minX, float minY, float maxX, float maxY)
      Returns true if this rectangle contains the given rectangle.
      boolean contains​(Rect2D rect)
      Returns true if this rectangle contains the given rectangle.
      float height()
      Return the rectangle's height.
      boolean intersects​(float minX, float minY, float maxX, float maxY)
      Returns true if this rectangle intersects the given rectangle.
      boolean intersects​(Rect2D rect)
      Returns true if this rectangle intersects the given rectangle.
      float radius()
      Return the rectangle's radius.
      String toString()  
      float width()
      Return the rectangle's width.
    • Field Detail

      • minX

        public final float minX
      • minY

        public final float minY
      • maxX

        public final float maxX
      • maxY

        public final float maxY
    • Constructor Detail

      • Rect2D

        public Rect2D​(Rect2D source)
        Create a new Rect2D as a copy of the given source .
        Parameters:
        source - the Rect2D to copy from
      • Rect2D

        public Rect2D​(float minX,
                      float minY,
                      float maxX,
                      float maxY)
        Create a new Rect2D with the given minimum and maximum corner coordinates.
        Parameters:
        minX - the x coordinate of the minimum corner
        minY - the y coordinate of the minimum corner
        maxX - the x coordinate of the maximum corner
        maxY - the y coordinate of the maximum corner
    • Method Detail

      • width

        public float width()
        Return the rectangle's width.
        Returns:
        the rectangle's width
      • height

        public float height()
        Return the rectangle's height.
        Returns:
        the rectangle's height
      • center

        public float[] center()
        Return the rectangle's center, as an array where the first element is the x coordinate and the second element is the y coordinate.
        Returns:
        the rectangle's center
      • radius

        public float radius()
        Return the rectangle's radius.
        Returns:
        the rectangle's radius
      • contains

        public boolean contains​(Rect2D rect)
        Returns true if this rectangle contains the given rectangle.
        Parameters:
        rect - the rectangle to check
        Returns:
        true if this rectangle contains, false otherwise
      • intersects

        public boolean intersects​(Rect2D rect)
        Returns true if this rectangle intersects the given rectangle.
        Parameters:
        rect - the rectangle to check
        Returns:
        true if this rectangle intersects, false otherwise
      • contains

        public boolean contains​(float minX,
                                float minY,
                                float maxX,
                                float maxY)
        Returns true if this rectangle contains the given rectangle.
        Parameters:
        minX - the x coordinate of the minimum corner
        minY - the y coordinate of the minimum corner
        maxX - the x coordinate of the maximum corner
        maxY - the y coordinate of the maximum corner
        Returns:
        true if this rectangle contains, false otherwise
      • intersects

        public boolean intersects​(float minX,
                                  float minY,
                                  float maxX,
                                  float maxY)
        Returns true if this rectangle intersects the given rectangle.
        Parameters:
        minX - the x coordinate of the minimum corner
        minY - the y coordinate of the minimum corner
        maxX - the x coordinate of the maximum corner
        maxY - the y coordinate of the maximum corner
        Returns:
        true if this rectangle intersects, false otherwise