Points and Rectangles

Points and Rectangles — Simple graphical data types

Functions

Types and Values

Includes

#include <cdk/cdk.h>

Description

CDK provides the CdkPoint and CdkRectangle data types for representing pixels and sets of pixels on the screen. Together with Cairo’s cairo_region_t data type, they make up the central types for representing graphical data.

A CdkPoint represents an x and y coordinate of a point.

A CdkRectangle represents the position and size of a rectangle. The intersection of two rectangles can be computed with cdk_rectangle_intersect(). To find the union of two rectangles use cdk_rectangle_union().

cairo_region_t is usually used for managing clipping of graphical operations.

Functions

cdk_rectangle_intersect ()

gboolean
cdk_rectangle_intersect (const CdkRectangle *src1,
                         const CdkRectangle *src2,
                         CdkRectangle *dest);

Calculates the intersection of two rectangles. It is allowed for dest to be the same as either src1 or src2 . If the rectangles do not intersect, dest ’s width and height is set to 0 and its x and y values are undefined. If you are only interested in whether the rectangles intersect, but not in the intersecting area itself, pass NULL for dest .

Parameters

src1

a CdkRectangle

 

src2

a CdkRectangle

 

dest

return location for the intersection of src1 and src2 , or NULL.

[out caller-allocates][allow-none]

Returns

TRUE if the rectangles intersect.


cdk_rectangle_union ()

void
cdk_rectangle_union (const CdkRectangle *src1,
                     const CdkRectangle *src2,
                     CdkRectangle *dest);

Calculates the union of two rectangles. The union of rectangles src1 and src2 is the smallest rectangle which includes both src1 and src2 within it. It is allowed for dest to be the same as either src1 or src2 .

Note that this function does not ignore 'empty' rectangles (ie. with zero width or height).

Parameters

src1

a CdkRectangle

 

src2

a CdkRectangle

 

dest

return location for the union of src1 and src2 .

[out]

cdk_rectangle_equal ()

gboolean
cdk_rectangle_equal (const CdkRectangle *rect1,
                     const CdkRectangle *rect2);

Checks if the two given rectangles are equal.

Parameters

rect1

a CdkRectangle

 

rect2

a CdkRectangle

 

Returns

TRUE if the rectangles are equal.

Since: 3.20

Types and Values

struct CdkPoint

struct CdkPoint {
  gint x;
  gint y;
};

Defines the x and y coordinates of a point.

Members

gint x;

the x coordinate of the point.

 

gint y;

the y coordinate of the point.

 

CdkRectangle

typedef struct {
    int x, y;
    int width, height;
} CdkRectangle;

Defines the position and size of a rectangle. It is identical to cairo_rectangle_int_t.

Members

int x;

X coordinate of the left side of the rectangle

 

int y;

Y coordinate of the the top side of the rectangle

 

int width;

width of the rectangle

 

int height;

height of the rectangle