Record Class Rect

java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Rect
All Implemented Interfaces:
Shape

public record Rect(float x, float y, float width, float height) extends Record implements Shape
Two-dimensional rectangle with coordinates defined with float precision. Rectangles are specified using their top-left coordinate, width, and height. Methods are provided for obtaining the rectangle's X1 and Y1 coordinates and its center.
  • Field Summary

    Fields inherited from interface nl.colorize.multimedialib.math.Shape

    EPSILON
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rect(float x, float y, float width, float height)
    Creates an instance of a Rect record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Rect
    around(float x, float y, float width, float height)
    Returns a rectangle that has X and Y coordinates so that the specified point becomes its center.
    static Rect
    around(Point2D center, float width, float height)
    Returns a rectangle that has X and Y coordinates so that the specified point becomes its center.
    boolean
    contains(float px, float py)
     
    boolean
    Returns whether this shape contains the specified point.
    boolean
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    static Rect
    fromPoints(float x0, float y0, float x1, float y1)
    Created a rectangle from 4 points (x0, y0, x1, y1) instead of requiring its width and height.
    Returns the smallest possible rectangular bounding box that can fit this shape.
     
    float
     
    float
     
    float
     
    float
     
    final int
    Returns a hash code value for this object.
    float
    Returns the value of the height record component.
    boolean
     
    Returns a new Shape instance that is repositioned by the specified X and Y offset.
     
    Returns a string representation of this record class.
    float
    Returns the value of the width record component.
    float
    x()
    Returns the value of the x record component.
    float
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface nl.colorize.multimedialib.math.Shape

    reposition
  • Constructor Details

    • Rect

      public Rect(float x, float y, float width, float height)
      Creates an instance of a Rect record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
      width - the value for the width record component
      height - the value for the height record component
  • Method Details

    • getEndX

      public float getEndX()
    • getEndY

      public float getEndY()
    • getCenterX

      public float getCenterX()
    • getCenterY

      public float getCenterY()
    • getCenter

      public Point2D getCenter()
    • contains

      public boolean contains(Point2D p)
      Description copied from interface: Shape
      Returns whether this shape contains the specified point.
      Specified by:
      contains in interface Shape
    • contains

      public boolean contains(float px, float py)
    • contains

      public boolean contains(Rect r)
    • intersects

      public boolean intersects(Rect r)
    • getBoundingBox

      public Rect getBoundingBox()
      Description copied from interface: Shape
      Returns the smallest possible rectangular bounding box that can fit this shape.
      Specified by:
      getBoundingBox in interface Shape
    • reposition

      public Rect reposition(Point2D offset)
      Description copied from interface: Shape
      Returns a new Shape instance that is repositioned by the specified X and Y offset.
      Specified by:
      reposition in interface Shape
    • toPolygon

      public Polygon toPolygon()
    • toString

      public 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
    • fromPoints

      public static Rect fromPoints(float x0, float y0, float x1, float y1)
      Created a rectangle from 4 points (x0, y0, x1, y1) instead of requiring its width and height.
    • around

      public static Rect around(float x, float y, float width, float height)
      Returns a rectangle that has X and Y coordinates so that the specified point becomes its center.
    • around

      public static Rect around(Point2D center, float width, float height)
      Returns a rectangle that has X and Y coordinates so that the specified point becomes its center.
    • 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 '=='.
      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.
    • x

      public float x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public float y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component
    • width

      public float width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public float height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component