gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Improvements in dim2::BoundingBox (ticket #126) - Rename the private varibles to start with underscore. - Doc improvements.
0 1 0
default
1 file changed with 54 insertions and 52 deletions:
↑ Collapse diff ↑
Show white space 2 line context
... ...
@@ -22,3 +22,2 @@
22 22
#include <iostream>
23
#include <lemon/core.h>
24 23

	
... ...
@@ -269,3 +268,3 @@
269 268
    class BoundingBox {
270
      Point<T> bottom_left, top_right;
269
      Point<T> _bottom_left, _top_right;
271 270
      bool _empty;
... ...
@@ -277,3 +276,6 @@
277 276
      ///Construct an instance from one point
278
      BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; }
277
      BoundingBox(Point<T> a) {
278
        _bottom_left = _top_right = a;
279
        _empty = false;
280
      }
279 281

	
... ...
@@ -288,4 +290,4 @@
288 290
      {
289
        bottom_left=a;
290
        top_right=b;
291
        _bottom_left = a;
292
        _top_right = b;
291 293
        _empty = false;
... ...
@@ -304,4 +306,4 @@
304 306
      {
305
        bottom_left=Point<T>(l,b);
306
        top_right=Point<T>(r,t);
307
        _bottom_left=Point<T>(l,b);
308
        _top_right=Point<T>(r,t);
307 309
        _empty = false;
... ...
@@ -322,3 +324,3 @@
322 324
      void clear() {
323
        _empty=1;
325
        _empty = true;
324 326
      }
... ...
@@ -330,3 +332,3 @@
330 332
      Point<T> bottomLeft() const {
331
        return bottom_left;
333
        return _bottom_left;
332 334
      }
... ...
@@ -336,5 +338,5 @@
336 338
      ///Set the bottom left corner of the box.
337
      ///It should only be used for non-empty box.
339
      ///\pre The box must not be empty.
338 340
      void bottomLeft(Point<T> p) {
339
        bottom_left = p;
341
        _bottom_left = p;
340 342
      }
... ...
@@ -346,3 +348,3 @@
346 348
      Point<T> topRight() const {
347
        return top_right;
349
        return _top_right;
348 350
      }
... ...
@@ -352,5 +354,5 @@
352 354
      ///Set the top right corner of the box.
353
      ///It should only be used for non-empty box.
355
      ///\pre The box must not be empty.
354 356
      void topRight(Point<T> p) {
355
        top_right = p;
357
        _top_right = p;
356 358
      }
... ...
@@ -362,3 +364,3 @@
362 364
      Point<T> bottomRight() const {
363
        return Point<T>(top_right.x,bottom_left.y);
365
        return Point<T>(_top_right.x,_bottom_left.y);
364 366
      }
... ...
@@ -368,6 +370,6 @@
368 370
      ///Set the bottom right corner of the box.
369
      ///It should only be used for non-empty box.
371
      ///\pre The box must not be empty.
370 372
      void bottomRight(Point<T> p) {
371
        top_right.x = p.x;
372
        bottom_left.y = p.y;
373
        _top_right.x = p.x;
374
        _bottom_left.y = p.y;
373 375
      }
... ...
@@ -379,3 +381,3 @@
379 381
      Point<T> topLeft() const {
380
        return Point<T>(bottom_left.x,top_right.y);
382
        return Point<T>(_bottom_left.x,_top_right.y);
381 383
      }
... ...
@@ -385,6 +387,6 @@
385 387
      ///Set the top left corner of the box.
386
      ///It should only be used for non-empty box.
388
      ///\pre The box must not be empty.
387 389
      void topLeft(Point<T> p) {
388
        top_right.y = p.y;
389
        bottom_left.x = p.x;
390
        _top_right.y = p.y;
391
        _bottom_left.x = p.x;
390 392
      }
... ...
@@ -396,3 +398,3 @@
396 398
      T bottom() const {
397
        return bottom_left.y;
399
        return _bottom_left.y;
398 400
      }
... ...
@@ -402,5 +404,5 @@
402 404
      ///Set the bottom of the box.
403
      ///It should only be used for non-empty box.
405
      ///\pre The box must not be empty.
404 406
      void bottom(T t) {
405
        bottom_left.y = t;
407
        _bottom_left.y = t;
406 408
      }
... ...
@@ -412,3 +414,3 @@
412 414
      T top() const {
413
        return top_right.y;
415
        return _top_right.y;
414 416
      }
... ...
@@ -418,5 +420,5 @@
418 420
      ///Set the top of the box.
419
      ///It should only be used for non-empty box.
421
      ///\pre The box must not be empty.
420 422
      void top(T t) {
421
        top_right.y = t;
423
        _top_right.y = t;
422 424
      }
... ...
@@ -428,3 +430,3 @@
428 430
      T left() const {
429
        return bottom_left.x;
431
        return _bottom_left.x;
430 432
      }
... ...
@@ -434,5 +436,5 @@
434 436
      ///Set the left side of the box.
435
      ///It should only be used for non-empty box.
437
      ///\pre The box must not be empty.
436 438
      void left(T t) {
437
        bottom_left.x = t;
439
        _bottom_left.x = t;
438 440
      }
... ...
@@ -444,3 +446,3 @@
444 446
      T right() const {
445
        return top_right.x;
447
        return _top_right.x;
446 448
      }
... ...
@@ -450,5 +452,5 @@
450 452
      ///Set the right side of the box.
451
      ///It should only be used for non-empty box.
453
      ///\pre The box must not be empty.
452 454
      void right(T t) {
453
        top_right.x = t;
455
        _top_right.x = t;
454 456
      }
... ...
@@ -460,3 +462,3 @@
460 462
      T height() const {
461
        return top_right.y-bottom_left.y;
463
        return _top_right.y-_bottom_left.y;
462 464
      }
... ...
@@ -468,3 +470,3 @@
468 470
      T width() const {
469
        return top_right.x-bottom_left.x;
471
        return _top_right.x-_bottom_left.x;
470 472
      }
... ...
@@ -476,4 +478,4 @@
476 478
        else{
477
          return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
478
              (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
479
          return ( (u.x-_bottom_left.x)*(_top_right.x-u.x) >= 0 &&
480
                   (u.y-_bottom_left.y)*(_top_right.y-u.y) >= 0 );
479 481
        }
... ...
@@ -487,3 +489,3 @@
487 489
        if (_empty){
488
          bottom_left=top_right=u;
490
          _bottom_left = _top_right = u;
489 491
          _empty = false;
... ...
@@ -491,6 +493,6 @@
491 493
        else{
492
          if (bottom_left.x > u.x) bottom_left.x = u.x;
493
          if (bottom_left.y > u.y) bottom_left.y = u.y;
494
          if (top_right.x < u.x) top_right.x = u.x;
495
          if (top_right.y < u.y) top_right.y = u.y;
494
          if (_bottom_left.x > u.x) _bottom_left.x = u.x;
495
          if (_bottom_left.y > u.y) _bottom_left.y = u.y;
496
          if (_top_right.x < u.x) _top_right.x = u.x;
497
          if (_top_right.y < u.y) _top_right.y = u.y;
496 498
        }
... ...
@@ -505,4 +507,4 @@
505 507
        if ( !u.empty() ){
506
          this->add(u.bottomLeft());
507
          this->add(u.topRight());
508
          add(u._bottom_left);
509
          add(u._top_right);
508 510
        }
... ...
@@ -517,11 +519,11 @@
517 519
        BoundingBox b;
518
        if (this->_empty || u._empty) {
520
        if (_empty || u._empty) {
519 521
          b._empty = true;
520 522
        } else {
521
          b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x);
522
          b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y);
523
          b.top_right.x = std::min(this->top_right.x,u.top_right.x);
524
          b.top_right.y = std::min(this->top_right.y,u.top_right.y);
525
          b._empty = b.bottom_left.x > b.top_right.x ||
526
                     b.bottom_left.y > b.top_right.y;
523
          b._bottom_left.x = std::max(_bottom_left.x, u._bottom_left.x);
524
          b._bottom_left.y = std::max(_bottom_left.y, u._bottom_left.y);
525
          b._top_right.x = std::min(_top_right.x, u._top_right.x);
526
          b._top_right.y = std::min(_top_right.y, u._top_right.y);
527
          b._empty = b._bottom_left.x > b._top_right.x ||
528
                     b._bottom_left.y > b._top_right.y;
527 529
        }
0 comments (0 inline)