sources/SpriteWorld.c
void SWCollectIdleSpriteIntersectingRects(
	SWRect checkRect1,
	SWRect checkRect2,
	SWRect *enclosingRect)
{
	SWRect newEnclosingRect;
	SWRect intersectionRect;
	int enclosingRectNeedsInitialization;

		// determine if we need to initialize the collection
	if ((enclosingRect->left == 0) && (enclosingRect->right == 0) &&
		(enclosingRect->top == 0) && (enclosingRect->bottom == 0))
	{
		enclosingRectNeedsInitialization = true;
	}
	else
	{
		enclosingRectNeedsInitialization = false;
	}
		
		// do the rects intersect?
	if ((checkRect1.top < checkRect2.bottom) &&
		 (checkRect1.bottom > checkRect2.top) &&
		 (checkRect1.left < checkRect2.right) &&
		 (checkRect1.right > checkRect2.left))
	{

			// calculate the intersection between the two rects
		intersectionRect.left =
				SW_MAX(checkRect1.left, checkRect2.left);
		intersectionRect.top =
				SW_MAX(checkRect1.top, checkRect2.top);
		intersectionRect.right =
				SW_MIN(checkRect1.right, checkRect2.right);
		intersectionRect.bottom =
				SW_MIN(checkRect1.bottom, checkRect2.bottom);

		if (!enclosingRectNeedsInitialization)
		{
				// caclulate the smallest rect which encloses all the intersection
				// rects found so far
			newEnclosingRect.left =
					SW_MIN(enclosingRect->left, intersectionRect.left);
			newEnclosingRect.top =
					SW_MIN(enclosingRect->top, intersectionRect.top);
			newEnclosingRect.right =
					SW_MAX(enclosingRect->right, intersectionRect.right);
			newEnclosingRect.bottom =
					SW_MAX(enclosingRect->bottom, intersectionRect.bottom);
		}
		else
		{
				// initialize the enclosing rect with the first intersection
			enclosingRectNeedsInitialization = false;
			newEnclosingRect = intersectionRect;
		}

		*enclosingRect = newEnclosingRect;

	}
}
///--------------------------------------------------------------------------------------
//	SWCollectIntersectingRects - find the minimum rect that encloses the current
// enclosing rect and the intersection of checkRect1 and checkRect2
///--------------------------------------------------------------------------------------
find the minimum rect that encloses the current
enclosing rect and the intersection of checkRect1 and checkRect2
find the minimum rect that encloses the current enclosing rect and the intersection of checkRect1 and checkRect2
void SWCollectIdleSpriteIntersectingRects(
	SWRect checkRect1,
	SWRect checkRect2,
	SWRect *enclosingRect)
{
	SWRect newEnclosingRect;
	SWRect intersectionRect;
	int enclosingRectNeedsInitialization;
	if ((enclosingRect->left == 0) && (enclosingRect->right == 0) &&
		(enclosingRect->top == 0) && (enclosingRect->bottom == 0))
	{
		enclosingRectNeedsInitialization = true;
	}
	else
	{
		enclosingRectNeedsInitialization = false;
	}
	if ((checkRect1.top < checkRect2.bottom) &&
		 (checkRect1.bottom > checkRect2.top) &&
		 (checkRect1.left < checkRect2.right) &&
		 (checkRect1.right > checkRect2.left))
	{
		intersectionRect.left =
				SW_MAX(checkRect1.left, checkRect2.left);
		intersectionRect.top =
				SW_MAX(checkRect1.top, checkRect2.top);
		intersectionRect.right =
				SW_MIN(checkRect1.right, checkRect2.right);
		intersectionRect.bottom =
				SW_MIN(checkRect1.bottom, checkRect2.bottom);
		if (!enclosingRectNeedsInitialization)
		{
			newEnclosingRect.left =
					SW_MIN(enclosingRect->left, intersectionRect.left);
			newEnclosingRect.top =
					SW_MIN(enclosingRect->top, intersectionRect.top);
			newEnclosingRect.right =
					SW_MAX(enclosingRect->right, intersectionRect.right);
			newEnclosingRect.bottom =
					SW_MAX(enclosingRect->bottom, intersectionRect.bottom);
		}
		else
		{
			enclosingRectNeedsInitialization = false;
			newEnclosingRect = intersectionRect;
		}
		*enclosingRect = newEnclosingRect;
	}
}
void SWCollectIdleSpriteIntersectingRects ( SWRect checkRect1 , SWRect checkRect2 , SWRect * enclosingRect ) { SWRect newEnclosingRect ; SWRect intersectionRect ; int enclosingRectNeedsInitialization ; if ( ( enclosingRect -> left == 0 ) && ( enclosingRect -> right == 0 ) && ( enclosingRect -> top == 0 ) && ( enclosingRect -> bottom == 0 ) ) { enclosingRectNeedsInitialization = true ; } else { enclosingRectNeedsInitialization = false ; } if ( ( checkRect1 . top < checkRect2 . bottom ) && ( checkRect1 . bottom > checkRect2 . top ) && ( checkRect1 . left < checkRect2 . right ) && ( checkRect1 . right > checkRect2 . left ) ) { intersectionRect . left = SW_MAX ( checkRect1 . left , checkRect2 . left ) ; intersectionRect . top = SW_MAX ( checkRect1 . top , checkRect2 . top ) ; intersectionRect . right = SW_MIN ( checkRect1 . right , checkRect2 . right ) ; intersectionRect . bottom = SW_MIN ( checkRect1 . bottom , checkRect2 . bottom ) ; if ( ! enclosingRectNeedsInitialization ) { newEnclosingRect . left = SW_MIN ( enclosingRect -> left , intersectionRect . left ) ; newEnclosingRect . top = SW_MIN ( enclosingRect -> top , intersectionRect . top ) ; newEnclosingRect . right = SW_MAX ( enclosingRect -> right , intersectionRect . right ) ; newEnclosingRect . bottom = SW_MAX ( enclosingRect -> bottom , intersectionRect . bottom ) ; } else { enclosingRectNeedsInitialization = false ; newEnclosingRect = intersectionRect ; } * enclosingRect = newEnclosingRect ; } }
SWCollectIntersectingRects - find the minimum rect that encloses the current
enclosing rect and the intersection of checkRect1 and checkRect2
SWCollectIntersectingRects - find the minimum rect that encloses the current enclosing rect and the intersection of checkRect1 and checkRect2
// determine if we need to initialize the collection // do the rects intersect? // calculate the intersection between the two rects // caclulate the smallest rect which encloses all the intersection // rects found so far // initialize the enclosing rect with the first intersection