/* * CSE 303, Autumn 2006, Assignment 3, Extra Credit * * You must modify this program as described in the assignment. */ #include #include // Bounding Box Type: // Assumes top < bottom and left < right. typedef struct _BBox { double left; double top; double right; double bottom; } BBox; // Return the maximum of two numbers double max(double a, double b) { return (a > b) ? a : b; } // Return the minimum of two numbers double min(double a, double b) { return (a < b) ? a : b; } // Initialize the allocated BBox structure with the given values. void BBoxInit(BBox *bb, double left, double top, double right, double bottom) { bb->left = left; bb->top = top; bb->right = right; bb->bottom = bottom; } // Print the given BBox to stdout. void BBoxPrint(BBox *bb) { printf("[(%g,%g) (%g,%g)]\n",bb->left, bb->top, bb->right, bb->bottom); } /* PUT YOUR FUNCTIONS HERE */ // A very fast test to see if bounding boxes overlap int BBoxOverlap(BBox bb1, BBox bb2) { return (bb1.bottom > bb2.top && bb1.top < bb2.bottom && bb1.right > bb2.left && bb1.left < bb2.right); } void BBoxOverlapTest() { BBox boxes[19]; BBoxInit(&boxes[0], -4.0, -4.0, 4.0, 4.0); BBoxInit(&boxes[1], -7.0, -5.0, -5.0, -3.0); BBoxInit(&boxes[2], -6.0, -5.0, -4.0, -3.0); BBoxInit(&boxes[3], -5.0, -5.0, -3.0, -3.0); BBoxInit(&boxes[4], -4.0, -5.0, -2.0, -3.0); BBoxInit(&boxes[5], -3.0, -5.0, -1.0, -3.0); BBoxInit(&boxes[6], 2.0, -5.0, 4.0, -3.0); BBoxInit(&boxes[7], 3.0, -5.0, 5.0, -3.0); BBoxInit(&boxes[8], 4.0, -5.0, 6.0, -3.0); BBoxInit(&boxes[9], 5.0, -5.0, 7.0, -3.0); BBoxInit(&boxes[10], -1.0, -7.0, 1.0, -5.0); BBoxInit(&boxes[11], -1.0, -6.0, 1.0, -4.0); BBoxInit(&boxes[12], -1.0, -5.0, 1.0, -3.0); BBoxInit(&boxes[13], -1.0, -4.0, 1.0, -2.0); BBoxInit(&boxes[14], -1.0, -3.0, 1.0, -1.0); BBoxInit(&boxes[15], -1.0, 2.0, 1.0, 4.0); BBoxInit(&boxes[16], -1.0, 3.0, 1.0, 5.0); BBoxInit(&boxes[17], -1.0, 4.0, 1.0, 6.0); BBoxInit(&boxes[18], -1.0, 5.0, 1.0, 7.0); int i; for (i=1; i<=18; i++) printf("%d ", BBoxOverlap(boxes[i], boxes[0])); printf("\n"); } int main(int argc, char**argv) { BBoxOverlapTest(); return 0; }