rect_t Struct Reference


Public Methods

void rect_set (struct rect_t *ptr_rect, int x, int y, int width, int height)
bool rect_and (struct rect_t *ptr_rectangle, struct rect_t *ptr_rectangle_1, struct rect_t *ptr_rectangle_2)
bool rect_or (struct rect_t *ptr_rectangle, struct rect_t *ptr_rectangle_1, struct rect_t *ptr_rectangle_2)

Public Attributes

short x
short y
short w
short h


Detailed Description

A rectangle.

See also:
Drawing Primitives and Screen Manipulation


Member Function Documentation

bool rect_and ( struct rect_t * ptr_rectangle,
struct rect_t * ptr_rectangle_1,
struct rect_t * ptr_rectangle_2 )
 

Intersects two rectangles.
Sets the value ptr_rectangle into an intersection of two given rectangles.

Parameters:
ptr_rectangle   The intersection result
ptr_rectangle_1   The first rectangle to intersect
ptr_rectangle_2   The second rectangle to intersect
Returns:
TRUE if a valid rectangle intersection was obtained, or FALSE if no intersection was found
       #include <cybiko.h>
       #define VEHICLE_WIDTH          60
       #define VEHICLE_HEIGHT         20
       ...
       int x1;
       int x2;
       int y1;
       int y2;
       struct rect_t vehicle_1_boundary;
       struct rect_t vehicle_2_boundary;
       struct rect_t intersection;
       ...
       rect_set( &vehicle_1_boundary, x1, y1, VEHICLE_WIDTH, VEHICLE_HEIGHT );
       rect_set( &vehicle_2_boundary, x2, y2, VEHICLE_WIDTH, VEHICLE_HEIGHT );
       //  Checks collision of the vehicles.
       if( rect_and( &intersection, &vehicle_1_boundary, &vehicle_2_boundary ) )
       ...

bool rect_or ( struct rect_t * ptr_rectangle,
struct rect_t * ptr_rectangle_1,
struct rect_t * ptr_rectangle_2 )
 

Merges two rectangles.
Sets the value ptr_rectangle into a union of two given rectangles.

Parameters:
ptr_rectangle   The merged result
ptr_rectangle_1   The first rectangle to join
ptr_rectangle_2   The second rectangle to join
Returns:
TRUE if a valid rectangle was obtained, or FALSE otherwise
       #include <cybiko.h>
       #define VEHICLE_WIDTH          60
       #define VEHICLE_HEIGHT         20
       ...
       int x1;
       int x2;
       int y1;
       int y2;
       struct rect_t vehicle_1_boundary;
       struct rect_t vehicle_2_boundary;
       struct rect_t common_boundary;
       ...
       rect_set( &vehicle_1_boundary, x1, y1, VEHICLE_WIDTH, VEHICLE_HEIGHT );
       rect_set( &vehicle_2_boundary, x2, y2, VEHICLE_WIDTH, VEHICLE_HEIGHT );
       rect_or( &common_boundary, &vehicle_1_boundary, &vehicle_2_boundary );
       ...

void rect_set ( struct rect_t * ptr_rect,
int x,
int y,
int width,
int height )
 

Initializes a rectangle.

Parameters:
ptr_rect   A pointer to the rect_t structure
x   The rectangle's x-coordinate
y   The rectangle's y-coordinate
width   The rectangle's width
height   The rectangle's height
Returns:
None
       #include <cybiko.h>
       #define VEHICLE_WIDTH          60
       #define VEHICLE_HEIGHT         20
       ...
       int x1;
       int x2;
       int y1;
       int y2;
       struct rect_t vehicle_1_boundary;
       struct rect_t vehicle_2_boundary;
       struct rect_t intersection;
       ...
       rect_set( &vehicle_1_boundary, x1, y1, VEHICLE_WIDTH, VEHICLE_HEIGHT );
       rect_set( &vehicle_2_boundary, x2, y2, VEHICLE_WIDTH, VEHICLE_HEIGHT );
       //  Checks collision of the vehicles.
       if( rect_and( &intersection, &vehicle_1_boundary, &vehicle_2_boundary ) )
       ...


Member Data Documentation

short h
 

Rectangle's height.

short w
 

Rectangle's width.

short x
 

Rectangle's x-coordinate.

short y
 

Rectangle's y-coordinate.