QuakeForge  0.7.2.210-815cf
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
vrect.h File Reference
This graph shows which files directly or indirectly include this file:

Data Structures

struct  vrect_s
 

Macros

#define VRect_IsEmpty(vr)   ((vr)->width <= 0 || (vr)->height <= 0)
 
#define VRect_MaxX(vr)   ((vr)->x + (vr)->width)
 
#define VRect_MaxY(vr)   ((vr)->y + (vr)->height)
 
#define VRect_MinX(vr)   ((vr)->x)
 
#define VRect_MinY(vr)   ((vr)->y)
 

Typedefs

typedef struct vrect_s vrect_t
 

Functions

void VRect_Delete (vrect_t *rect)
 Free one rectangle. More...
 
vrect_tVRect_Difference (const vrect_t *r, const vrect_t *s)
 Return up to four rectangles representing the result of carving rectangle s out of rectangle r. More...
 
vrect_tVRect_HSplit (const vrect_t *r, int y)
 Return two rectangles representing the portions of r above and below y. More...
 
vrect_tVRect_Intersect (const vrect_t *r1, const vrect_t *r2)
 Return a rectangle representing the intersection of r1 and r2. More...
 
vrect_tVRect_Merge (const vrect_t *r1, const vrect_t *r2)
 Return the rectangle representing the merge of the two given rectangles. More...
 
vrect_tVRect_New (int x, int y, int width, int height)
 Create a new rectangle of the specified shape. More...
 
vrect_tVRect_Union (const vrect_t *r1, const vrect_t *r2)
 Return the union of the two rectangles. More...
 
vrect_tVRect_VSplit (const vrect_t *r, int x)
 Return two rectangles representing the portions of r to the left and right of y. More...
 

Macro Definition Documentation

#define VRect_IsEmpty (   vr)    ((vr)->width <= 0 || (vr)->height <= 0)
#define VRect_MaxX (   vr)    ((vr)->x + (vr)->width)
#define VRect_MaxY (   vr)    ((vr)->y + (vr)->height)
#define VRect_MinX (   vr)    ((vr)->x)
#define VRect_MinY (   vr)    ((vr)->y)

Typedef Documentation

typedef struct vrect_s vrect_t

Function Documentation

void VRect_Delete ( vrect_t rect)

Free one rectangle.

This function will not free any other rectangles linked to the specified rectangle.

Parameters
rectThe rectangle to be freed.
vrect_t* VRect_Difference ( const vrect_t r,
const vrect_t s 
)

Return up to four rectangles representing the result of carving rectangle s out of rectangle r.

None of the returned rectangles will be empty. If the difference is empty, null will be returned.

Parameters
rThe rectangle to be carved.
sThe rectangle used to carve r.
Returns
Up to four linked rectangles representing the portions of r after carving out the portion represented by s, or null if the result is empty. A new rectangle that is a copy of r will be returned if r and s do not intersect.
Note
It is the caller's responsibility to delete the returned rectangles.
vrect_t* VRect_HSplit ( const vrect_t r,
int  y 
)

Return two rectangles representing the portions of r above and below y.

One of the returned rectangles may be empty. Use VRect_IsEmpty to check. The first rectangle represents the portion of r that is above y, and the second rectangle repesents the portion of r that is below y. The second rectangle is linked to the first via the first's vrect_t::next pointer.

Parameters
rThe rectangle to split.
yThe horizontal line by which r will be split.
Returns
The two linked rectangles representing the portions above and below y. The returned pointer points to the first (above) rectangle, which links to the second (below) rectangle.
Note
It is the caller's responsibility to delete the returned rectangles.
vrect_t* VRect_Intersect ( const vrect_t r1,
const vrect_t r2 
)

Return a rectangle representing the intersection of r1 and r2.

The returned rectangle may be empty. Use VRect_IsEmpty to check.

Parameters
r1The first rectangle.
r2The second rectangle.
Returns
The single (possibly empty) rectangle representing the intersection of r1 and r2.
Note
It is the caller's responsibility to delete the returned rectangle.
vrect_t* VRect_Merge ( const vrect_t r1,
const vrect_t r2 
)

Return the rectangle representing the merge of the two given rectangles.

If the two given rectangles cannot be perfectly joined (either they intesect or subtracting them from the merged rectangle would result in scrap rectangles, null will be returned. Two empty rectangles will result in null being returned, but only one empty rectangle will result in a copy of the non-empty rectangle.

Parameters
r1The first rectangle to be merged.
r2The second rectangle to be merged.
Returns
The merged rectangle, or null if the given rectangles cannot be merged.
Note
It is the caller's responsibility to delete the returned rectangle.
vrect_t* VRect_New ( int  x,
int  y,
int  width,
int  height 
)

Create a new rectangle of the specified shape.

Other VRect functions will return a rectangle (or chain of rectangles) created by this function.

Parameters
xThe X coordinate of the top-left corner.
yThe Y coordinate of the top-left corner.
widthThe width of the rectangle.
heightThe height of the rectangle.
Returns
The newly created rectangle.
vrect_t* VRect_Union ( const vrect_t r1,
const vrect_t r2 
)

Return the union of the two rectangles.

The union rectangle will be big enough to entirely contain both r1 and r2. An empty rectangle will be returned if both rectangles are empty.

Parameters
r1The first rectangle.
r2The second rectangle.
Returns
The union of the two rectangles.
Note
It is the caller's responsibility to delete the returned rectangle.
vrect_t* VRect_VSplit ( const vrect_t r,
int  x 
)

Return two rectangles representing the portions of r to the left and right of y.

One of the returned rectangles may be empty. Use VRect_IsEmpty to check. The first rectangle represents the portion of r that is to the left of y, and the second rectangle repesents the portion of r that is to the right of y. The second rectangle is linked to the first via the first's vrect_t::next pointer.

Parameters
rThe rectangle to split.
xThe vertical line by which r will be split.
Returns
The two linked rectangles representing the portions to the left and right of y. The returned pointer points to the first (left) rectangle, which links to the second (right) rectangle.
Note
It is the caller's responsibility to delete the returned rectangles.