Changeset 253:dbe309b5e855 in lemon
 Timestamp:
 08/30/08 22:19:43 (12 years ago)
 Branch:
 default
 Phase:
 public
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

lemon/dim2.h
r250 r253 29 29 /// a two dimensional vector with the usual operations. 30 30 /// 31 /// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox" 32 /// can be used to determine 31 /// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine 33 32 /// the rectangular bounding box of a set of 34 33 /// \ref lemon::dim2::Point "dim2::Point"'s. … … 45 44 /// @{ 46 45 47 /// A simple two dimensional vector (plain vector) implementation46 /// Two dimensional vector (plain vector) 48 47 49 48 /// A simple two dimensional vector (plain vector) implementation … … 261 260 262 261 263 /// A class to calculate or store the bounding box of plain vectors.264 265 /// A class to calculate or store the bounding box of plain vectors.266 ///267 268 class BoundingBox {262 /// Bounding box of plain vectors (\ref Point points). 263 264 /// A class to calculate or store the bounding box of plain vectors 265 /// (\ref Point points). 266 template<typename T> 267 class Box { 269 268 Point<T> _bottom_left, _top_right; 270 269 bool _empty; 271 270 public: 272 271 273 ///Default constructor: creates an empty bo unding box274 Bo undingBox() { _empty = true; }275 276 ///Construct a n instancefrom one point277 Bo undingBox(Point<T> a) {272 ///Default constructor: creates an empty box 273 Box() { _empty = true; } 274 275 ///Construct a box from one point 276 Box(Point<T> a) { 278 277 _bottom_left = _top_right = a; 279 278 _empty = false; 280 279 } 281 280 282 ///Construct a n instancefrom two points283 284 ///Construct a n instancefrom two points.281 ///Construct a box from two points 282 283 ///Construct a box from two points. 285 284 ///\param a The bottom left corner. 286 285 ///\param b The top right corner. 287 286 ///\warning The coordinates of the bottom left corner must be no more 288 287 ///than those of the top right one. 289 Bo undingBox(Point<T> a,Point<T> b)288 Box(Point<T> a,Point<T> b) 290 289 { 291 290 _bottom_left = a; … … 294 293 } 295 294 296 ///Construct a n instancefrom four numbers297 298 ///Construct a n instancefrom four numbers.295 ///Construct a box from four numbers 296 297 ///Construct a box from four numbers. 299 298 ///\param l The left side of the box. 300 299 ///\param b The bottom of the box. … … 303 302 ///\warning The left side must be no more than the right side and 304 303 ///bottom must be no more than the top. 305 Bo undingBox(T l,T b,T r,T t)304 Box(T l,T b,T r,T t) 306 305 { 307 306 _bottom_left=Point<T>(l,b); … … 310 309 } 311 310 312 ///Return \c true if the bo unding box is empty.313 314 ///Return \c true if the bo unding box is empty (i.e. return \c false311 ///Return \c true if the box is empty. 312 313 ///Return \c true if the box is empty (i.e. return \c false 315 314 ///if at least one point was added to the box or the coordinates of 316 315 ///the box were set). 317 316 /// 318 ///The coordinates of an empty bo unding box are not defined.317 ///The coordinates of an empty box are not defined. 319 318 bool empty() const { 320 319 return _empty; 321 320 } 322 321 323 ///Make the BoundingBox empty322 ///Make the box empty 324 323 void clear() { 325 324 _empty = true; … … 329 328 330 329 ///Give back the bottom left corner of the box. 331 ///If the bo unding box is empty, then the return value is not defined.330 ///If the box is empty, then the return value is not defined. 332 331 Point<T> bottomLeft() const { 333 332 return _bottom_left; … … 345 344 346 345 ///Give back the top right corner of the box. 347 ///If the bo unding box is empty, then the return value is not defined.346 ///If the box is empty, then the return value is not defined. 348 347 Point<T> topRight() const { 349 348 return _top_right; … … 361 360 362 361 ///Give back the bottom right corner of the box. 363 ///If the bo unding box is empty, then the return value is not defined.362 ///If the box is empty, then the return value is not defined. 364 363 Point<T> bottomRight() const { 365 364 return Point<T>(_top_right.x,_bottom_left.y); … … 378 377 379 378 ///Give back the top left corner of the box. 380 ///If the bo unding box is empty, then the return value is not defined.379 ///If the box is empty, then the return value is not defined. 381 380 Point<T> topLeft() const { 382 381 return Point<T>(_bottom_left.x,_top_right.y); … … 395 394 396 395 ///Give back the bottom of the box. 397 ///If the bo unding box is empty, then the return value is not defined.396 ///If the box is empty, then the return value is not defined. 398 397 T bottom() const { 399 398 return _bottom_left.y; … … 411 410 412 411 ///Give back the top of the box. 413 ///If the bo unding box is empty, then the return value is not defined.412 ///If the box is empty, then the return value is not defined. 414 413 T top() const { 415 414 return _top_right.y; … … 427 426 428 427 ///Give back the left side of the box. 429 ///If the bo unding box is empty, then the return value is not defined.428 ///If the box is empty, then the return value is not defined. 430 429 T left() const { 431 430 return _bottom_left.x; … … 443 442 444 443 /// Give back the right side of the box. 445 ///If the bo unding box is empty, then the return value is not defined.444 ///If the box is empty, then the return value is not defined. 446 445 T right() const { 447 446 return _top_right.x; … … 459 458 460 459 ///Give back the height of the box. 461 ///If the bo unding box is empty, then the return value is not defined.460 ///If the box is empty, then the return value is not defined. 462 461 T height() const { 463 462 return _top_right.y_bottom_left.y; … … 467 466 468 467 ///Give back the width of the box. 469 ///If the bo unding box is empty, then the return value is not defined.468 ///If the box is empty, then the return value is not defined. 470 469 T width() const { 471 470 return _top_right.x_bottom_left.x; 472 471 } 473 472 474 ///Checks whether a point is inside a boundingbox473 ///Checks whether a point is inside the box 475 474 bool inside(const Point<T>& u) const { 476 475 if (_empty) … … 482 481 } 483 482 484 ///Increments a boundingbox with a point485 486 ///Increments a boundingbox with a point.483 ///Increments the box with a point 484 485 ///Increments the box with a point. 487 486 /// 488 Bo undingBox& add(const Point<T>& u){487 Box& add(const Point<T>& u){ 489 488 if (_empty) { 490 489 _bottom_left = _top_right = u; … … 500 499 } 501 500 502 ///Increments a bounding box to contain another boundingbox503 504 ///Increments a bounding box to contain another boundingbox.501 ///Increments the box to contain another box 502 503 ///Increments the box to contain another box. 505 504 /// 506 Bo undingBox& add(const BoundingBox &u){505 Box& add(const Box &u){ 507 506 if ( !u.empty() ){ 508 507 add(u._bottom_left); … … 512 511 } 513 512 514 ///Intersection of two bo unding boxes515 516 ///Intersection of two bo unding boxes.513 ///Intersection of two boxes 514 515 ///Intersection of two boxes. 517 516 /// 518 Bo undingBox operator&(const BoundingBox& u) const {519 Bo undingBox b;517 Box operator&(const Box& u) const { 518 Box b; 520 519 if (_empty  u._empty) { 521 520 b._empty = true; … … 531 530 } 532 531 533 };//class Boundingbox534 535 536 ///Read a bo unding box from a stream537 538 ///Read a bo unding box from a stream.539 ///\relates Bo undingBox540 template<typename T> 541 inline std::istream& operator>>(std::istream &is, Bo undingBox<T>& b) {532 };//class Box 533 534 535 ///Read a box from a stream 536 537 ///Read a box from a stream. 538 ///\relates Box 539 template<typename T> 540 inline std::istream& operator>>(std::istream &is, Box<T>& b) { 542 541 char c; 543 542 Point<T> p; … … 564 563 } 565 564 566 ///Write a bo unding box to a stream567 568 ///Write a bo unding box to a stream.569 ///\relates Bo undingBox570 template<typename T> 571 inline std::ostream& operator<<(std::ostream &os, const Bo undingBox<T>& b)565 ///Write a box to a stream 566 567 ///Write a box to a stream. 568 ///\relates Box 569 template<typename T> 570 inline std::ostream& operator<<(std::ostream &os, const Box<T>& b) 572 571 { 573 572 os << "(" << b.bottomLeft() << "," << b.topRight() << ")"; 
lemon/graph_to_eps.h
r220 r253 726 726 double diag_len = 1; 727 727 if(!(_absoluteNodeSizes&&_absoluteArcWidths)) { 728 dim2::Bo undingBox<double> bb;728 dim2::Box<double> bb; 729 729 for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]); 730 730 if (bb.empty()) { 731 bb = dim2::Bo undingBox<double>(dim2::Point<double>(0,0));731 bb = dim2::Box<double>(dim2::Point<double>(0,0)); 732 732 } 733 733 diag_len = std::sqrt((bb.bottomLeft()bb.topRight()).normSquare()); … … 737 737 } 738 738 739 dim2::Bo undingBox<double> bb;739 dim2::Box<double> bb; 740 740 for(NodeIt n(g);n!=INVALID;++n) { 741 741 double ns=_nodeSizes[n]*_nodeScale; … … 759 759 } 760 760 if (bb.empty()) { 761 bb = dim2::Bo undingBox<double>(dim2::Point<double>(0,0));761 bb = dim2::Box<double>(dim2::Point<double>(0,0)); 762 762 } 763 763 
test/dim_test.cc
r242 r253 51 51 check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); 52 52 53 typedef dim2::Bo undingBox<int> BB;54 B Bbox1;55 check(box1.empty(), "Wrong empty() in dim2::Bo undingBox.");53 typedef dim2::Box<int> Box; 54 Box box1; 55 check(box1.empty(), "Wrong empty() in dim2::Box."); 56 56 57 57 box1.add(a); 58 check(!box1.empty(), "Wrong empty() in dim2::Bo undingBox.");58 check(!box1.empty(), "Wrong empty() in dim2::Box."); 59 59 box1.add(b); 60 60 61 61 check(box1.left()==1 && box1.bottom()==2 && 62 62 box1.right()==3 && box1.top()==4, 63 "Wrong addition of points to dim2::Bo undingBox.");63 "Wrong addition of points to dim2::Box."); 64 64 65 check(box1.inside(Point(2,3)), "Wrong inside() in dim2::Bo undingBox.");66 check(box1.inside(Point(1,3)), "Wrong inside() in dim2::Bo undingBox.");67 check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::Bo undingBox.");65 check(box1.inside(Point(2,3)), "Wrong inside() in dim2::Box."); 66 check(box1.inside(Point(1,3)), "Wrong inside() in dim2::Box."); 67 check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::Box."); 68 68 69 B Bbox2(Point(2,2));70 check(!box2.empty(), "Wrong empty() in dim2::Bo undingBox.");71 69 Box box2(Point(2,2)); 70 check(!box2.empty(), "Wrong empty() in dim2::Box."); 71 72 72 box2.bottomLeft(Point(2,0)); 73 73 box2.topRight(Point(5,3)); 74 B Bbox3 = box1 & box2;74 Box box3 = box1 & box2; 75 75 check(!box3.empty() && 76 box3.left()==2 && box3.bottom()==2 && 76 box3.left()==2 && box3.bottom()==2 && 77 77 box3.right()==3 && box3.top()==3, 78 "Wrong intersection of two dim2::Bo undingBox objects.");79 78 "Wrong intersection of two dim2::Box objects."); 79 80 80 box1.add(box2); 81 81 check(!box1.empty() && 82 82 box1.left()==1 && box1.bottom()==0 && 83 83 box1.right()==5 && box1.top()==4, 84 "Wrong addition of two dim2::Bo undingBox objects.");84 "Wrong addition of two dim2::Box objects."); 85 85 86 86 return 0;
Note: See TracChangeset
for help on using the changeset viewer.