Class Rectangle

java.lang.Object
com.cedarsoftware.util.geom.Rectangle

public final class Rectangle extends Object
Zero-dependency geometric primitive - Immutable Rectangle class representing a rectangular region defined by location (x, y) and size (width, height).

This class provides an API-compatible replacement for java.awt.Rectangle without requiring the java.desktop module (~8MB), making it ideal for headless servers, microservices, and modular applications.

No AWT dependency - This class is completely independent and does not require java.awt.

Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

License

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rectangle(int x, int y, int width, int height)
    Creates a Rectangle at location (x, y) with the specified width and height.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    int
    Returns the height of this Rectangle.
    int
    Returns the width of this Rectangle.
    int
    Returns the x coordinate of the upper-left corner.
    int
    Returns the y coordinate of the upper-left corner.
    int
     
     

    Methods inherited from class java.lang.Object

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

    • Rectangle

      public Rectangle(int x, int y, int width, int height)
      Creates a Rectangle at location (x, y) with the specified width and height.
      Parameters:
      x - the x coordinate of the upper-left corner
      y - the y coordinate of the upper-left corner
      width - the width of the rectangle
      height - the height of the rectangle
  • Method Details

    • getX

      public int getX()
      Returns the x coordinate of the upper-left corner.
    • getY

      public int getY()
      Returns the y coordinate of the upper-left corner.
    • getWidth

      public int getWidth()
      Returns the width of this Rectangle.
    • getHeight

      public int getHeight()
      Returns the height of this Rectangle.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object