3 Implementation of a bounding box of plainvectors.
6 #ifndef HUGO_BOUNDINGBOX_H
7 #define HUGO_BOUNDINGBOX_H
16 xy<T> bottomleft, topright;
20 ///Default constructor: an empty bounding box
21 BoundingBox() { _empty = true; }
23 ///Constructing the instance from one point
24 BoundingBox(xy<T> a) { bottomleft=topright=a; _empty = false; }
26 ///Is there any point added
31 ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined)
32 xy<T> bottomLeft() const {
36 ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined)
37 xy<T> topRight() const {
41 ///Checks whether a point is inside a bounding box
42 bool inside(const xy<T>& u){
46 return ((u.x-bottomleft.x)*(topright.x-u.x) >= 0 &&
47 (u.y-bottomleft.y)*(topright.y-u.y) >= 0 );
51 ///Increments a bounding box with a point
52 BoundingBox& operator +=(const xy<T>& u){
54 bottomleft=topright=u;
58 if (bottomleft.x > u.x) bottomleft.x = u.x;
59 if (bottomleft.y > u.y) bottomleft.y = u.y;
60 if (topright.x < u.x) topright.x = u.x;
61 if (topright.y < u.y) topright.y = u.y;
66 ///Sums a bounding box and a point
67 BoundingBox operator +(const xy<T>& u){
68 BoundingBox b = *this;
72 ///Increments a bounding box with an other bounding box
73 BoundingBox& operator +=(const BoundingBox &u){
75 *this += u.bottomLeft();
76 *this += u.topRight();
81 ///Sums two bounding boxes
82 BoundingBox operator +(const BoundingBox& u){
83 BoundingBox b = *this;
92 #endif //HUGO_BOUNDINGBOX_H