src/work/athos/xy/xy.h
changeset 244 0e02be2ca43c
parent 242 b255f25ad394
child 249 0b0bdf24d00c
     1.1 --- a/src/work/athos/xy/xy.h	Thu Mar 25 09:42:59 2004 +0000
     1.2 +++ b/src/work/athos/xy/xy.h	Thu Mar 25 17:38:45 2004 +0000
     1.3 @@ -117,6 +117,89 @@
     1.4      return os;
     1.5    }
     1.6  
     1.7 +
     1.8 +  /** \brief
     1.9 +     Implementation of a bounding box of plainvectors.
    1.10 +     
    1.11 +  */
    1.12 +  template<typename T>
    1.13 +    class BoundingBox {
    1.14 +      xy<T> bottom_left, top_right;
    1.15 +      bool _empty;
    1.16 +    public:
    1.17 +      
    1.18 +      ///Default constructor: an empty bounding box
    1.19 +      BoundingBox() { _empty = true; }
    1.20 +
    1.21 +      ///Constructing the instance from one point
    1.22 +      BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
    1.23 +
    1.24 +      ///Is there any point added
    1.25 +      bool empty() const {
    1.26 +	return _empty;
    1.27 +      }
    1.28 +
    1.29 +      ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined) 
    1.30 +      xy<T> bottomLeft() const {
    1.31 +	return bottom_left;
    1.32 +      };
    1.33 +
    1.34 +      ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined) 
    1.35 +      xy<T> topRight() const {
    1.36 +	return top_right;
    1.37 +      };
    1.38 +
    1.39 +      ///Checks whether a point is inside a bounding box
    1.40 +      bool inside(const xy<T>& u){
    1.41 +	if (_empty)
    1.42 +	  return false;
    1.43 +	else{
    1.44 +	  return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
    1.45 +		  (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
    1.46 +	}
    1.47 +      }
    1.48 +  
    1.49 +      ///Increments a bounding box with a point
    1.50 +      BoundingBox& operator +=(const xy<T>& u){
    1.51 +	if (_empty){
    1.52 +	  bottom_left=top_right=u;
    1.53 +	  _empty = false;
    1.54 +	}
    1.55 +	else{
    1.56 +	  if (bottom_left.x > u.x) bottom_left.x = u.x;
    1.57 +	  if (bottom_left.y > u.y) bottom_left.y = u.y;
    1.58 +	  if (top_right.x < u.x) top_right.x = u.x;
    1.59 +	  if (top_right.y < u.y) top_right.y = u.y;
    1.60 +	}
    1.61 +	return *this;
    1.62 +      };
    1.63 +  
    1.64 +      ///Sums a bounding box and a point
    1.65 +      BoundingBox operator +(const xy<T>& u){
    1.66 +	BoundingBox b = *this;
    1.67 +	return b += u;
    1.68 +      };
    1.69 +
    1.70 +      ///Increments a bounding box with an other bounding box
    1.71 +      BoundingBox& operator +=(const BoundingBox &u){
    1.72 +	if ( !u.empty() ){
    1.73 +	  *this += u.bottomLeft();
    1.74 +	  *this += u.topRight();
    1.75 +	}
    1.76 +	return *this;
    1.77 +      };
    1.78 +  
    1.79 +      ///Sums two bounding boxes
    1.80 +      BoundingBox operator +(const BoundingBox& u){
    1.81 +	BoundingBox b = *this;
    1.82 +	return b += u;
    1.83 +      };
    1.84 +
    1.85 +    };//class Boundingbox
    1.86 +
    1.87 +
    1.88 +
    1.89 +
    1.90  } //namespace hugo
    1.91  
    1.92  #endif //HUGO_XY_H