Package ch.bailu.gtk.graphene
Class Rect
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.graphene.Rect
- All Implemented Interfaces:
PointerInterface
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.
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.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Rect
alloc()
Allocates a new #graphene_rect_t.boolean
Checks whether a #graphene_rect_t contains the given coordinates.boolean
containsRect
(Rect b) Checks whether a #graphene_rect_t fully contains the given
rectangle.boolean
Checks whether the two given rectangle are equal.void
Expands a #graphene_rect_t to contain the given #graphene_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.static ClassHandler
float
Retrieves the normalized height of the given rectangle.static int
static long
static TypeSystem.TypeSize
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 long
static TypeSystem.TypeSize
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 given #graphene_rect_t with the given values.initFromRect
(Rect src) Initializes @r using the given @src rectangle.inset
(float d_x, float d_y) 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, Rect res) Computes the intersection of the two given rectangles.Normalizes the passed rectangle.void
normalizeR
(Rect res) Normalizes the passed rectangle.offset
(float d_x, float d_y) Offsets the origin by @d_x and @d_y.void
Offsets the origin of the given rectangle by @d_x and @d_y.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.void
Scales the size and origin of a rectangle horizontaly by @s_h,
and vertically by @s_v.void
Computes the union of the two given rectangles.static Rect
zero()
Returns a degenerate rectangle with origin fixed at (0, 0) and
a size of 0, 0.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
ORIGIN
the coordinates of the origin of the rectangle
Private field: direct-type- See Also:
-
SIZE
the size of the rectangle
Private field: direct-type- See Also:
-
-
Constructor Details
-
Rect
-
Rect
public Rect()
-
-
Method Details
-
getClassHandler
-
containsPoint
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
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
Checks whether the two given rectangle are equal.- Parameters:
b
- a #graphene_rect_t- Returns:
- `true` if the rectangles are equal
-
expand
Expands a #graphene_rect_t to contain the given #graphene_point_t.- Parameters:
p
- a #graphene_point_tres
- 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
Retrieves the coordinates of the bottom-left corner of the given rectangle.- Parameters:
p
- return location for a #graphene_point_t
-
getBottomRight
Retrieves the coordinates of the bottom-right corner of the given rectangle.- Parameters:
p
- return location for a #graphene_point_t
-
getCenter
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
Retrieves the coordinates of the top-left corner of the given rectangle.- Parameters:
p
- return location for a #graphene_point_t
-
getTopRight
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
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.originy
- the Y coordinate of the @graphene_rect_t.originwidth
- the width of the @graphene_rect_t.sizeheight
- the height of the @graphene_rect_t.size- Returns:
- the initialized rectangle
-
initFromRect
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
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 insetd_y
- 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 @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 insetd_y
- the vertical insetres
- return location for the inset rectangle
-
interpolate
Linearly interpolates the origin and size of the two given
rectangles.- Parameters:
b
- a #graphene_rect_tfactor
- the linear interpolation factorres
- return location for the interpolated rectangle
-
intersection
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_tres
- return location for a #graphene_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 by @d_x and @d_y.
The size of the rectangle is unchanged.- Parameters:
d_x
- the horizontal offsetd_y
- the vertical offset- Returns:
- the offset rectangle
-
offsetR
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 offsetd_y
- the vertical offsetres
- return location for the offset 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
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
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 factors_v
- vertical scale factorres
- return location for the scaled rectangle
-
union
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_tres
- return location for a #graphene_rect_t
-
alloc
Allocates a new #graphene_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
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-