package ocgtk

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Wrappers.Rect

type t = [ `rect ] Gobject.obj

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.

val union : t -> t -> t

Computes the union of the two given rectangles.

!(rectangle-union.png)

The union in the image above is the blue outline.

val scale : t -> float -> float -> t

Scales the size and origin of a rectangle horizontaly by @s_h, and vertically by @s_v. The result @res is normalized.

val round_to_pixel : t -> t

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.

val round_extents : t -> t

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.

val round : t -> t

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.

val offset_r : t -> float -> float -> t

Offsets the origin of the given rectangle by @d_x and @d_y.

The size of the rectangle is left unchanged.

val offset : t -> float -> float -> t

Offsets the origin by @d_x and @d_y.

The size of the rectangle is unchanged.

val normalize_r : t -> t

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.

val normalize : t -> t

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.

val intersection : t -> t -> bool * t

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.

val interpolate : t -> t -> float -> t

Linearly interpolates the origin and size of the two given rectangles.

val inset_r : t -> float -> float -> t

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.

val inset : t -> float -> float -> t

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.

val init_from_rect : t -> t -> t

Initializes @r using the given @src rectangle.

This function will implicitly normalize the #graphene_rect_t before returning.

val init : t -> float -> float -> float -> float -> t

Initializes the given #graphene_rect_t with the given values.

This function will implicitly normalize the #graphene_rect_t before returning.

val get_y : t -> float

Retrieves the normalized Y coordinate of the origin of the given rectangle.

val get_x : t -> float

Retrieves the normalized X coordinate of the origin of the given rectangle.

val get_width : t -> float

Retrieves the normalized width of the given rectangle.

val get_vertices : t -> [ `vec2 ] Gobject.obj array

Computes the four vertices of a #graphene_rect_t.

val get_top_right : t -> [ `point ] Gobject.obj

Retrieves the coordinates of the top-right corner of the given rectangle.

val get_top_left : t -> [ `point ] Gobject.obj

Retrieves the coordinates of the top-left corner of the given rectangle.

val get_height : t -> float

Retrieves the normalized height of the given rectangle.

val get_center : t -> [ `point ] Gobject.obj

Retrieves the coordinates of the center of the given rectangle.

val get_bottom_right : t -> [ `point ] Gobject.obj

Retrieves the coordinates of the bottom-right corner of the given rectangle.

val get_bottom_left : t -> [ `point ] Gobject.obj

Retrieves the coordinates of the bottom-left corner of the given rectangle.

val get_area : t -> float

Compute the area of given normalized rectangle.

val expand : t -> [ `point ] Gobject.obj -> t

Expands a #graphene_rect_t to contain the given #graphene_point_t.

val equal : t -> t -> bool

Checks whether the two given rectangle are equal.

val contains_rect : t -> t -> bool

Checks whether a #graphene_rect_t fully contains the given rectangle.

val contains_point : t -> [ `point ] Gobject.obj -> bool

Checks whether a #graphene_rect_t contains the given coordinates.

val get_type : unit -> Gobject.Type.t