Changeset 2157:f9171bfc7ebb in lemon-0.x for lemon
- Timestamp:
- 07/20/06 08:20:27 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2872
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/xy.h
r2006 r2157 48 48 /// operators. 49 49 /// 50 ///\note As you might have noticed, this class does not follow the 51 ///\ref naming_conv "LEMON Coding Style" (it should be called \c Xy 52 ///according to it). There is a stupid Hungarian proverb, "A kivétel 53 ///erõsíti a szabályt" ("An exception 54 ///reinforces a rule", which is 55 ///actually a mistranslation of the Latin proverb "Exceptio probat regulam"). 56 ///This class is an example for that. 50 57 ///\author Attila Bernath 51 58 template<typename T> … … 64 71 xy() {} 65 72 66 ///Construct ing theinstance from coordinates73 ///Construct an instance from coordinates 67 74 xy(T a, T b) : x(a), y(b) { } 68 75 … … 71 78 template<class TT> xy(const xy<TT> &p) : x(p.x), y(p.y) {} 72 79 73 ///Give sback the square of the norm of the vector80 ///Give back the square of the norm of the vector 74 81 T normSquare() const { 75 82 return x*x+y*y; 76 83 } 77 84 78 ///Increment sthe left hand side by u85 ///Increment the left hand side by u 79 86 xy<T>& operator +=(const xy<T>& u) { 80 87 x += u.x; … … 83 90 } 84 91 85 ///Decrement sthe left hand side by u92 ///Decrement the left hand side by u 86 93 xy<T>& operator -=(const xy<T>& u) { 87 94 x -= u.x; … … 90 97 } 91 98 92 ///Multiply ingthe left hand side with a scalar99 ///Multiply the left hand side with a scalar 93 100 xy<T>& operator *=(const T &u) { 94 101 x *= u; … … 97 104 } 98 105 99 ///Divid ingthe left hand side by a scalar106 ///Divide the left hand side by a scalar 100 107 xy<T>& operator /=(const T &u) { 101 108 x /= u; … … 104 111 } 105 112 106 ///Return sthe scalar product of two vectors113 ///Return the scalar product of two vectors 107 114 T operator *(const xy<T>& u) const { 108 115 return x*u.x+y*u.y; 109 116 } 110 117 111 ///Return sthe sum of two vectors118 ///Return the sum of two vectors 112 119 xy<T> operator+(const xy<T> &u) const { 113 120 xy<T> b=*this; … … 115 122 } 116 123 117 ///Return sthe neg of the vectors124 ///Return the neg of the vectors 118 125 xy<T> operator-() const { 119 126 xy<T> b=*this; … … 122 129 } 123 130 124 ///Return sthe difference of two vectors131 ///Return the difference of two vectors 125 132 xy<T> operator-(const xy<T> &u) const { 126 133 xy<T> b=*this; … … 128 135 } 129 136 130 ///Return sa vector multiplied by a scalar137 ///Return a vector multiplied by a scalar 131 138 xy<T> operator*(const T &u) const { 132 139 xy<T> b=*this; … … 134 141 } 135 142 136 ///Return sa vector divided by a scalar143 ///Return a vector divided by a scalar 137 144 xy<T> operator/(const T &u) const { 138 145 xy<T> b=*this; … … 140 147 } 141 148 142 ///Test ingequality149 ///Test equality 143 150 bool operator==(const xy<T> &u) const { 144 151 return (x==u.x) && (y==u.y); 145 152 } 146 153 147 ///Test inginequality154 ///Test inequality 148 155 bool operator!=(xy u) const { 149 156 return (x!=u.x) || (y!=u.y); … … 152 159 }; 153 160 154 ///Return san xy155 156 ///Return san xy161 ///Return an xy 162 163 ///Return an xy 157 164 ///\relates xy 158 165 template <typename T> … … 161 168 } 162 169 163 ///Return sa vector multiplied by a scalar164 165 ///Return sa vector multiplied by a scalar170 ///Return a vector multiplied by a scalar 171 172 ///Return a vector multiplied by a scalar 166 173 ///\relates xy 167 174 template<typename T> xy<T> operator*(const T &u,const xy<T> &x) { … … 220 227 } 221 228 229 ///Rotate by 180 degrees 230 231 ///Returns its parameter rotated by 180 degrees. 232 ///\relates xy 233 /// 234 template<typename T> 235 inline xy<T> rot180(const xy<T> &z) 236 { 237 return xy<T>(-z.x,-z.y); 238 } 239 222 240 ///Rotate by 270 degrees 223 241 … … 247 265 BoundingBox() { _empty = true; } 248 266 249 ///Construct ing theinstance from one point267 ///Construct an instance from one point 250 268 BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; } 251 269 … … 255 273 } 256 274 257 ///Make sthe BoundingBox empty275 ///Make the BoundingBox empty 258 276 void clear() { 259 277 _empty=1; 260 278 } 261 279 262 ///\brief Gives back the bottom left corner 263 ///(if the bounding box is empty, then the return value is not defined) 280 ///Give back the bottom left corner 281 282 ///Give back the bottom left corner. 283 ///If the bounding box is empty, then the return value is not defined. 264 284 xy<T> bottomLeft() const { 265 285 return bottom_left; 266 286 } 267 287 268 ///\brief Sets the bottom left corner 269 ///(should only bee used for non-empty box) 288 ///Set the bottom left corner 289 290 ///Set the bottom left corner. 291 ///It should only bee used for non-empty box. 270 292 void bottomLeft(xy<T> p) { 271 293 bottom_left = p; 272 294 } 273 295 274 ///\brief Gives back the top right corner 275 ///(if the bounding box is empty, then the return value is not defined) 296 ///Give back the top right corner 297 298 ///Give back the top right corner. 299 ///If the bounding box is empty, then the return value is not defined. 276 300 xy<T> topRight() const { 277 301 return top_right; 278 302 } 279 303 280 ///\brief Sets the top right corner 281 ///(should only bee used for non-empty box) 304 ///Set the top right corner 305 306 ///Set the top right corner. 307 ///It should only bee used for non-empty box. 282 308 void topRight(xy<T> p) { 283 309 top_right = p; 284 310 } 285 311 286 ///\brief Gives back the bottom right corner 287 ///(if the bounding box is empty, then the return value is not defined) 312 ///Give back the bottom right corner 313 314 ///Give back the bottom right corner. 315 ///If the bounding box is empty, then the return value is not defined. 288 316 xy<T> bottomRight() const { 289 317 return xy<T>(top_right.x,bottom_left.y); 290 318 } 291 319 292 ///\brief Sets the bottom right corner 293 ///(should only bee used for non-empty box) 320 ///Set the bottom right corner 321 322 ///Set the bottom right corner. 323 ///It should only bee used for non-empty box. 294 324 void bottomRight(xy<T> p) { 295 325 top_right.x = p.x; 296 326 bottom_left.y = p.y; 297 327 } 298 299 ///\brief Gives back the top left corner 300 ///(if the bounding box is empty, then the return value is not defined) 328 329 ///Give back the top left corner 330 331 ///Give back the top left corner. 332 ///If the bounding box is empty, then the return value is not defined. 301 333 xy<T> topLeft() const { 302 334 return xy<T>(bottom_left.x,top_right.y); 303 335 } 304 336 305 ///\brief Sets the top left corner 306 ///(should only bee used for non-empty box) 337 ///Set the top left corner 338 339 ///Set the top left corner. 340 ///It should only bee used for non-empty box. 307 341 void topLeft(xy<T> p) { 308 342 top_right.y = p.y; … … 310 344 } 311 345 312 ///\brief Gives back the bottom of the box 313 ///(if the bounding box is empty, then the return value is not defined) 346 ///Give back the bottom of the box 347 348 ///Give back the bottom of the box. 349 ///If the bounding box is empty, then the return value is not defined. 314 350 T bottom() const { 315 351 return bottom_left.y; 316 352 } 317 353 318 ///\brief Sets the bottom of the box 319 ///(should only bee used for non-empty box) 354 ///Set the bottom of the box 355 356 ///Set the bottom of the box. 357 ///It should only bee used for non-empty box. 320 358 void bottom(T t) { 321 359 bottom_left.y = t; 322 360 } 323 361 324 ///\brief Gives back the top of the box 325 ///(if the bounding box is empty, then the return value is not defined) 362 ///Give back the top of the box 363 364 ///Give back the top of the box. 365 ///If the bounding box is empty, then the return value is not defined. 326 366 T top() const { 327 367 return top_right.y; 328 368 } 329 369 330 ///\brief Sets the top of the box 331 ///(should only bee used for non-empty box) 370 ///Set the top of the box 371 372 ///Set the top of the box. 373 ///It should only bee used for non-empty box. 332 374 void top(T t) { 333 375 top_right.y = t; 334 376 } 335 377 336 ///\brief Gives back the left side of the box 337 ///(if the bounding box is empty, then the return value is not defined) 378 ///Give back the left side of the box 379 380 ///Give back the left side of the box. 381 ///If the bounding box is empty, then the return value is not defined. 338 382 T left() const { 339 383 return bottom_left.x; 340 384 } 341 342 ///\brief Sets the left side of the box 343 ///(should only bee used for non-empty box) 385 386 ///Set the left side of the box 387 388 ///Set the left side of the box. 389 ///It should only bee used for non-empty box 344 390 void left(T t) { 345 391 bottom_left.x = t; 346 392 } 347 393 348 ///\brief Gives back the right side of the box 349 ///(if the bounding box is empty, then the return value is not defined) 394 /// Give back the right side of the box 395 396 /// Give back the right side of the box. 397 ///If the bounding box is empty, then the return value is not defined. 350 398 T right() const { 351 399 return top_right.x; 352 400 } 353 401 354 ///\brief Sets the right side of the box 355 ///(should only bee used for non-empty box) 402 ///Set the right side of the box 403 404 ///Set the right side of the box. 405 ///It should only bee used for non-empty box 356 406 void right(T t) { 357 407 top_right.x = t; 358 408 } 359 409 360 ///\brief Gives back the height of the box 361 ///(if the bounding box is empty, then the return value is not defined) 410 ///Give back the height of the box 411 412 ///Give back the height of the box. 413 ///If the bounding box is empty, then the return value is not defined. 362 414 T height() const { 363 415 return top_right.y-bottom_left.y; 364 416 } 365 417 366 ///\brief Gives back the width of the box 367 ///(if the bounding box is empty, then the return value is not defined) 418 ///Give back the width of the box 419 420 ///Give back the width of the box. 421 ///If the bounding box is empty, then the return value is not defined. 368 422 T width() const { 369 423 return top_right.x-bottom_left.x;
Note: See TracChangeset
for help on using the changeset viewer.