Class Rectangle

java.lang.Object
org.djutils.quadtree.Rectangle
All Implemented Interfaces:
Serializable

public class Rectangle extends Object implements Serializable
Rectangle defines an area bounded by a lower and left edges (inclusive) and a upper and right edges (not inclusive). The boundary values are stored in the object; unlike the Rectangle2D class where the width and height are stored and to the left and bottom. Doing it this way absolutely ensures that we can make a grid of rectangles that have no ULP width gaps. Additionally, this Rectangle object is immutable. Finally, there is no annoying name collision with the java.lang.Double class.

Copyright (c) 2020-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
Author:
Alexander Verbraeck, Peter Knoppers
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rectangle(double left, double bottom, double right, double top)
    Construct a new Rectangle without checking the arguments for making sense.
    Rectangle(double left, double bottom, double right, double top, boolean check)
    Construct a new Rectangle; all arguments are checked for having sensible values.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(double x, double y)
    Determine if this Rectangle contains a point.
    boolean
    Determine if this Rectangle contains all points of another Rectangle.
    double
    Retrieve the bottom boundary value.
    double
    Return the height of this Rectangle.
    double
    Retrieve the left boundary value.
    double
    Retrieve the right boundary value.
    double
    Retrieve the top boundary value.
    double
    Return the width of this Rectangle.
    boolean
    Determine if this Rectangle intersects another Rectangle.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Rectangle

      public Rectangle(double left, double bottom, double right, double top, boolean check)
      Construct a new Rectangle; all arguments are checked for having sensible values.
      Parameters:
      left - double; the left boundary (inclusive)
      bottom - double; the bottom boundary (inclusive)
      right - double; the right boundary (not inclusive)
      top - double; the top boundary (not inclusive)
      check - boolean; if true; the values are checked for making sense
    • Rectangle

      public Rectangle(double left, double bottom, double right, double top)
      Construct a new Rectangle without checking the arguments for making sense.
      Parameters:
      left - double; the left boundary (inclusive)
      bottom - double; the bottom boundary (inclusive)
      right - double; the right boundary (not inclusive)
      top - double; the top boundary (not inclusive)
  • Method Details

    • getLeft

      public double getLeft()
      Retrieve the left boundary value.
      Returns:
      double; the left boundary value
    • getBottom

      public double getBottom()
      Retrieve the bottom boundary value.
      Returns:
      double; the bottom boundary value
    • getRight

      public double getRight()
      Retrieve the right boundary value.
      Returns:
      double; the right boundary value
    • getTop

      public double getTop()
      Retrieve the top boundary value.
      Returns:
      double; the top boundary value
    • getWidth

      public double getWidth()
      Return the width of this Rectangle.
      Returns:
      double; the width of this Rectangle
    • getHeight

      public double getHeight()
      Return the height of this Rectangle.
      Returns:
      double; the height of this Rectangle
    • intersects

      public boolean intersects(Rectangle other)
      Determine if this Rectangle intersects another Rectangle.
      Parameters:
      other - Rectangle; the other rectangle
      Returns:
      boolean; true if the rectangles intersect, false if the rectangles do not intersect
    • contains

      public boolean contains(double x, double y)
      Determine if this Rectangle contains a point.
      Parameters:
      x - double; x-coordinate of the point
      y - double; y-coordinate of the point
      Returns:
      boolean; true if this Rectangle contains the point; false if this Rectangle does not contain the point
    • contains

      public boolean contains(Rectangle other)
      Determine if this Rectangle contains all points of another Rectangle.
      Parameters:
      other - Rectangle; the other rectangle
      Returns:
      boolean; true if this Rectangle contains all points of the other Rectangle; false if this Rectangle does not contain all points of the other Rectangle
    • toString

      public String toString()
      Overrides:
      toString in class Object