Advertisement
zamotivator

Untitled

Jun 10th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. inline position_t coord2position(Coordinates const& coord) const
  2. {
  3. assert(maped());
  4. assert(insideOverlap(coord));
  5. position_t position = 0;
  6. /* stride-major-order */
  7. for (size_t i = 0; i < n(); ++i) {
  8. position *= m_sizeOverlap[i];
  9. position += coord[i] - lowerOverlap()[i];
  10. }
  11. assert(position < m_positionCount);
  12. /*
  13. Temporary commented:
  14. (need another implementation of "aligned(Coordinates const&)".
  15. */
  16. /* assert(aligned(coord) == aligned(position)); */
  17. return position;
  18. }
  19.  
  20. inline Coordinates position2coord(position_t const &position) const
  21. {
  22. assert(maped());
  23. assert(position < m_positionCount);
  24. Coordinates coord;
  25. coord.resize(n());
  26. position_t remainder= position;
  27. /* stride-major-order */
  28. for (Size i = n(); i > 0; --i) {
  29. Size const k = i - 1;
  30. coord[k] = lowerOverlap()[k] + (remainder % m_sizeOverlap[k]);
  31. remainder /= m_sizeOverlap[k];
  32. }
  33. assert(insideOverlap(coord));
  34. assert(aligned(coord) == aligned(position));
  35. return coord;
  36. }
  37. inline bool aligned(position_t const& actual) const
  38. {
  39. assert(maped());
  40. assert(actual < m_positionCount);
  41. if (isTiled()) {
  42. return actual % tileSize() == 0;
  43. } else {
  44. return true;
  45. }
  46. }
  47. inline bool move(Coordinates& coord,
  48. position_t step,
  49. position_t& left) const
  50. {
  51. assert(maped());
  52. assert(insideOverlap(coord));
  53. assert(step > 0);
  54. if (!isTiled() && step == 1) {
  55. size_t i = n() - 1;
  56. while(++coord[i] >= upper()[i]) {
  57. if (i == 0) {
  58. return false;
  59. }
  60. coord[i] = lower()[i];
  61. i -= 1;
  62. }
  63. left = 1;
  64. return true;
  65. } else {
  66. position_t position = coord2position(coord);
  67. position += step;
  68. bool result = position < m_positionCount;
  69. if (result) {
  70. left = tileSize() -
  71. (position % tileSize());
  72. left = min(left, (m_positionCount - position));
  73. coord = position2coord(position);
  74. } else {
  75. coord = upper();
  76. }
  77. return result;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement