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.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionRect()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 Rectalloc()Allocates a newgraphene_rect_t.booleanChecks whether agraphene_rect_tcontains the given coordinates.booleancontainsRect(Rect b) Checks whether agraphene_rect_tfully contains the given rectangle.booleanChecks whether the two given rectangle are equal.voidExpands agraphene_rect_tto contain the givengraphene_point_t.voidfree()Frees the resources allocated by graphene_rect_alloc().floatgetArea()Compute the area of given normalized rectangle.voidRetrieves the coordinates of the bottom-left corner of the given rectangle.voidRetrieves the coordinates of the bottom-right corner of the given rectangle.voidRetrieves the coordinates of the center of the given rectangle.floatRetrieves the normalized height of the given rectangle.static MemoryLayoutThe memory layout of the native struct.voidgetTopLeft(Point p) Retrieves the coordinates of the top-left corner of the given rectangle.voidgetTopRight(Point p) Retrieves the coordinates of the top-right corner of the given rectangle.static @Nullable TypegetType()Get the GType of the Rect classvoidgetVertices(@Nullable Out<Vec2[]> vertices) Computes the four vertices of agraphene_rect_t.floatgetWidth()Retrieves the normalized width of the given rectangle.floatgetX()Retrieves the normalized X coordinate of the origin of the given rectangle.floatgetY()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_twith the given values.initFromRect(Rect src) Initializes this Rect using the givensrcrectangle.inset(float dX, float dY) Changes the given rectangle to be smaller, or larger depending on the given inset parameters.voidChanges the given rectangle to be smaller, or larger depending on the given inset parameters.voidinterpolate(Rect b, double factor, Rect res) Linearly interpolates the origin and size of the two given rectangles.booleanintersection(Rect b, @Nullable Rect res) Computes the intersection of the two given rectangles.Normalizes the passed rectangle.voidnormalizeR(Rect res) Normalizes the passed rectangle.offset(float dX, float dY) Offsets the origin bydXanddY.voidOffsets the origin of the given rectangle bydXanddY.@Nullable PointRead the value of the fieldorigin.@Nullable SizereadSize()Read the value of the fieldsize.voidDeprecated.Use graphene_rect_round_extents() insteadvoidroundExtents(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() insteadvoidScales the size and origin of a rectangle horizontaly bysH,and vertically bysV.The resultresis normalized.voidComputes the union of the two given rectangles.voidwriteOrigin(@Nullable Point origin) Write a value in the fieldorigin.voidWrite a value in the fieldsize.static Rectzero()Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.Methods inherited from class org.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 fieldoriginsize- 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
Read the value of the fieldsize.- Returns:
- The value of the field
size
-
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
- Since:
- 1.0
-
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
Checks whether agraphene_rect_tcontains the given coordinates.- Parameters:
p- agraphene_point_t- Returns:
trueif the rectangle contains the point- Since:
- 1.0
-
containsRect
Checks whether agraphene_rect_tfully contains the given rectangle.- Parameters:
b- agraphene_rect_t- Returns:
trueif the rectangle this Rect fully containsb- Since:
- 1.0
-
equal
Checks whether the two given rectangle are equal.- Parameters:
b- agraphene_rect_t- Returns:
trueif the rectangles are equal- Since:
- 1.0
-
expand
-
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
Retrieves the coordinates of the bottom-left corner of the given rectangle.- Parameters:
p- return location for agraphene_point_t- Since:
- 1.0
-
getBottomRight
Retrieves the coordinates of the bottom-right corner of the given rectangle.- Parameters:
p- return location for agraphene_point_t- Since:
- 1.0
-
getCenter
Retrieves the coordinates of the center of the given rectangle.- Parameters:
p- return location for agraphene_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
Retrieves the coordinates of the top-left corner of the given rectangle.- Parameters:
p- return location for agraphene_point_t- Since:
- 1.0
-
getTopRight
Retrieves the coordinates of the top-right corner of the given rectangle.- Parameters:
p- return location for agraphene_point_t- Since:
- 1.0
-
getVertices
-
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
Initializes the givengraphene_rect_twith the given values.This function will implicitly normalize the
graphene_rect_tbefore 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
- Since:
- 1.0
-
initFromRect
-
inset
Changes the given rectangle to be smaller, or larger depending on the given inset parameters.To create an inset rectangle, use positive
dXordYvalues; to create a larger, encompassing rectangle, use negativedXordYvalues.The origin of the rectangle is offset by
dXanddY,while the size is adjusted by(2 * @d_x, 2 * @d_y). IfdXanddYare positive values, the size of the rectangle is decreased; ifdXanddYare 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
- Since:
- 1.0
-
insetR
Changes the given rectangle to be smaller, or larger depending on the given inset parameters.To create an inset rectangle, use positive
dXordYvalues; to create a larger, encompassing rectangle, use negativedXordYvalues.The origin of the rectangle is offset by
dXanddY,while the size is adjusted by(2 * @d_x, 2 * @d_y). IfdXanddYare positive values, the size of the rectangle is decreased; ifdXanddYare 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- Since:
- 1.4
-
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,
reswill contain a degenerate rectangle with origin in (0, 0) and a size of 0.- Parameters:
b- agraphene_rect_tres- return location for agraphene_rect_t- Returns:
trueif the two rectangles intersect- Since:
- 1.0
-
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
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
Offsets the origin bydXanddY.The size of the rectangle is unchanged.
- Parameters:
dX- the horizontal offsetdY- the vertical offset- Returns:
- the offset rectangle
- Since:
- 1.0
-
offsetR
Offsets the origin of the given rectangle bydXanddY.The size of the rectangle is left unchanged.
- Parameters:
dX- the horizontal offsetdY- the vertical offsetres- return location for the offset rectangle- Since:
- 1.4
-
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
flooron the coordinates of the origin, andceilon the size.- Parameters:
res- return location for the rounded rectangle- Since:
- 1.4
-
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
flooron the coordinates of the origin, and recomputing the size callingceilon 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.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.
- Since:
- 1.0
-
scale
Scales the size and origin of a rectangle horizontaly bysH,and vertically bysV.The resultresis normalized.- Parameters:
sH- horizontal scale factorsV- vertical scale factorres- return location for the scaled rectangle- Since:
- 1.10
-
union
-