Record Class Rectangle

java.lang.Object
java.lang.Record
technology.sola.math.geometry.Rectangle
Record Components:
min - the top, left point of the rectangle
max - the bottom, right point of the rectangle
All Implemented Interfaces:
Shape

@NullMarked public record Rectangle(Vector2D min, Vector2D max) extends Record implements Shape
Rectangle represents an axis aligned geometric rectangle.
  • Constructor Details

    • Rectangle

      public Rectangle(Vector2D min, Vector2D max)
      Creates a rectangle by min and max points.

      The min point's x and y must both be below the max point's x and y. If they are the same then a degenerate rectangle with width or height of zero will be created.

      Parameters:
      min - the top, left point of the rectangle
      max - the bottom, right point of the rectangle
  • Method Details

    • contains

      public boolean contains(Vector2D point)
      Description copied from interface: Shape
      Checks if this Shape contains a point.
      Specified by:
      contains in interface Shape
      Parameters:
      point - the point to check
      Returns:
      true if this shape contains the point
    • getArea

      public float getArea()
      Description copied from interface: Shape
      Calculates the area of this shape and return it.
      Specified by:
      getArea in interface Shape
      Returns:
      the area of this shape
    • getPoints

      public Vector2D[] getPoints()
      Specified by:
      getPoints in interface Shape
      Returns:
      the array of points making up this shape
    • getWidth

      public float getWidth()
      Gets the width of the rectangle.
      Returns:
      the width
    • getHeight

      public float getHeight()
      Gets the height of the rectangle.
      Returns:
      the height
    • intersects

      public boolean intersects(Rectangle rectangle)
      Checks to see if this Rectangle intersects with another Rectangle.
      Parameters:
      rectangle - the other Rectangle to check intersection with
      Returns:
      true if they are intersecting
    • getCenter

      public Vector2D getCenter()
      Returns:
      the center point of the rectangle
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • min

      public Vector2D min()
      Returns the value of the min record component.
      Returns:
      the value of the min record component
    • max

      public Vector2D max()
      Returns the value of the max record component.
      Returns:
      the value of the max record component