Changeset 2562:27c54b7f4f1d in lemon-0.x
- Timestamp:
- 02/05/08 12:23:23 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3443
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/dim2.h
r2553 r2562 53 53 54 54 /// A simple two dimensional vector (plainvector) implementation 55 ///with the usual vector 56 /// operators. 57 /// 55 /// with the usual vector operations. 58 56 template<typename T> 59 57 class Point { … … 63 61 typedef T Value; 64 62 65 ///First co -ordinate63 ///First coordinate 66 64 T x; 67 ///Second co -ordinate65 ///Second coordinate 68 66 T y; 69 67 … … 76 74 ///The dimension of the vector. 77 75 78 ///This class give back always 2.76 ///This function always returns 2. 79 77 /// 80 78 int size() const { return 2; } … … 100 98 } 101 99 102 ///Increment the left hand side by u100 ///Increment the left hand side by \c u 103 101 Point<T>& operator +=(const Point<T>& u) { 104 102 x += u.x; … … 107 105 } 108 106 109 ///Decrement the left hand side by u107 ///Decrement the left hand side by \c u 110 108 Point<T>& operator -=(const Point<T>& u) { 111 109 x -= u.x; … … 139 137 } 140 138 141 ///Return the neg of the vectors139 ///Return the negative of the vector 142 140 Point<T> operator-() const { 143 141 Point<T> b=*this; … … 176 174 }; 177 175 178 ///Return a nPoint179 180 ///Return a n Point176 ///Return a Point 177 178 ///Return a Point. 181 179 ///\relates Point 182 180 template <typename T> … … 287 285 ///Construct an instance from two points 288 286 289 ///Construct an instance from two points 290 ///\warning The coordinates of the bottom-left corner must be no more 291 ///than those of the top-right one 287 ///Construct an instance from two points. 288 ///\param a The bottom left corner. 289 ///\param b The top right corner. 290 ///\warning The coordinates of the bottom left corner must be no more 291 ///than those of the top right one. 292 292 BoundingBox(Point<T> a,Point<T> b) 293 293 { … … 299 299 ///Construct an instance from four numbers 300 300 301 ///Construct an instance from four numbers 302 ///\warning The coordinates of the bottom-left corner must be no more 303 ///than those of the top-right one 301 ///Construct an instance from four numbers. 302 ///\param l The left side of the box. 303 ///\param b The bottom of the box. 304 ///\param r The right side of the box. 305 ///\param t The top of the box. 306 ///\warning The left side must be no more than the right side and 307 ///bottom must be no more than the top. 304 308 BoundingBox(T l,T b,T r,T t) 305 309 { … … 309 313 } 310 314 311 ///Were any points added? 315 ///Return \c true if the bounding box is empty. 316 317 ///Return \c true if the bounding box is empty (i.e. return \c false 318 ///if at least one point was added to the box or the coordinates of 319 ///the box were set). 320 /// 321 ///The coordinates of an empty bounding box are not defined. 312 322 bool empty() const { 313 323 return _empty; … … 319 329 } 320 330 321 ///Give back the bottom left corner 322 323 ///Give back the bottom left corner .331 ///Give back the bottom left corner of the box 332 333 ///Give back the bottom left corner of the box. 324 334 ///If the bounding box is empty, then the return value is not defined. 325 335 Point<T> bottomLeft() const { … … 327 337 } 328 338 329 ///Set the bottom left corner 330 331 ///Set the bottom left corner .332 ///It should only be eused for non-empty box.339 ///Set the bottom left corner of the box 340 341 ///Set the bottom left corner of the box. 342 ///It should only be used for non-empty box. 333 343 void bottomLeft(Point<T> p) { 334 344 bottom_left = p; 335 345 } 336 346 337 ///Give back the top right corner 338 339 ///Give back the top right corner .347 ///Give back the top right corner of the box 348 349 ///Give back the top right corner of the box. 340 350 ///If the bounding box is empty, then the return value is not defined. 341 351 Point<T> topRight() const { … … 343 353 } 344 354 345 ///Set the top right corner 346 347 ///Set the top right corner .348 ///It should only be eused for non-empty box.355 ///Set the top right corner of the box 356 357 ///Set the top right corner of the box. 358 ///It should only be used for non-empty box. 349 359 void topRight(Point<T> p) { 350 360 top_right = p; 351 361 } 352 362 353 ///Give back the bottom right corner 354 355 ///Give back the bottom right corner .363 ///Give back the bottom right corner of the box 364 365 ///Give back the bottom right corner of the box. 356 366 ///If the bounding box is empty, then the return value is not defined. 357 367 Point<T> bottomRight() const { … … 359 369 } 360 370 361 ///Set the bottom right corner 362 363 ///Set the bottom right corner .364 ///It should only be eused for non-empty box.371 ///Set the bottom right corner of the box 372 373 ///Set the bottom right corner of the box. 374 ///It should only be used for non-empty box. 365 375 void bottomRight(Point<T> p) { 366 376 top_right.x = p.x; … … 368 378 } 369 379 370 ///Give back the top left corner 371 372 ///Give back the top left corner .380 ///Give back the top left corner of the box 381 382 ///Give back the top left corner of the box. 373 383 ///If the bounding box is empty, then the return value is not defined. 374 384 Point<T> topLeft() const { … … 376 386 } 377 387 378 ///Set the top left corner 379 380 ///Set the top left corner .381 ///It should only be eused for non-empty box.388 ///Set the top left corner of the box 389 390 ///Set the top left corner of the box. 391 ///It should only be used for non-empty box. 382 392 void topLeft(Point<T> p) { 383 393 top_right.y = p.y; … … 396 406 397 407 ///Set the bottom of the box. 398 ///It should only be eused for non-empty box.408 ///It should only be used for non-empty box. 399 409 void bottom(T t) { 400 410 bottom_left.y = t; … … 412 422 413 423 ///Set the top of the box. 414 ///It should only be eused for non-empty box.424 ///It should only be used for non-empty box. 415 425 void top(T t) { 416 426 top_right.y = t; … … 428 438 429 439 ///Set the left side of the box. 430 ///It should only be e used for non-empty box440 ///It should only be used for non-empty box. 431 441 void left(T t) { 432 442 bottom_left.x = t; … … 444 454 445 455 ///Set the right side of the box. 446 ///It should only be e used for non-empty box456 ///It should only be used for non-empty box. 447 457 void right(T t) { 448 458 top_right.x = t; … … 466 476 467 477 ///Checks whether a point is inside a bounding box 468 bool inside(const Point<T>& u) {478 bool inside(const Point<T>& u) const { 469 479 if (_empty) 470 480 return false; … … 476 486 477 487 ///Increments a bounding box with a point 488 489 ///Increments a bounding box with a point. 490 /// 478 491 BoundingBox& add(const Point<T>& u){ 479 492 if (_empty){ … … 490 503 } 491 504 492 ///Increments a bounding to contain another bounding box 505 ///Increments a bounding box to contain another bounding box 506 507 ///Increments a bounding box to contain another bounding box. 508 /// 493 509 BoundingBox& add(const BoundingBox &u){ 494 510 if ( !u.empty() ){ … … 500 516 501 517 ///Intersection of two bounding boxes 502 BoundingBox operator &(const BoundingBox& u){ 518 519 ///Intersection of two bounding boxes. 520 /// 521 BoundingBox operator&(const BoundingBox& u) const { 503 522 BoundingBox b; 504 b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x); 505 b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y); 506 b.top_right.x=std::min(this->top_right.x,u.top_right.x); 507 b.top_right.y=std::min(this->top_right.y,u.top_right.y); 508 b._empty = this->_empty || u._empty || 509 b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y; 523 if (this->_empty || u._empty) { 524 b._empty = true; 525 } else { 526 b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x); 527 b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y); 528 b.top_right.x=std::min(this->top_right.x,u.top_right.x); 529 b.top_right.y=std::min(this->top_right.y,u.top_right.y); 530 b._empty = b.bottom_left.x > b.top_right.x || 531 b.bottom_left.y > b.top_right.y; 532 } 510 533 return b; 511 534 } … … 514 537 515 538 516 ///Map of x-coordinates of a dim2::Point<>-map517 518 ///\ingroup maps 519 ///Map of x-coordinates of a dim2::Point<>-map539 ///Map of x-coordinates of a \ref Point "Point"-map 540 541 ///\ingroup maps 542 ///Map of x-coordinates of a \ref Point "Point"-map. 520 543 /// 521 544 template<class M> … … 571 594 ///Returns a \ref ConstXMap class 572 595 573 ///This function just returns a n\ref ConstXMap class.596 ///This function just returns a \ref ConstXMap class. 574 597 /// 575 598 ///\ingroup maps … … 581 604 } 582 605 583 ///Map of y-coordinates of a dim2::Point<>-map606 ///Map of y-coordinates of a \ref Point "Point"-map 584 607 585 608 ///\ingroup maps 586 ///Map of y-coordinates of a dim2::Point<>-map609 ///Map of y-coordinates of a \ref Point "Point"-map. 587 610 /// 588 611 template<class M> … … 600 623 }; 601 624 602 ///Returns a n\ref YMap class603 604 ///This function just returns a n\ref YMap class.625 ///Returns a \ref YMap class 626 627 ///This function just returns a \ref YMap class. 605 628 /// 606 629 ///\ingroup maps … … 638 661 ///Returns a \ref ConstYMap class 639 662 640 ///This function just returns a n\ref ConstYMap class.663 ///This function just returns a \ref ConstYMap class. 641 664 /// 642 665 ///\ingroup maps … … 649 672 650 673 651 652 ///of an\ref Point "Point"-map653 654 655 ///of an \ref Point "Point"-map656 674 ///\brief Map of the \ref Point::normSquare() "normSquare()" 675 ///of a \ref Point "Point"-map 676 /// 677 ///Map of the \ref Point::normSquare() "normSquare()" 678 ///of a \ref Point "Point"-map. 679 ///\ingroup maps 657 680 /// 658 681 template<class M> … … 671 694 ///Returns a \ref NormSquareMap class 672 695 673 ///This function just returns a n\ref NormSquareMap class.696 ///This function just returns a \ref NormSquareMap class. 674 697 /// 675 698 ///\ingroup maps
Note: See TracChangeset
for help on using the changeset viewer.