<-- Back to AG_Intro.3


#include <agar/core.h>
#include <agar/gui.h>


Many functions in Agar accept AG_Rect parameters. This structure describes a two-dimensional integer rectangle:
typedef struct ag_rect {
	int x, y;
	int w, h;
} AG_Rect;

The alternate AG_Rect2 structure also stores the two endpoints explicitely:
typedef struct ag_rect2 {
	int x1, y1;
	int w, h;
	int x2, y2;
} AG_Rect2;


AG_Rect AG_RECT (int x, int y, int w, int h)

AG_Rect2 AG_RECT2 (int x, int y, int w, int h)

AG_Rect AG_ReadRect (AG_DataSource *ds)

AG_Rect2 AG_ReadRect2 (AG_DataSource *ds)

void AG_WriteRect (AG_DataSource *ds, AG_Rect r)

void AG_WriteRect2 (AG_DataSource *ds, AG_Rect2 r)

AG_Rect AG_Rect2ToRect (AG_Rect2 r)

AG_Rect2 AG_RectToRect2 (AG_Rect r)

AG_Rect AG_RectIntersect (AG_Rect a, AG_Rect b)

AG_Rect2 AG_RectIntersect2 (const AG_Rect2 *a, const AG_Rect2 *b)

int AG_RectInside (AG_Rect r, int x, int y)

int AG_RectInside2 (const AG_Rect2 *r, int x, int y)

int AG_RectCompare (AG_Rect a, AG_Rect b)

int AG_RectCompare2 (const AG_Rect2 *a, const AG_Rect2 *b)

void AG_RectSize (AG_Rect *r, int w, int h)

void AG_RectSize2 (AG_Rect2 *r, int w, int h)

void AG_RectTranslate (AG_Rect *r, int x, int y)

void AG_RectTranslate2 (AG_Rect2 *r, int x, int y)

The AG_RECT() routine returns an AG_Rect structure initialized to the given coordinates x, y and dimensions w, h. The AG_RECT2() variant returns an AG_Rect2.

The AG_ReadRect() function loads a rectangle from the given AG_DataSource(3). AG_WriteRect() writes a rectangle to a data source.

The AG_RectToRect2() and AG_Rect2ToRect() routines convert between the AG_Rect and AG_Rect2 formats.

AG_RectIntersect() and AG_RectIntersect2() return intersection of rectangles a and b.

AG_RectInside() and AG_RectInside() return 1 if the point x, y lies inside of rectangle r.

The AG_RectCompare() and AG_RectCompare2() routines return 0 if both rectangles possess the same coordinates and dimensions.

The AG_RectSize() and AG_RectSize2() routines resize a rectangle to the specified dimensions.

AG_RectTranslate() and AG_RectTranslate2() translate a rectangle by the specified amount.


AG_Intro(3), AG_Widget(3)


The AG_Rect structure first appeared in Agar 1.3.