/** \file IsoGeometryTools.cpp * Contains the definitions of the tools commonly used to manipulate * the POINT and the RECT structures, as well as those that simplify * the transition between the MFC-style rectangle structure, and the * SDL-style rectangular structure. * * @note The author himself is in doubts exactly why he chose to * employ the MFC-style RECT structure in the first place, and didn't * stick solely to SDL_Rect. There were several reasons to that, * actually, but one of these days the migration to one and only * standard will be made, instead of using the two different ones in * different chunks of code and having to convert between them. * * Revision history: * v1.2 - added the setRect method * v1.1 - added the PointInRect and the setRectEmpty methods * * @author Vovansim (aka Scorpion) * @version 1.2 * @date May 26, 2003 */ #include "IsoGeometryTools.h" ///////////////////////////////// POINT tools ///////////////////////////////// /** Creates a new POINT with the given coordinates. */ POINT CreatePoint(int x, int y) { POINT result; result.x = x; result.y = y; return result; } /** Makes an SDL_Rect out of the POINT passed in. Width and Height are 0. */ SDL_Rect* GetSDLRect(POINT* p) { SDL_Rect* result = new SDL_Rect(); result->x = p->x; result->y = p->y; result->w = 0; result->h = 0; return result; } bool PointInRect(RECT* r, POINT* p) { if(p->x <= r->left) { return false; } if(p->x > r->right) { return false; } if(p->y <= r->top) { return false; } if(p->y > r->bottom) { return false; } return true; } /////////////////////////////// End POINT tools /////////////////////////////// ///////////////////////////////// RECT tools ////////////////////////////////// /** Sets all the datat members of the RECT passed in to zero. */ void setRectEmpty(RECT* rectangle) { rectangle->bottom = 0; rectangle->left = 0; rectangle->right = 0; rectangle->top = 0; } /** Sets the data members of the RECT passed in to the values passed in. */ void setRect(RECT* rectangle, long left, long top, long right, long bottom) { rectangle->bottom = bottom; rectangle->left = left; rectangle->right = right; rectangle->top = top; } /** Copies the source rectangle into the destination rectangle. */ void CopyRect(RECT* destination, RECT* source) { destination->bottom = source->bottom; destination->left = source->left; destination->right = source->right; destination->top = source->top; } /** Moves the rectangle passed in by the values passed in. */ void OffsetRect(RECT* rectangle, int dx, int dy) { rectangle->left += dx; rectangle->right += dx; rectangle->top += dy; rectangle->bottom += dy; } void OffsetRect(RECT* rectangle, POINT point) { OffsetRect(rectangle, point.x, point.y); } /** Makes an SDL_Rect out of a RECT. */ SDL_Rect* GetSDLRect(RECT* r) { SDL_Rect* result = new SDL_Rect(); result->x = r->left; result->y = r->top; result->w = r->right - r->left; result->h = r->bottom - r->top; return result; } /////////////////////////////// End RECT tools ////////////////////////////////