1.1 --- a/src/lemon/xy.h Mon May 16 21:49:35 2005 +0000
1.2 +++ b/src/lemon/xy.h Wed May 18 09:39:06 2005 +0000
1.3 @@ -29,7 +29,7 @@
1.4 /// operations.
1.5 ///
1.6 /// The class \ref lemon::BoundingBox "BoundingBox" can be used to determine
1.7 -/// the rectangular bounding box a set of \ref lemon::xy "xy"'s.
1.8 +/// the rectangular bounding box of a set of \ref lemon::xy "xy"'s.
1.9 ///
1.10 ///\author Attila Bernath
1.11
1.12 @@ -67,81 +67,81 @@
1.13
1.14 ///Gives back the square of the norm of the vector
1.15 T normSquare() const {
1.16 - return x*x+y*y;
1.17 + return x*x+y*y;
1.18 }
1.19
1.20 ///Increments the left hand side by u
1.21 xy<T>& operator +=(const xy<T>& u) {
1.22 - x += u.x;
1.23 - y += u.y;
1.24 - return *this;
1.25 + x += u.x;
1.26 + y += u.y;
1.27 + return *this;
1.28 }
1.29
1.30 ///Decrements the left hand side by u
1.31 xy<T>& operator -=(const xy<T>& u) {
1.32 - x -= u.x;
1.33 - y -= u.y;
1.34 - return *this;
1.35 + x -= u.x;
1.36 + y -= u.y;
1.37 + return *this;
1.38 }
1.39
1.40 ///Multiplying the left hand side with a scalar
1.41 xy<T>& operator *=(const T &u) {
1.42 - x *= u;
1.43 - y *= u;
1.44 - return *this;
1.45 + x *= u;
1.46 + y *= u;
1.47 + return *this;
1.48 }
1.49
1.50 ///Dividing the left hand side by a scalar
1.51 xy<T>& operator /=(const T &u) {
1.52 - x /= u;
1.53 - y /= u;
1.54 - return *this;
1.55 + x /= u;
1.56 + y /= u;
1.57 + return *this;
1.58 }
1.59
1.60 ///Returns the scalar product of two vectors
1.61 T operator *(const xy<T>& u) const {
1.62 - return x*u.x+y*u.y;
1.63 + return x*u.x+y*u.y;
1.64 }
1.65
1.66 ///Returns the sum of two vectors
1.67 xy<T> operator+(const xy<T> &u) const {
1.68 - xy<T> b=*this;
1.69 - return b+=u;
1.70 + xy<T> b=*this;
1.71 + return b+=u;
1.72 }
1.73
1.74 ///Returns the neg of the vectors
1.75 xy<T> operator-() const {
1.76 - xy<T> b=*this;
1.77 - b.x=-b.x; b.y=-b.y;
1.78 - return b;
1.79 + xy<T> b=*this;
1.80 + b.x=-b.x; b.y=-b.y;
1.81 + return b;
1.82 }
1.83
1.84 ///Returns the difference of two vectors
1.85 xy<T> operator-(const xy<T> &u) const {
1.86 - xy<T> b=*this;
1.87 - return b-=u;
1.88 + xy<T> b=*this;
1.89 + return b-=u;
1.90 }
1.91
1.92 ///Returns a vector multiplied by a scalar
1.93 xy<T> operator*(const T &u) const {
1.94 - xy<T> b=*this;
1.95 - return b*=u;
1.96 + xy<T> b=*this;
1.97 + return b*=u;
1.98 }
1.99
1.100 ///Returns a vector divided by a scalar
1.101 xy<T> operator/(const T &u) const {
1.102 - xy<T> b=*this;
1.103 - return b/=u;
1.104 + xy<T> b=*this;
1.105 + return b/=u;
1.106 }
1.107
1.108 ///Testing equality
1.109 bool operator==(const xy<T> &u) const {
1.110 - return (x==u.x) && (y==u.y);
1.111 + return (x==u.x) && (y==u.y);
1.112 }
1.113
1.114 ///Testing inequality
1.115 bool operator!=(xy u) const {
1.116 - return (x!=u.x) || (y!=u.y);
1.117 + return (x!=u.x) || (y!=u.y);
1.118 }
1.119
1.120 };
1.121 @@ -229,116 +229,116 @@
1.122 bool _empty;
1.123 public:
1.124
1.125 - ///Default constructor: an empty bounding box
1.126 + ///Default constructor: creates an empty bounding box
1.127 BoundingBox() { _empty = true; }
1.128
1.129 ///Constructing the instance from one point
1.130 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
1.131
1.132 - ///Is there any point added
1.133 + ///Were any points added?
1.134 bool empty() const {
1.135 - return _empty;
1.136 + return _empty;
1.137 }
1.138
1.139 ///Makes the BoundingBox empty
1.140 void clear() {
1.141 - _empty=1;
1.142 + _empty=1;
1.143 }
1.144
1.145 ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined)
1.146 xy<T> bottomLeft() const {
1.147 - return bottom_left;
1.148 + return bottom_left;
1.149 }
1.150
1.151 ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined)
1.152 xy<T> topRight() const {
1.153 - return top_right;
1.154 + return top_right;
1.155 }
1.156
1.157 ///Gives back the bottom right corner (if the bounding box is empty, then the return value is not defined)
1.158 xy<T> bottomRight() const {
1.159 - return xy<T>(top_right.x,bottom_left.y);
1.160 + return xy<T>(top_right.x,bottom_left.y);
1.161 }
1.162
1.163 ///Gives back the top left corner (if the bounding box is empty, then the return value is not defined)
1.164 xy<T> topLeft() const {
1.165 - return xy<T>(bottom_left.x,top_right.y);
1.166 + return xy<T>(bottom_left.x,top_right.y);
1.167 }
1.168
1.169 ///Gives back the bottom of the box (if the bounding box is empty, then the return value is not defined)
1.170 T bottom() const {
1.171 - return bottom_left.y;
1.172 + return bottom_left.y;
1.173 }
1.174
1.175 ///Gives back the top of the box (if the bounding box is empty, then the return value is not defined)
1.176 T top() const {
1.177 - return top_right.y;
1.178 + return top_right.y;
1.179 }
1.180
1.181 ///Gives back the left side of the box (if the bounding box is empty, then the return value is not defined)
1.182 T left() const {
1.183 - return bottom_left.x;
1.184 + return bottom_left.x;
1.185 }
1.186
1.187 ///Gives back the right side of the box (if the bounding box is empty, then the return value is not defined)
1.188 T right() const {
1.189 - return top_right.x;
1.190 + return top_right.x;
1.191 }
1.192
1.193 ///Gives back the height of the box (if the bounding box is empty, then the return value is not defined)
1.194 T height() const {
1.195 - return top_right.y-bottom_left.y;
1.196 + return top_right.y-bottom_left.y;
1.197 }
1.198
1.199 ///Gives back the width of the box (if the bounding box is empty, then the return value is not defined)
1.200 T width() const {
1.201 - return top_right.x-bottom_left.x;
1.202 + return top_right.x-bottom_left.x;
1.203 }
1.204
1.205 ///Checks whether a point is inside a bounding box
1.206 bool inside(const xy<T>& u){
1.207 - if (_empty)
1.208 - return false;
1.209 - else{
1.210 - return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
1.211 - (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
1.212 - }
1.213 + if (_empty)
1.214 + return false;
1.215 + else{
1.216 + return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
1.217 + (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
1.218 + }
1.219 }
1.220
1.221 ///Increments a bounding box with a point
1.222 BoundingBox& operator +=(const xy<T>& u){
1.223 - if (_empty){
1.224 - bottom_left=top_right=u;
1.225 - _empty = false;
1.226 - }
1.227 - else{
1.228 - if (bottom_left.x > u.x) bottom_left.x = u.x;
1.229 - if (bottom_left.y > u.y) bottom_left.y = u.y;
1.230 - if (top_right.x < u.x) top_right.x = u.x;
1.231 - if (top_right.y < u.y) top_right.y = u.y;
1.232 - }
1.233 - return *this;
1.234 + if (_empty){
1.235 + bottom_left=top_right=u;
1.236 + _empty = false;
1.237 + }
1.238 + else{
1.239 + if (bottom_left.x > u.x) bottom_left.x = u.x;
1.240 + if (bottom_left.y > u.y) bottom_left.y = u.y;
1.241 + if (top_right.x < u.x) top_right.x = u.x;
1.242 + if (top_right.y < u.y) top_right.y = u.y;
1.243 + }
1.244 + return *this;
1.245 }
1.246
1.247 ///Sums a bounding box and a point
1.248 BoundingBox operator +(const xy<T>& u){
1.249 - BoundingBox b = *this;
1.250 - return b += u;
1.251 + BoundingBox b = *this;
1.252 + return b += u;
1.253 }
1.254
1.255 ///Increments a bounding box with an other bounding box
1.256 BoundingBox& operator +=(const BoundingBox &u){
1.257 - if ( !u.empty() ){
1.258 - *this += u.bottomLeft();
1.259 - *this += u.topRight();
1.260 - }
1.261 - return *this;
1.262 + if ( !u.empty() ){
1.263 + *this += u.bottomLeft();
1.264 + *this += u.topRight();
1.265 + }
1.266 + return *this;
1.267 }
1.268
1.269 ///Sums two bounding boxes
1.270 BoundingBox operator +(const BoundingBox& u){
1.271 - BoundingBox b = *this;
1.272 - return b += u;
1.273 + BoundingBox b = *this;
1.274 + return b += u;
1.275 }
1.276
1.277 };//class Boundingbox