Class Rect

All Implemented Interfaces:
PointerInterface

public class Rect extends Record
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.

https://ebassi.github.io/graphene/docs/

  • Field Details

    • ORIGIN

      public static final String ORIGIN
      the coordinates of the origin of the rectangle
      Private field: direct-type
      See Also:
    • SIZE

      public static final String SIZE
      the size of the rectangle
      Private field: direct-type
      See Also:
  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • containsPoint

      public boolean containsPoint(@Nonnull 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
    • containsRect

      public boolean containsRect(@Nonnull Rect b)
      Checks whether a #graphene_rect_t fully contains the given
      rectangle.
      Parameters:
      b - a #graphene_rect_t
      Returns:
      `true` if the rectangle @a fully contains @b
    • equal

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

      public void expand(@Nonnull Point p, @Nonnull 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
    • free

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

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

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

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

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

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

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

      public void getTopRight(@Nonnull Point p)
      Retrieves the coordinates of the top-right corner of the given rectangle.
      Parameters:
      p - return location for a #graphene_point_t
    • getWidth

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

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

      public float getY()
      Retrieves the normalized Y coordinate of the origin of the given
      rectangle.
      Returns:
      the normalized Y coordinate of the rectangle
    • 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 @graphene_rect_t.origin
      y - the Y coordinate of the @graphene_rect_t.origin
      width - the width of the @graphene_rect_t.size
      height - the height of the @graphene_rect_t.size
      Returns:
      the initialized rectangle
    • initFromRect

      public Rect initFromRect(@Nonnull Rect src)
      Initializes @r 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
    • inset

      public Rect inset(float d_x, float d_y)
      Changes the given rectangle to be smaller, or larger depending on the
      given inset parameters.

      To create an inset rectangle, use positive @d_x or @d_y values; to
      create a larger, encompassing rectangle, use negative @d_x or @d_y
      values.

      The origin of the rectangle is offset by @d_x and @d_y, while the size
      is adjusted by `(2 * @d_x, 2 * @d_y)`. If @d_x and @d_y are positive
      values, the size of the rectangle is decreased; if @d_x and @d_y 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:
      d_x - the horizontal inset
      d_y - the vertical inset
      Returns:
      the inset rectangle
    • insetR

      public void insetR(float d_x, float d_y, @Nonnull Rect res)
      Changes the given rectangle to be smaller, or larger depending on the
      given inset parameters.

      To create an inset rectangle, use positive @d_x or @d_y values; to
      create a larger, encompassing rectangle, use negative @d_x or @d_y
      values.

      The origin of the rectangle is offset by @d_x and @d_y, while the size
      is adjusted by `(2 * @d_x, 2 * @d_y)`. If @d_x and @d_y are positive
      values, the size of the rectangle is decreased; if @d_x and @d_y 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:
      d_x - the horizontal inset
      d_y - the vertical inset
      res - return location for the inset rectangle
    • interpolate

      public void interpolate(@Nonnull Rect b, double factor, @Nonnull 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
    • intersection

      public boolean intersection(@Nonnull Rect b, @Nullable Rect res)
      Computes the intersection of the two given rectangles.

      ![](rectangle-intersection.png)

      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
    • 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
    • normalizeR

      public void normalizeR(@Nonnull 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
    • offset

      public Rect offset(float d_x, float d_y)
      Offsets the origin by @d_x and @d_y.

      The size of the rectangle is unchanged.
      Parameters:
      d_x - the horizontal offset
      d_y - the vertical offset
      Returns:
      the offset rectangle
    • offsetR

      public void offsetR(float d_x, float d_y, @Nonnull Rect res)
      Offsets the origin of the given rectangle by @d_x and @d_y.

      The size of the rectangle is left unchanged.
      Parameters:
      d_x - the horizontal offset
      d_y - the vertical offset
      res - return location for the offset rectangle
    • roundExtents

      public void roundExtents(@Nonnull 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
    • scale

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

      public void union(@Nonnull Rect b, @Nonnull Rect res)
      Computes the union of the two given rectangles.

      ![](rectangle-union.png)

      The union in the image above is the blue outline.
      Parameters:
      b - a #graphene_rect_t
      res - return location for a #graphene_rect_t
    • alloc

      public static Rect alloc()
      Allocates a new #graphene_rect_t.

      The contents of the returned rectangle are undefined.
      Returns:
      the newly allocated rectangle
    • 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
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()