-
Notifications
You must be signed in to change notification settings - Fork 3
darnit_bbox.h
a DARNIT_BBOX is a statically allocated list of bounding boxes. These can quickly be matched against an area, with a list of bounding boxes overlapping that area being returned.
- DARNIT_BBOX *d_bbox_new( unsigned int size);
- DARNIT_BBOX *d_bbox_free(DARNIT_BBOX *bbox);
- int d_bbox_test(DARNIT_BBOX *bbox, int x, int y, unsigned int w, unsigned int h, unsigned int *list, unsigned int listlen);
- int d_bbox_add(DARNIT_BBOX *bbox, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
- void d_bbox_delete(DARNIT_BBOX *bbox, int key);
- void d_bbox_move(DARNIT_BBOX *bbox, int key, unsigned int x, unsigned int y);
- void d_bbox_resize(DARNIT_BBOX *bbox, int key, unsigned int w, unsigned int h);
- void d_bbox_clear(DARNIT_BBOX *bbox);
DARNIT_BBOX *d_bbox_new(unsigned int size);
Returns a list with space for size bounding boxes.
Arguments
- size - Number of bounding boxes to allocate space for
Return value
NULL on failure. Something else is a valid bounding box list.
DARNIT_BBOX *d_bbox_free(DARNIT_BBOX *bbox);
Frees a list of bounding boxes and returns a NULL-pointer.
Arguments
- bbox - A valid list of bounding boxes
Return value
- A NULL-pointer. Provided for compact NULL-ing of the pointer that used to point to the list.
int d_bbox_test(DARNIT_BBOX *bbox, int x, int y, unsigned int w, unsigned int h, unsigned int *list, unsigned int listlen);
Tests for bounding boxes in the specified area and fills the array list with index values for the matching boxes.
Arguments
- bbox - the list of bounding boxes to test
- x - the x-coordinate of the area to test
- y - the y-coordinate of the area to test
- w - the width of the area to test
- h - the height of the area to test
- list - An array of indices for matching bounding boxes
- listlen - The size of the array (maximum amount of matches to return)
Illustration

Return value
Returns the number of matching bounding boxes that was written to the array
int d_bbox_add(DARNIT_BBOX *bbox, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
Adds a bounding box to a list of bounding boxes
Arguments
- bbox - The bounding box list to add a bounding box to
- x - The x coordinate that the bounding box have
- y - The y coordinate that the bounding box have
- w - The width of the bounding box to add
- h - The height of the bounding box to add
Return value
Returns the index for the bounding box just added. When the bounding box is matched in a test, this is the index you'll get. Returns -1 if the list is full.
void d_bbox_delete(DARNIT_BBOX *bbox, int key);
Deletes a bounding box from the provided list.
Arguments
- bbox - The bounding box list to delete a bounding box from
- key - Index of the bounding box to delete
Return value None
void d_bbox_move(DARNIT_BBOX *bbox, int key, unsigned int x, unsigned int y);
Sets the x and y coordinates of a bounding box without affecting its size.
Arguments
- bbox - The bounding box list to move a bounding box in
- key - Index of the bounding box to move
- x - New x coordinate for the bounding box
- y - New y coordinate for the bounding box
Return value None
void d_bbox_resize(DARNIT_BBOX *bbox, int key, unsigned int w, unsigned int h);
Resizes a bounding box without changing its origin coordinates
Arguments
- bbox - The bounding box list to resize a bounding box in
- key - Index of the bounding box to resize
- w - New width of the bounding box
- h - New height of the bounding box
Return value None
void d_bbox_clear(DARNIT_BBOX *bbox);
Clears a bounding box list from all bounding boxes
Arguments
- bbox - The bounding box list to clear
Return value None