Skip to content
slaeshjag edited this page Mar 23, 2013 · 19 revisions

DARNIT_BBOX

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);

d_bbox_new

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.

d_bbox_free

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.

d_bbox_test

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


An illustration of how bbox_test work

Return value

Returns the number of matching bounding boxes that was written to the array

d_bbox_add

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.

Clone this wiki locally