Rev 650 | Rev 656 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 650 | Rev 651 | ||
---|---|---|---|
Line 411... | Line 411... | ||
411 | ////////////////////////////////////////////////////////////
|
411 | ////////////////////////////////////////////////////////////
|
412 | template <class T> |
412 | template <class T> |
413 | void GridRunner<T>::setup(const Grid<T> *target_grid, const QRect &rectangle) |
413 | void GridRunner<T>::setup(const Grid<T> *target_grid, const QRect &rectangle) |
414 | {
|
414 | {
|
415 | QPoint upper_left = rectangle.topLeft(); |
415 | QPoint upper_left = rectangle.topLeft(); |
- | 416 | // due to the strange behavior of QRect::bottom() and right():
|
|
416 | QPoint lower_right = rectangle.bottomRight(); |
417 | QPoint lower_right = rectangle.bottomRight(); |
417 | mCurrent = const_cast<Grid<T> *>(target_grid)->ptr(upper_left.x(), upper_left.y()); |
418 | mCurrent = const_cast<Grid<T> *>(target_grid)->ptr(upper_left.x(), upper_left.y()); |
418 | mFirst = mCurrent; |
419 | mFirst = mCurrent; |
419 | mCurrent--; // point to first element -1 |
420 | mCurrent--; // point to first element -1 |
420 | mLast = const_cast<Grid<T> *>(target_grid)->ptr(lower_right.x()-1, lower_right.y()-1); |
421 | mLast = const_cast<Grid<T> *>(target_grid)->ptr(lower_right.x()-1, lower_right.y()-1); |
Line 454... | Line 455... | ||
454 | 455 | ||
455 | template <class T> |
456 | template <class T> |
456 | void GridRunner<T>::neighbors4(T** rArray) |
457 | void GridRunner<T>::neighbors4(T** rArray) |
457 | {
|
458 | {
|
458 | // north:
|
459 | // north:
|
459 | rArray[0] = mCurrent + mCols > mLast?0: mCurrent + mCols; |
- | |
- | 460 | rArray[0] = mCurrent + mCols + mLineLength > mLast?0: mCurrent + mCols + mLineLength; |
|
460 | // south:
|
461 | // south:
|
461 | rArray[3] = mCurrent - mCols < mFirst?0: mCurrent - mCols; |
- | |
- | 462 | rArray[3] = mCurrent - (mCols + mLineLength) < mFirst?0: mCurrent - (mCols + mLineLength); |
|
462 | // east / west
|
463 | // east / west
|
463 | rArray[1] = mCurrentCol>0? mCurrent-1 : 0; |
464 | rArray[1] = mCurrentCol>0? mCurrent-1 : 0; |
464 | rArray[2] = mCurrentCol<mCols? mCurrent + 1 : 0; |
465 | rArray[2] = mCurrentCol<mCols? mCurrent + 1 : 0; |
465 | }
|
466 | }
|
466 | 467 |