1.1 --- a/lemon/xy.h Wed Jul 19 15:13:24 2006 +0000
1.2 +++ b/lemon/xy.h Thu Jul 20 06:20:27 2006 +0000
1.3 @@ -47,6 +47,13 @@
1.4 ///with the usual vector
1.5 /// operators.
1.6 ///
1.7 + ///\note As you might have noticed, this class does not follow the
1.8 + ///\ref naming_conv "LEMON Coding Style" (it should be called \c Xy
1.9 + ///according to it). There is a stupid Hungarian proverb, "A kivétel
1.10 + ///erõsíti a szabályt" ("An exception
1.11 + ///reinforces a rule", which is
1.12 + ///actually a mistranslation of the Latin proverb "Exceptio probat regulam").
1.13 + ///This class is an example for that.
1.14 ///\author Attila Bernath
1.15 template<typename T>
1.16 class xy {
1.17 @@ -63,106 +70,106 @@
1.18 ///Default constructor
1.19 xy() {}
1.20
1.21 - ///Constructing the instance from coordinates
1.22 + ///Construct an instance from coordinates
1.23 xy(T a, T b) : x(a), y(b) { }
1.24
1.25
1.26 ///Conversion constructor
1.27 template<class TT> xy(const xy<TT> &p) : x(p.x), y(p.y) {}
1.28
1.29 - ///Gives back the square of the norm of the vector
1.30 + ///Give back the square of the norm of the vector
1.31 T normSquare() const {
1.32 return x*x+y*y;
1.33 }
1.34
1.35 - ///Increments the left hand side by u
1.36 + ///Increment the left hand side by u
1.37 xy<T>& operator +=(const xy<T>& u) {
1.38 x += u.x;
1.39 y += u.y;
1.40 return *this;
1.41 }
1.42
1.43 - ///Decrements the left hand side by u
1.44 + ///Decrement the left hand side by u
1.45 xy<T>& operator -=(const xy<T>& u) {
1.46 x -= u.x;
1.47 y -= u.y;
1.48 return *this;
1.49 }
1.50
1.51 - ///Multiplying the left hand side with a scalar
1.52 + ///Multiply the left hand side with a scalar
1.53 xy<T>& operator *=(const T &u) {
1.54 x *= u;
1.55 y *= u;
1.56 return *this;
1.57 }
1.58
1.59 - ///Dividing the left hand side by a scalar
1.60 + ///Divide the left hand side by a scalar
1.61 xy<T>& operator /=(const T &u) {
1.62 x /= u;
1.63 y /= u;
1.64 return *this;
1.65 }
1.66
1.67 - ///Returns the scalar product of two vectors
1.68 + ///Return the scalar product of two vectors
1.69 T operator *(const xy<T>& u) const {
1.70 return x*u.x+y*u.y;
1.71 }
1.72
1.73 - ///Returns the sum of two vectors
1.74 + ///Return the sum of two vectors
1.75 xy<T> operator+(const xy<T> &u) const {
1.76 xy<T> b=*this;
1.77 return b+=u;
1.78 }
1.79
1.80 - ///Returns the neg of the vectors
1.81 + ///Return the neg of the vectors
1.82 xy<T> operator-() const {
1.83 xy<T> b=*this;
1.84 b.x=-b.x; b.y=-b.y;
1.85 return b;
1.86 }
1.87
1.88 - ///Returns the difference of two vectors
1.89 + ///Return the difference of two vectors
1.90 xy<T> operator-(const xy<T> &u) const {
1.91 xy<T> b=*this;
1.92 return b-=u;
1.93 }
1.94
1.95 - ///Returns a vector multiplied by a scalar
1.96 + ///Return a vector multiplied by a scalar
1.97 xy<T> operator*(const T &u) const {
1.98 xy<T> b=*this;
1.99 return b*=u;
1.100 }
1.101
1.102 - ///Returns a vector divided by a scalar
1.103 + ///Return a vector divided by a scalar
1.104 xy<T> operator/(const T &u) const {
1.105 xy<T> b=*this;
1.106 return b/=u;
1.107 }
1.108
1.109 - ///Testing equality
1.110 + ///Test equality
1.111 bool operator==(const xy<T> &u) const {
1.112 return (x==u.x) && (y==u.y);
1.113 }
1.114
1.115 - ///Testing inequality
1.116 + ///Test inequality
1.117 bool operator!=(xy u) const {
1.118 return (x!=u.x) || (y!=u.y);
1.119 }
1.120
1.121 };
1.122
1.123 - ///Returns an xy
1.124 + ///Return an xy
1.125
1.126 - ///Returns an xy
1.127 + ///Return an xy
1.128 ///\relates xy
1.129 template <typename T>
1.130 inline xy<T> make_xy(const T& x, const T& y) {
1.131 return xy<T>(x, y);
1.132 }
1.133
1.134 - ///Returns a vector multiplied by a scalar
1.135 + ///Return a vector multiplied by a scalar
1.136
1.137 - ///Returns a vector multiplied by a scalar
1.138 + ///Return a vector multiplied by a scalar
1.139 ///\relates xy
1.140 template<typename T> xy<T> operator*(const T &u,const xy<T> &x) {
1.141 return x*u;
1.142 @@ -219,6 +226,17 @@
1.143 return xy<T>(-z.y,z.x);
1.144 }
1.145
1.146 + ///Rotate by 180 degrees
1.147 +
1.148 + ///Returns its parameter rotated by 180 degrees.
1.149 + ///\relates xy
1.150 + ///
1.151 + template<typename T>
1.152 + inline xy<T> rot180(const xy<T> &z)
1.153 + {
1.154 + return xy<T>(-z.x,-z.y);
1.155 + }
1.156 +
1.157 ///Rotate by 270 degrees
1.158
1.159 ///Returns its parameter rotated by 90 degrees in negative direction.
1.160 @@ -246,7 +264,7 @@
1.161 ///Default constructor: creates an empty bounding box
1.162 BoundingBox() { _empty = true; }
1.163
1.164 - ///Constructing the instance from one point
1.165 + ///Construct an instance from one point
1.166 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
1.167
1.168 ///Were any points added?
1.169 @@ -254,117 +272,153 @@
1.170 return _empty;
1.171 }
1.172
1.173 - ///Makes the BoundingBox empty
1.174 + ///Make the BoundingBox empty
1.175 void clear() {
1.176 _empty=1;
1.177 }
1.178
1.179 - ///\brief Gives back the bottom left corner
1.180 - ///(if the bounding box is empty, then the return value is not defined)
1.181 + ///Give back the bottom left corner
1.182 +
1.183 + ///Give back the bottom left corner.
1.184 + ///If the bounding box is empty, then the return value is not defined.
1.185 xy<T> bottomLeft() const {
1.186 return bottom_left;
1.187 }
1.188
1.189 - ///\brief Sets the bottom left corner
1.190 - ///(should only bee used for non-empty box)
1.191 + ///Set the bottom left corner
1.192 +
1.193 + ///Set the bottom left corner.
1.194 + ///It should only bee used for non-empty box.
1.195 void bottomLeft(xy<T> p) {
1.196 bottom_left = p;
1.197 }
1.198
1.199 - ///\brief Gives back the top right corner
1.200 - ///(if the bounding box is empty, then the return value is not defined)
1.201 + ///Give back the top right corner
1.202 +
1.203 + ///Give back the top right corner.
1.204 + ///If the bounding box is empty, then the return value is not defined.
1.205 xy<T> topRight() const {
1.206 return top_right;
1.207 }
1.208
1.209 - ///\brief Sets the top right corner
1.210 - ///(should only bee used for non-empty box)
1.211 + ///Set the top right corner
1.212 +
1.213 + ///Set the top right corner.
1.214 + ///It should only bee used for non-empty box.
1.215 void topRight(xy<T> p) {
1.216 top_right = p;
1.217 }
1.218
1.219 - ///\brief Gives back the bottom right corner
1.220 - ///(if the bounding box is empty, then the return value is not defined)
1.221 + ///Give back the bottom right corner
1.222 +
1.223 + ///Give back the bottom right corner.
1.224 + ///If the bounding box is empty, then the return value is not defined.
1.225 xy<T> bottomRight() const {
1.226 return xy<T>(top_right.x,bottom_left.y);
1.227 }
1.228
1.229 - ///\brief Sets the bottom right corner
1.230 - ///(should only bee used for non-empty box)
1.231 + ///Set the bottom right corner
1.232 +
1.233 + ///Set the bottom right corner.
1.234 + ///It should only bee used for non-empty box.
1.235 void bottomRight(xy<T> p) {
1.236 top_right.x = p.x;
1.237 bottom_left.y = p.y;
1.238 }
1.239 +
1.240 + ///Give back the top left corner
1.241
1.242 - ///\brief Gives back the top left corner
1.243 - ///(if the bounding box is empty, then the return value is not defined)
1.244 + ///Give back the top left corner.
1.245 + ///If the bounding box is empty, then the return value is not defined.
1.246 xy<T> topLeft() const {
1.247 return xy<T>(bottom_left.x,top_right.y);
1.248 }
1.249
1.250 - ///\brief Sets the top left corner
1.251 - ///(should only bee used for non-empty box)
1.252 + ///Set the top left corner
1.253 +
1.254 + ///Set the top left corner.
1.255 + ///It should only bee used for non-empty box.
1.256 void topLeft(xy<T> p) {
1.257 top_right.y = p.y;
1.258 bottom_left.x = p.x;
1.259 }
1.260
1.261 - ///\brief Gives back the bottom of the box
1.262 - ///(if the bounding box is empty, then the return value is not defined)
1.263 + ///Give back the bottom of the box
1.264 +
1.265 + ///Give back the bottom of the box.
1.266 + ///If the bounding box is empty, then the return value is not defined.
1.267 T bottom() const {
1.268 return bottom_left.y;
1.269 }
1.270
1.271 - ///\brief Sets the bottom of the box
1.272 - ///(should only bee used for non-empty box)
1.273 + ///Set the bottom of the box
1.274 +
1.275 + ///Set the bottom of the box.
1.276 + ///It should only bee used for non-empty box.
1.277 void bottom(T t) {
1.278 bottom_left.y = t;
1.279 }
1.280
1.281 - ///\brief Gives back the top of the box
1.282 - ///(if the bounding box is empty, then the return value is not defined)
1.283 + ///Give back the top of the box
1.284 +
1.285 + ///Give back the top of the box.
1.286 + ///If the bounding box is empty, then the return value is not defined.
1.287 T top() const {
1.288 return top_right.y;
1.289 }
1.290
1.291 - ///\brief Sets the top of the box
1.292 - ///(should only bee used for non-empty box)
1.293 + ///Set the top of the box
1.294 +
1.295 + ///Set the top of the box.
1.296 + ///It should only bee used for non-empty box.
1.297 void top(T t) {
1.298 top_right.y = t;
1.299 }
1.300
1.301 - ///\brief Gives back the left side of the box
1.302 - ///(if the bounding box is empty, then the return value is not defined)
1.303 + ///Give back the left side of the box
1.304 +
1.305 + ///Give back the left side of the box.
1.306 + ///If the bounding box is empty, then the return value is not defined.
1.307 T left() const {
1.308 return bottom_left.x;
1.309 }
1.310 +
1.311 + ///Set the left side of the box
1.312
1.313 - ///\brief Sets the left side of the box
1.314 - ///(should only bee used for non-empty box)
1.315 + ///Set the left side of the box.
1.316 + ///It should only bee used for non-empty box
1.317 void left(T t) {
1.318 bottom_left.x = t;
1.319 }
1.320
1.321 - ///\brief Gives back the right side of the box
1.322 - ///(if the bounding box is empty, then the return value is not defined)
1.323 + /// Give back the right side of the box
1.324 +
1.325 + /// Give back the right side of the box.
1.326 + ///If the bounding box is empty, then the return value is not defined.
1.327 T right() const {
1.328 return top_right.x;
1.329 }
1.330
1.331 - ///\brief Sets the right side of the box
1.332 - ///(should only bee used for non-empty box)
1.333 + ///Set the right side of the box
1.334 +
1.335 + ///Set the right side of the box.
1.336 + ///It should only bee used for non-empty box
1.337 void right(T t) {
1.338 top_right.x = t;
1.339 }
1.340
1.341 - ///\brief Gives back the height of the box
1.342 - ///(if the bounding box is empty, then the return value is not defined)
1.343 + ///Give back the height of the box
1.344 +
1.345 + ///Give back the height of the box.
1.346 + ///If the bounding box is empty, then the return value is not defined.
1.347 T height() const {
1.348 return top_right.y-bottom_left.y;
1.349 }
1.350
1.351 - ///\brief Gives back the width of the box
1.352 - ///(if the bounding box is empty, then the return value is not defined)
1.353 + ///Give back the width of the box
1.354 +
1.355 + ///Give back the width of the box.
1.356 + ///If the bounding box is empty, then the return value is not defined.
1.357 T width() const {
1.358 return top_right.x-bottom_left.x;
1.359 }