Class Rect
- All Implemented Interfaces:
Proxy
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.
-
Constructor Summary
ConstructorDescriptionRect()
Allocate a new Rect.Allocate a new Rect.Rect
(MemorySegment address) Create a Rect proxy instance for the provided memory address.Allocate a new Rect with the fields set to the provided values.Allocate a new Rect with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionstatic Rect
alloc()
Allocates a newgraphene_rect_t
.boolean
Checks whether agraphene_rect_t
contains the given coordinates.boolean
containsRect
(Rect b) Checks whether agraphene_rect_t
fully contains the given rectangle.boolean
Checks whether the two given rectangle are equal.void
Expands agraphene_rect_t
to contain the givengraphene_point_t
.void
free()
Frees the resources allocated by graphene_rect_alloc().float
getArea()
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.static MemoryLayout
The memory layout of the native struct.void
getTopLeft
(Point p) Retrieves the coordinates of the top-left corner of the given rectangle.void
getTopRight
(Point p) Retrieves the coordinates of the top-right corner of the given rectangle.static Type
getType()
Get the GType of the Rect classvoid
getVertices
(Vec2[] vertices) Computes the four vertices of agraphene_rect_t
.float
getWidth()
Retrieves the normalized width of the given rectangle.float
getX()
Retrieves the normalized X coordinate of the origin of the given rectangle.float
getY()
Retrieves the normalized Y coordinate of the origin of the given rectangle.init
(float x, float y, float width, float height) Initializes the givengraphene_rect_t
with the given values.initFromRect
(Rect src) Initializes this Rect using the givensrc
rectangle.inset
(float dX, float dY) Changes the given rectangle to be smaller, or larger depending on the given inset parameters.void
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
normalizeR
(Rect res) Normalizes the passed rectangle.offset
(float dX, float dY) Offsets the origin bydX
anddY
.void
Offsets the origin of the given rectangle bydX
anddY
.Read the value of the fieldorigin
.readSize()
Read the value of the fieldsize
.void
Deprecated.Use graphene_rect_round_extents() insteadvoid
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.Deprecated.Use graphene_rect_round() insteadvoid
Scales the size and origin of a rectangle horizontaly bysH
, and vertically bysV
.void
Computes the union of the two given rectangles.void
writeOrigin
(Point origin) Write a value in the fieldorigin
.void
Write a value in the fieldsize
.static Rect
zero()
Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Rect
Create a Rect proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Rect
Allocate a new Rect.- Parameters:
arena
- to control the memory allocation scope
-
Rect
public Rect()Allocate a new Rect. The memory is allocated withArena.ofAuto()
. -
Rect
-
Rect
Allocate a new Rect with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
origin
- value for the fieldorigin
size
- value for the fieldsize
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readOrigin
Read the value of the fieldorigin
.- Returns:
- The value of the field
origin
-
writeOrigin
Write a value in the fieldorigin
.- Parameters:
origin
- The new value for the fieldorigin
-
readSize
-
writeSize
Write a value in the fieldsize
.- Parameters:
size
- The new value for the fieldsize
-
alloc
Allocates a newgraphene_rect_t
.The contents of the returned rectangle are undefined.
- Returns:
- the newly allocated rectangle
-
zero
Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.- Returns:
- a fixed rectangle
-
containsPoint
Checks whether agraphene_rect_t
contains the given coordinates.- Parameters:
p
- agraphene_point_t
- Returns:
true
if the rectangle contains the point
-
containsRect
Checks whether agraphene_rect_t
fully contains the given rectangle.- Parameters:
b
- agraphene_rect_t
- Returns:
true
if the rectangle this Rect fully containsb
-
equal
Checks whether the two given rectangle are equal.- Parameters:
b
- agraphene_rect_t
- Returns:
true
if the rectangles are equal
-
expand
-
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
Retrieves the coordinates of the bottom-left corner of the given rectangle.- Parameters:
p
- return location for agraphene_point_t
-
getBottomRight
Retrieves the coordinates of the bottom-right corner of the given rectangle.- Parameters:
p
- return location for agraphene_point_t
-
getCenter
Retrieves the coordinates of the center of the given rectangle.- Parameters:
p
- return location for agraphene_point_t
-
getHeight
public float getHeight()Retrieves the normalized height of the given rectangle.- Returns:
- the normalized height of the rectangle
-
getTopLeft
Retrieves the coordinates of the top-left corner of the given rectangle.- Parameters:
p
- return location for agraphene_point_t
-
getTopRight
Retrieves the coordinates of the top-right corner of the given rectangle.- Parameters:
p
- return location for agraphene_point_t
-
getVertices
Computes the four vertices of agraphene_rect_t
.- Parameters:
vertices
- return location for an array of 4graphene_vec2_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
Initializes the givengraphene_rect_t
with the given values.This function will implicitly normalize the
graphene_rect_t
before returning.- Parameters:
x
- the X coordinate of thegrapheneRectT
.originy
- the Y coordinate of thegrapheneRectT
.originwidth
- the width of thegrapheneRectT
.sizeheight
- the height of thegrapheneRectT
.size- Returns:
- the initialized rectangle
-
initFromRect
-
inset
Changes the given rectangle to be smaller, or larger depending on the given inset parameters.To create an inset rectangle, use positive
dX
ordY
values; to create a larger, encompassing rectangle, use negativedX
ordY
values.The origin of the rectangle is offset by
dX
anddY
, while the size is adjusted by(2 * @d_x, 2 * @d_y)
. IfdX
anddY
are positive values, the size of the rectangle is decreased; ifdX
anddY
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 insetdY
- the vertical inset- Returns:
- the inset rectangle
-
insetR
Changes the given rectangle to be smaller, or larger depending on the given inset parameters.To create an inset rectangle, use positive
dX
ordY
values; to create a larger, encompassing rectangle, use negativedX
ordY
values.The origin of the rectangle is offset by
dX
anddY
, while the size is adjusted by(2 * @d_x, 2 * @d_y)
. IfdX
anddY
are positive values, the size of the rectangle is decreased; ifdX
anddY
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 insetdY
- the vertical insetres
- return location for the inset rectangle
-
interpolate
-
intersection
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
- agraphene_rect_t
res
- return location for agraphene_rect_t
- Returns:
true
if the two rectangles intersect
-
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
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
Offsets the origin bydX
anddY
.The size of the rectangle is unchanged.
- Parameters:
dX
- the horizontal offsetdY
- the vertical offset- Returns:
- the offset rectangle
-
offsetR
Offsets the origin of the given rectangle bydX
anddY
.The size of the rectangle is left unchanged.
- Parameters:
dX
- the horizontal offsetdY
- the vertical offsetres
- return location for the offset rectangle
-
round
Deprecated.Use graphene_rect_round_extents() insteadRounds 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, andceil
on the size.- Parameters:
res
- return location for the rounded rectangle
-
roundExtents
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 callingceil
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
-
roundToPixel
Deprecated.Use graphene_rect_round() insteadRounds 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.
-
scale
Scales the size and origin of a rectangle horizontaly bysH
, and vertically bysV
. The resultres
is normalized.- Parameters:
sH
- horizontal scale factorsV
- vertical scale factorres
- return location for the scaled rectangle
-
union
-