| ... | ... |
@@ -488,96 +488,137 @@ |
| 488 | 488 |
BoundingBox& add(const Point<T>& u){
|
| 489 | 489 |
if (_empty) {
|
| 490 | 490 |
_bottom_left = _top_right = u; |
| 491 | 491 |
_empty = false; |
| 492 | 492 |
} |
| 493 | 493 |
else {
|
| 494 | 494 |
if (_bottom_left.x > u.x) _bottom_left.x = u.x; |
| 495 | 495 |
if (_bottom_left.y > u.y) _bottom_left.y = u.y; |
| 496 | 496 |
if (_top_right.x < u.x) _top_right.x = u.x; |
| 497 | 497 |
if (_top_right.y < u.y) _top_right.y = u.y; |
| 498 | 498 |
} |
| 499 | 499 |
return *this; |
| 500 | 500 |
} |
| 501 | 501 |
|
| 502 | 502 |
///Increments a bounding box to contain another bounding box |
| 503 | 503 |
|
| 504 | 504 |
///Increments a bounding box to contain another bounding box. |
| 505 | 505 |
/// |
| 506 | 506 |
BoundingBox& add(const BoundingBox &u){
|
| 507 | 507 |
if ( !u.empty() ){
|
| 508 | 508 |
add(u._bottom_left); |
| 509 | 509 |
add(u._top_right); |
| 510 | 510 |
} |
| 511 | 511 |
return *this; |
| 512 | 512 |
} |
| 513 | 513 |
|
| 514 | 514 |
///Intersection of two bounding boxes |
| 515 | 515 |
|
| 516 | 516 |
///Intersection of two bounding boxes. |
| 517 | 517 |
/// |
| 518 | 518 |
BoundingBox operator&(const BoundingBox& u) const {
|
| 519 | 519 |
BoundingBox b; |
| 520 | 520 |
if (_empty || u._empty) {
|
| 521 | 521 |
b._empty = true; |
| 522 | 522 |
} else {
|
| 523 | 523 |
b._bottom_left.x = std::max(_bottom_left.x, u._bottom_left.x); |
| 524 | 524 |
b._bottom_left.y = std::max(_bottom_left.y, u._bottom_left.y); |
| 525 | 525 |
b._top_right.x = std::min(_top_right.x, u._top_right.x); |
| 526 | 526 |
b._top_right.y = std::min(_top_right.y, u._top_right.y); |
| 527 | 527 |
b._empty = b._bottom_left.x > b._top_right.x || |
| 528 | 528 |
b._bottom_left.y > b._top_right.y; |
| 529 | 529 |
} |
| 530 | 530 |
return b; |
| 531 | 531 |
} |
| 532 | 532 |
|
| 533 | 533 |
};//class Boundingbox |
| 534 | 534 |
|
| 535 | 535 |
|
| 536 |
///Read a bounding box from a stream |
|
| 537 |
|
|
| 538 |
///Read a bounding box from a stream. |
|
| 539 |
///\relates BoundingBox |
|
| 540 |
template<typename T> |
|
| 541 |
inline std::istream& operator>>(std::istream &is, BoundingBox<T>& b) {
|
|
| 542 |
char c; |
|
| 543 |
Point<T> p; |
|
| 544 |
if (is >> c) {
|
|
| 545 |
if (c != '(') is.putback(c);
|
|
| 546 |
} else {
|
|
| 547 |
is.clear(); |
|
| 548 |
} |
|
| 549 |
if (!(is >> p)) return is; |
|
| 550 |
b.bottomLeft(p); |
|
| 551 |
if (is >> c) {
|
|
| 552 |
if (c != ',') is.putback(c); |
|
| 553 |
} else {
|
|
| 554 |
is.clear(); |
|
| 555 |
} |
|
| 556 |
if (!(is >> p)) return is; |
|
| 557 |
b.topRight(p); |
|
| 558 |
if (is >> c) {
|
|
| 559 |
if (c != ')') is.putback(c); |
|
| 560 |
} else {
|
|
| 561 |
is.clear(); |
|
| 562 |
} |
|
| 563 |
return is; |
|
| 564 |
} |
|
| 565 |
|
|
| 566 |
///Write a bounding box to a stream |
|
| 567 |
|
|
| 568 |
///Write a bounding box to a stream. |
|
| 569 |
///\relates BoundingBox |
|
| 570 |
template<typename T> |
|
| 571 |
inline std::ostream& operator<<(std::ostream &os, const BoundingBox<T>& b) |
|
| 572 |
{
|
|
| 573 |
os << "(" << b.bottomLeft() << "," << b.topRight() << ")";
|
|
| 574 |
return os; |
|
| 575 |
} |
|
| 576 |
|
|
| 536 | 577 |
///Map of x-coordinates of a \ref Point "Point"-map |
| 537 | 578 |
|
| 538 | 579 |
///\ingroup maps |
| 539 | 580 |
///Map of x-coordinates of a \ref Point "Point"-map. |
| 540 | 581 |
/// |
| 541 | 582 |
template<class M> |
| 542 | 583 |
class XMap |
| 543 | 584 |
{
|
| 544 | 585 |
M& _map; |
| 545 | 586 |
public: |
| 546 | 587 |
|
| 547 | 588 |
typedef typename M::Value::Value Value; |
| 548 | 589 |
typedef typename M::Key Key; |
| 549 | 590 |
///\e |
| 550 | 591 |
XMap(M& map) : _map(map) {}
|
| 551 | 592 |
Value operator[](Key k) const {return _map[k].x;}
|
| 552 | 593 |
void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
|
| 553 | 594 |
}; |
| 554 | 595 |
|
| 555 | 596 |
///Returns an \ref XMap class |
| 556 | 597 |
|
| 557 | 598 |
///This function just returns an \ref XMap class. |
| 558 | 599 |
/// |
| 559 | 600 |
///\ingroup maps |
| 560 | 601 |
///\relates XMap |
| 561 | 602 |
template<class M> |
| 562 | 603 |
inline XMap<M> xMap(M &m) |
| 563 | 604 |
{
|
| 564 | 605 |
return XMap<M>(m); |
| 565 | 606 |
} |
| 566 | 607 |
|
| 567 | 608 |
template<class M> |
| 568 | 609 |
inline XMap<M> xMap(const M &m) |
| 569 | 610 |
{
|
| 570 | 611 |
return XMap<M>(m); |
| 571 | 612 |
} |
| 572 | 613 |
|
| 573 | 614 |
///Constant (read only) version of \ref XMap |
| 574 | 615 |
|
| 575 | 616 |
///\ingroup maps |
| 576 | 617 |
///Constant (read only) version of \ref XMap |
| 577 | 618 |
/// |
| 578 | 619 |
template<class M> |
| 579 | 620 |
class ConstXMap |
| 580 | 621 |
{
|
| 581 | 622 |
const M& _map; |
| 582 | 623 |
public: |
| 583 | 624 |
|
0 comments (0 inline)