Class Rectangle

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
Allocation

@Generated("org.javagi.JavaGI") public class Rectangle extends ProxyInstance

Represents a rectangle.

GdkRectangle is identical to cairo_rectangle_t. Together with Cairo’s cairo_region_t data type, these are the central types for representing sets of pixels.

The intersection of two rectangles can be computed with intersect(Rectangle, Rectangle); to find the union of two rectangles use union(Rectangle, Rectangle).

The cairo_region_t type provided by Cairo is usually used for managing non-rectangular clipping of graphical operations.

The Graphene library has a number of other data types for regions and volumes in 2D and 3D.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Allocate a new Rectangle.
    Rectangle(int x, int y, int width, int height)
    Allocate a new Rectangle with the fields set to the provided values.
    Rectangle(int x, int y, int width, int height, Arena arena)
    Allocate a new Rectangle with the fields set to the provided values.
    Allocate a new Rectangle.
    Create a Rectangle proxy instance for the provided memory address.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    containsPoint(int x, int y)
    Returns true if this Rectangle contains the point described by x and y.
    boolean
    Checks if the two given rectangles are equal.
    The memory layout of the native struct.
    static @Nullable Type
    Get the GType of the Rectangle class.
    boolean
    intersect(Rectangle src2, @Nullable Rectangle dest)
    Calculates the intersection of two rectangles.
    int
    Read the value of the field height.
    int
    Read the value of the field width.
    int
    Read the value of the field x.
    int
    Read the value of the field y.
    void
    union(Rectangle src2, Rectangle dest)
    Calculates the union of two rectangles.
    void
    writeHeight(int height)
    Write a value in the field height.
    void
    writeWidth(int width)
    Write a value in the field width.
    void
    writeX(int x)
    Write a value in the field x.
    void
    writeY(int y)
    Write a value in the field y.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

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

    • Rectangle

      public Rectangle(MemorySegment address)
      Create a Rectangle proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Rectangle

      public Rectangle(Arena arena)
      Allocate a new Rectangle.
      Parameters:
      arena - to control the memory allocation scope
    • Rectangle

      public Rectangle()
      Allocate a new Rectangle. The memory is allocated with Arena.ofAuto().
    • Rectangle

      public Rectangle(int x, int y, int width, int height, Arena arena)
      Allocate a new Rectangle with the fields set to the provided values.
      Parameters:
      x - value for the field x
      y - value for the field y
      width - value for the field width
      height - value for the field height
      arena - to control the memory allocation scope
    • Rectangle

      public Rectangle(int x, int y, int width, int height)
      Allocate a new Rectangle with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      x - value for the field x
      y - value for the field y
      width - value for the field width
      height - value for the field height
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Rectangle class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readX

      public int readX()
      Read the value of the field x.
      Returns:
      The value of the field x
    • writeX

      public void writeX(int x)
      Write a value in the field x.
      Parameters:
      x - The new value for the field x
    • readY

      public int readY()
      Read the value of the field y.
      Returns:
      The value of the field y
    • writeY

      public void writeY(int y)
      Write a value in the field y.
      Parameters:
      y - The new value for the field y
    • readWidth

      public int readWidth()
      Read the value of the field width.
      Returns:
      The value of the field width
    • writeWidth

      public void writeWidth(int width)
      Write a value in the field width.
      Parameters:
      width - The new value for the field width
    • readHeight

      public int readHeight()
      Read the value of the field height.
      Returns:
      The value of the field height
    • writeHeight

      public void writeHeight(int height)
      Write a value in the field height.
      Parameters:
      height - The new value for the field height
    • containsPoint

      public boolean containsPoint(int x, int y)
      Returns true if this Rectangle contains the point described by x and y.
      Parameters:
      x - X coordinate
      y - Y coordinate
      Returns:
      true if this Rectangle contains the point
    • equal

      public boolean equal(Rectangle rect2)
      Checks if the two given rectangles are equal.
      Parameters:
      rect2 - a GdkRectangle
      Returns:
      true if the rectangles are equal.
    • intersect

      public boolean intersect(Rectangle src2, @Nullable Rectangle dest)

      Calculates the intersection of two rectangles.

      It is allowed for dest to be the same as either this Rectangle or src2. If the rectangles do not intersect, dest’s width and height is set to 0 and its x and y values are undefined. If you are only interested in whether the rectangles intersect, but not in the intersecting area itself, pass null for dest.

      Parameters:
      src2 - a GdkRectangle
      dest - return location for the intersection of this Rectangle and src2
      Returns:
      true if the rectangles intersect.
    • union

      public void union(Rectangle src2, Rectangle dest)

      Calculates the union of two rectangles.

      The union of rectangles this Rectangle and src2 is the smallest rectangle which includes both this Rectangle and src2 within it. It is allowed for dest to be the same as either this Rectangle or src2.

      Note that this function does not ignore 'empty' rectangles (ie. with zero width or height).

      Parameters:
      src2 - a GdkRectangle
      dest - return location for the union of this Rectangle and src2