1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
#include <sstream>
using namespace std;
template <class Number = float>
class Rectangle {
public:
Number x, y, width, height;
Rectangle();
Rectangle(Number x, Number y, Number width, Number height);
Number area();
bool contains(const Rectangle& rect);
bool contains(Number _x, Number _y, Number _width, Number _height);
bool contains(Number pointX, Number pointY);
virtual ~Rectangle();
};
/**************************
** TEMPORARY #DEFINES
***************************/
#define TMP__ template <class Number>
#define RECT Rectangle<Number>
/*****************
** CONSTRUCTORS
******************/
TMP__ RECT::Rectangle()
: x(0), y(0), width(0), height(0) { }
TMP__ RECT::Rectangle(Number x, Number y, Number width, Number height)
: x(x), y(y), width(width), height(height) { }
TMP__ Number RECT::area() {
return width * height;
}
TMP__ bool RECT::contains(const RECT& rect) {
return contains(rect.x, rect.y, rect.width, rect.height);
}
TMP__ bool RECT::contains(Number _x, Number _y) {
return (_x >= x && _y >= y && _x < (x + width) && _y < (y + height));
}
TMP__ bool RECT::contains(Number _x, Number _y, Number _width, Number _height) {
return (_x >= x && _y >= y && (_x + _width) <= (x + width) && (_y + _height) <= (y + height));
}
/********************
** UNDEF TEMPORARIES
*********************/
#undef TMP__
#undef RECT
#endif // RECTANGLE_H
| |