Chris Taylor / Mbed 2 deprecated RETRO-CityRally

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Rect.h Source File

Rect.h

00001 #ifndef __RECT_H__
00002 #define __RECT_H__
00003 
00004 #include <algorithm>
00005 
00006 struct Rect
00007 {
00008     int16_t left;
00009     int16_t top;
00010     int16_t right;
00011     int16_t bottom;
00012     
00013     Rect() :
00014         left(0),
00015         top(0),
00016         right(0),
00017         bottom(0)
00018     {
00019     }
00020     
00021     Rect(int16_t l, int16_t t, int16_t w, int16_t h) :
00022         left(l),
00023         top(t),
00024         right(l + (w - 1)),        
00025         bottom(t + (h - 1))
00026     {
00027     }
00028     
00029     Rect Intersection(Rect &rect)
00030     {
00031         uint8_t x1 = max(left, rect.left);
00032         uint8_t y1 = max(top, rect.top);
00033         uint8_t x2 = min(right, rect.right);
00034         uint8_t y2 = min(bottom, rect.bottom);
00035         
00036         return Rect(x1, y1, x2, y2); 
00037     }
00038     
00039     inline int16_t getWidth() const { return right - left; }
00040     inline int16_t getHeight() const { return bottom - top; }
00041 };
00042 
00043 #endif //__RECT_H__