Changeset 244:0e02be2ca43c in lemon0.x
 Timestamp:
 03/25/04 18:38:45 (19 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@344
 Location:
 src/work/athos/xy
 Files:

 1 deleted
 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/athos/xy/boundingbox.cc
r240 r244 1 #include < boundingbox.h>1 #include <xy.h> 2 2 3 3 #include <iostream> 
src/work/athos/xy/xy.h
r242 r244 118 118 } 119 119 120 121 /** \brief 122 Implementation of a bounding box of plainvectors. 123 124 */ 125 template<typename T> 126 class BoundingBox { 127 xy<T> bottom_left, top_right; 128 bool _empty; 129 public: 130 131 ///Default constructor: an empty bounding box 132 BoundingBox() { _empty = true; } 133 134 ///Constructing the instance from one point 135 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; } 136 137 ///Is there any point added 138 bool empty() const { 139 return _empty; 140 } 141 142 ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined) 143 xy<T> bottomLeft() const { 144 return bottom_left; 145 }; 146 147 ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined) 148 xy<T> topRight() const { 149 return top_right; 150 }; 151 152 ///Checks whether a point is inside a bounding box 153 bool inside(const xy<T>& u){ 154 if (_empty) 155 return false; 156 else{ 157 return ((u.xbottom_left.x)*(top_right.xu.x) >= 0 && 158 (u.ybottom_left.y)*(top_right.yu.y) >= 0 ); 159 } 160 } 161 162 ///Increments a bounding box with a point 163 BoundingBox& operator +=(const xy<T>& u){ 164 if (_empty){ 165 bottom_left=top_right=u; 166 _empty = false; 167 } 168 else{ 169 if (bottom_left.x > u.x) bottom_left.x = u.x; 170 if (bottom_left.y > u.y) bottom_left.y = u.y; 171 if (top_right.x < u.x) top_right.x = u.x; 172 if (top_right.y < u.y) top_right.y = u.y; 173 } 174 return *this; 175 }; 176 177 ///Sums a bounding box and a point 178 BoundingBox operator +(const xy<T>& u){ 179 BoundingBox b = *this; 180 return b += u; 181 }; 182 183 ///Increments a bounding box with an other bounding box 184 BoundingBox& operator +=(const BoundingBox &u){ 185 if ( !u.empty() ){ 186 *this += u.bottomLeft(); 187 *this += u.topRight(); 188 } 189 return *this; 190 }; 191 192 ///Sums two bounding boxes 193 BoundingBox operator +(const BoundingBox& u){ 194 BoundingBox b = *this; 195 return b += u; 196 }; 197 198 };//class Boundingbox 199 200 201 202 120 203 } //namespace hugo 121 204
Note: See TracChangeset
for help on using the changeset viewer.