Class Rect

All Implemented Interfaces:
Proxy

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

The location and size of a rectangle region.

The width and height of a graphene_rect_t can be negative; for instance, a graphene_rect_t with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is equivalent to a graphene_rect_t with an origin of [ 10, 10 ] and a size of [ -10, -10 ].

Application code can normalize rectangles using graphene_rect_normalize(); this function will ensure that the width and height of a rectangle are positive values. All functions taking a graphene_rect_t as an argument will internally operate on a normalized copy; all functions returning a graphene_rect_t will always return a normalized rectangle.

Since:
1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Allocate a new Rect.
    Rect(Arena arena)
    Allocate a new Rect.
    Create a Rect proxy instance for the provided memory address.
    Rect(Point origin, Size size)
    Allocate a new Rect with the fields set to the provided values.
    Rect(Point origin, Size size, Arena arena)
    Allocate a new Rect with the fields set to the provided values.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Rect
    Allocates a new graphene_rect_t.
    boolean
    Checks whether a graphene_rect_t contains the given coordinates.
    boolean
    Checks whether a graphene_rect_t fully contains the given rectangle.
    boolean
    Checks whether the two given rectangle are equal.
    void
    expand(Point p, Rect res)
    Expands a graphene_rect_t to contain the given graphene_point_t.
    void
    Frees the resources allocated by graphene_rect_alloc().
    float
    Compute the area of given normalized rectangle.
    void
    Retrieves the coordinates of the bottom-left corner of the given rectangle.
    void
    Retrieves the coordinates of the bottom-right corner of the given rectangle.
    void
    Retrieves the coordinates of the center of the given rectangle.
    float
    Retrieves the normalized height of the given rectangle.
    The memory layout of the native struct.
    void
    Retrieves the coordinates of the top-left corner of the given rectangle.
    void
    Retrieves the coordinates of the top-right corner of the given rectangle.
    static @Nullable Type
    Get the GType of the Rect class.
    void
    getVertices(@Nullable Out<Vec2[]> vertices)
    Computes the four vertices of a graphene_rect_t.
    float
    Retrieves the normalized width of the given rectangle.
    float
    Retrieves the normalized X coordinate of the origin of the given rectangle.
    float
    Retrieves the normalized Y coordinate of the origin of the given rectangle.
    init(float x, float y, float width, float height)
    Initializes the given graphene_rect_t with the given values.
    Initializes this Rect using the given src rectangle.
    inset(float dX, float dY)
    Changes the given rectangle to be smaller, or larger depending on the given inset parameters.
    void
    insetR(float dX, float dY, Rect res)
    Changes the given rectangle to be smaller, or larger depending on the given inset parameters.
    void
    interpolate(Rect b, double factor, Rect res)
    Linearly interpolates the origin and size of the two given rectangles.
    boolean
    intersection(Rect b, @Nullable Rect res)
    Computes the intersection of the two given rectangles.
    Normalizes the passed rectangle.
    void
    Normalizes the passed rectangle.
    offset(float dX, float dY)
    Offsets the origin by dX and dY.
    void
    offsetR(float dX, float dY, Rect res)
    Offsets the origin of the given rectangle by dX and dY.
    @Nullable Point
    Read the value of the field origin.
    @Nullable Size
    Read the value of the field size.
    void
    round(Rect res)
    Deprecated.
    Use graphene_rect_round_extents() instead
    void
    Rounds the origin of the given rectangle to its nearest integer value and and recompute the size so that the rectangle is large enough to contain all the conrners of the original rectangle.
    Deprecated.
    Use graphene_rect_round() instead
    void
    scale(float sH, float sV, Rect res)
    Scales the size and origin of a rectangle horizontaly by sH, and vertically by sV. The result res is normalized.
    void
    union(Rect b, Rect res)
    Computes the union of the two given rectangles.
    void
    writeOrigin(@Nullable Point origin)
    Write a value in the field origin.
    void
    writeSize(@Nullable Size size)
    Write a value in the field size.
    static Rect
    Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

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

    • Rect

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

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

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

      public Rect(Point origin, Size size, Arena arena)
      Allocate a new Rect with the fields set to the provided values.
      Parameters:
      origin - value for the field origin
      size - value for the field size
      arena - to control the memory allocation scope
    • Rect

      public Rect(Point origin, Size size)
      Allocate a new Rect with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      origin - value for the field origin
      size - value for the field size
  • Method Details

    • getType

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

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

      public @Nullable Point readOrigin()
      Read the value of the field origin.
      Returns:
      The value of the field origin
    • writeOrigin

      public void writeOrigin(@Nullable Point origin)
      Write a value in the field origin.
      Parameters:
      origin - The new value for the field origin
    • readSize

      public @Nullable Size readSize()
      Read the value of the field size.
      Returns:
      The value of the field size
    • writeSize

      public void writeSize(@Nullable Size size)
      Write a value in the field size.
      Parameters:
      size - The new value for the field size
    • alloc

      public static Rect alloc()

      Allocates a new graphene_rect_t.

      The contents of the returned rectangle are undefined.

      Returns:
      the newly allocated rectangle
      Since:
      1.0
    • zero

      public static Rect zero()
      Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.
      Returns:
      a fixed rectangle
      Since:
      1.4
    • containsPoint

      public boolean containsPoint(Point p)
      Checks whether a graphene_rect_t contains the given coordinates.
      Parameters:
      p - a graphene_point_t
      Returns:
      true if the rectangle contains the point
      Since:
      1.0
    • containsRect

      public boolean containsRect(Rect b)
      Checks whether a graphene_rect_t fully contains the given rectangle.
      Parameters:
      b - a graphene_rect_t
      Returns:
      true if the rectangle this Rect fully contains b
      Since:
      1.0
    • equal

      public boolean equal(Rect b)
      Checks whether the two given rectangle are equal.
      Parameters:
      b - a graphene_rect_t
      Returns:
      true if the rectangles are equal
      Since:
      1.0
    • expand

      public void expand(Point p, Rect res)
      Expands a graphene_rect_t to contain the given graphene_point_t.
      Parameters:
      p - a graphene_point_t
      res - return location for the expanded rectangle
      Since:
      1.4
    • free

      public void free()
      Frees the resources allocated by graphene_rect_alloc().
      Since:
      1.0
    • getArea

      public float getArea()
      Compute the area of given normalized rectangle.
      Returns:
      the area of the normalized rectangle
      Since:
      1.10
    • getBottomLeft

      public void getBottomLeft(Point p)
      Retrieves the coordinates of the bottom-left corner of the given rectangle.
      Parameters:
      p - return location for a graphene_point_t
      Since:
      1.0
    • getBottomRight

      public void getBottomRight(Point p)
      Retrieves the coordinates of the bottom-right corner of the given rectangle.
      Parameters:
      p - return location for a graphene_point_t
      Since:
      1.0
    • getCenter

      public void getCenter(Point p)
      Retrieves the coordinates of the center of the given rectangle.
      Parameters:
      p - return location for a graphene_point_t
      Since:
      1.0
    • getHeight

      public float getHeight()
      Retrieves the normalized height of the given rectangle.
      Returns:
      the normalized height of the rectangle
      Since:
      1.0
    • getTopLeft

      public void getTopLeft(Point p)
      Retrieves the coordinates of the top-left corner of the given rectangle.
      Parameters:
      p - return location for a graphene_point_t
      Since:
      1.0
    • getTopRight

      public void getTopRight(Point p)
      Retrieves the coordinates of the top-right corner of the given rectangle.
      Parameters:
      p - return location for a graphene_point_t
      Since:
      1.0
    • getVertices

      public void getVertices(@Nullable Out<Vec2[]> vertices)
      Computes the four vertices of a graphene_rect_t.
      Parameters:
      vertices - return location for an array of 4 graphene_vec2_t
      Since:
      1.4
    • getWidth

      public float getWidth()
      Retrieves the normalized width of the given rectangle.
      Returns:
      the normalized width of the rectangle
      Since:
      1.0
    • getX

      public float getX()
      Retrieves the normalized X coordinate of the origin of the given rectangle.
      Returns:
      the normalized X coordinate of the rectangle
      Since:
      1.0
    • getY

      public float getY()
      Retrieves the normalized Y coordinate of the origin of the given rectangle.
      Returns:
      the normalized Y coordinate of the rectangle
      Since:
      1.0
    • init

      public Rect init(float x, float y, float width, float height)

      Initializes the given graphene_rect_t with the given values.

      This function will implicitly normalize the graphene_rect_t before returning.

      Parameters:
      x - the X coordinate of the grapheneRectT.origin
      y - the Y coordinate of the grapheneRectT.origin
      width - the width of the grapheneRectT.size
      height - the height of the grapheneRectT.size
      Returns:
      the initialized rectangle
      Since:
      1.0
    • initFromRect

      public Rect initFromRect(Rect src)

      Initializes this Rect using the given src rectangle.

      This function will implicitly normalize the graphene_rect_t before returning.

      Parameters:
      src - a graphene_rect_t
      Returns:
      the initialized rectangle
      Since:
      1.0
    • inset

      public Rect inset(float dX, float dY)

      Changes the given rectangle to be smaller, or larger depending on the given inset parameters.

      To create an inset rectangle, use positive dX or dY values; to create a larger, encompassing rectangle, use negative dX or dY values.

      The origin of the rectangle is offset by dX and dY, while the size is adjusted by (2 * @d_x, 2 * @d_y). If dX and dY are positive values, the size of the rectangle is decreased; if dX and dY are negative values, the size of the rectangle is increased.

      If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.

      Parameters:
      dX - the horizontal inset
      dY - the vertical inset
      Returns:
      the inset rectangle
      Since:
      1.0
    • insetR

      public void insetR(float dX, float dY, Rect res)

      Changes the given rectangle to be smaller, or larger depending on the given inset parameters.

      To create an inset rectangle, use positive dX or dY values; to create a larger, encompassing rectangle, use negative dX or dY values.

      The origin of the rectangle is offset by dX and dY, while the size is adjusted by (2 * @d_x, 2 * @d_y). If dX and dY are positive values, the size of the rectangle is decreased; if dX and dY are negative values, the size of the rectangle is increased.

      If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.

      Parameters:
      dX - the horizontal inset
      dY - the vertical inset
      res - return location for the inset rectangle
      Since:
      1.4
    • interpolate

      public void interpolate(Rect b, double factor, Rect res)
      Linearly interpolates the origin and size of the two given rectangles.
      Parameters:
      b - a graphene_rect_t
      factor - the linear interpolation factor
      res - return location for the interpolated rectangle
      Since:
      1.0
    • intersection

      public boolean intersection(Rect b, @Nullable Rect res)

      Computes the intersection of the two given rectangles.

      The intersection in the image above is the blue outline.

      If the two rectangles do not intersect, res will contain a degenerate rectangle with origin in (0, 0) and a size of 0.

      Parameters:
      b - a graphene_rect_t
      res - return location for a graphene_rect_t
      Returns:
      true if the two rectangles intersect
      Since:
      1.0
    • normalize

      public Rect normalize()

      Normalizes the passed rectangle.

      This function ensures that the size of the rectangle is made of positive values, and that the origin is the top-left corner of the rectangle.

      Returns:
      the normalized rectangle
      Since:
      1.0
    • normalizeR

      public void normalizeR(Rect res)

      Normalizes the passed rectangle.

      This function ensures that the size of the rectangle is made of positive values, and that the origin is in the top-left corner of the rectangle.

      Parameters:
      res - the return location for the normalized rectangle
      Since:
      1.4
    • offset

      public Rect offset(float dX, float dY)

      Offsets the origin by dX and dY.

      The size of the rectangle is unchanged.

      Parameters:
      dX - the horizontal offset
      dY - the vertical offset
      Returns:
      the offset rectangle
      Since:
      1.0
    • offsetR

      public void offsetR(float dX, float dY, Rect res)

      Offsets the origin of the given rectangle by dX and dY.

      The size of the rectangle is left unchanged.

      Parameters:
      dX - the horizontal offset
      dY - the vertical offset
      res - return location for the offset rectangle
      Since:
      1.4
    • round

      @Deprecated public void round(Rect res)
      Deprecated.
      Use graphene_rect_round_extents() instead

      Rounds the origin and size of the given rectangle to their nearest integer values; the rounding is guaranteed to be large enough to have an area bigger or equal to the original rectangle, but might not fully contain its extents. Use graphene_rect_round_extents() in case you need to round to a rectangle that covers fully the original one.

      This function is the equivalent of calling floor on the coordinates of the origin, and ceil on the size.

      Parameters:
      res - return location for the rounded rectangle
      Since:
      1.4
    • roundExtents

      public void roundExtents(Rect res)

      Rounds the origin of the given rectangle to its nearest integer value and and recompute the size so that the rectangle is large enough to contain all the conrners of the original rectangle.

      This function is the equivalent of calling floor on the coordinates of the origin, and recomputing the size calling ceil on the bottom-right coordinates.

      If you want to be sure that the rounded rectangle completely covers the area that was covered by the original rectangle — i.e. you want to cover the area including all its corners — this function will make sure that the size is recomputed taking into account the ceiling of the coordinates of the bottom-right corner. If the difference between the original coordinates and the coordinates of the rounded rectangle is greater than the difference between the original size and and the rounded size, then the move of the origin would not be compensated by a move in the anti-origin, leaving the corners of the original rectangle outside the rounded one.

      Parameters:
      res - return location for the rectangle with rounded extents
      Since:
      1.10
    • roundToPixel

      @Deprecated public Rect roundToPixel()
      Deprecated.
      Use graphene_rect_round() instead
      Rounds the origin and the size of the given rectangle to their nearest integer values; the rounding is guaranteed to be large enough to contain the original rectangle.
      Returns:
      the pixel-aligned rectangle.
      Since:
      1.0
    • scale

      public void scale(float sH, float sV, Rect res)
      Scales the size and origin of a rectangle horizontaly by sH, and vertically by sV. The result res is normalized.
      Parameters:
      sH - horizontal scale factor
      sV - vertical scale factor
      res - return location for the scaled rectangle
      Since:
      1.10
    • union

      public void union(Rect b, Rect res)

      Computes the union of the two given rectangles.

      The union in the image above is the blue outline.

      Parameters:
      b - a graphene_rect_t
      res - return location for a graphene_rect_t
      Since:
      1.0