Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline position_t coord2position(Coordinates const& coord) const
- {
- assert(maped());
- assert(insideOverlap(coord));
- position_t position = 0;
- /* stride-major-order */
- for (size_t i = 0; i < n(); ++i) {
- position *= m_sizeOverlap[i];
- position += coord[i] - lowerOverlap()[i];
- }
- assert(position < m_positionCount);
- /*
- Temporary commented:
- (need another implementation of "aligned(Coordinates const&)".
- */
- /* assert(aligned(coord) == aligned(position)); */
- return position;
- }
- inline Coordinates position2coord(position_t const &position) const
- {
- assert(maped());
- assert(position < m_positionCount);
- Coordinates coord;
- coord.resize(n());
- position_t remainder= position;
- /* stride-major-order */
- for (Size i = n(); i > 0; --i) {
- Size const k = i - 1;
- coord[k] = lowerOverlap()[k] + (remainder % m_sizeOverlap[k]);
- remainder /= m_sizeOverlap[k];
- }
- assert(insideOverlap(coord));
- assert(aligned(coord) == aligned(position));
- return coord;
- }
- inline bool aligned(position_t const& actual) const
- {
- assert(maped());
- assert(actual < m_positionCount);
- if (isTiled()) {
- return actual % tileSize() == 0;
- } else {
- return true;
- }
- }
- inline bool move(Coordinates& coord,
- position_t step,
- position_t& left) const
- {
- assert(maped());
- assert(insideOverlap(coord));
- assert(step > 0);
- if (!isTiled() && step == 1) {
- size_t i = n() - 1;
- while(++coord[i] >= upper()[i]) {
- if (i == 0) {
- return false;
- }
- coord[i] = lower()[i];
- i -= 1;
- }
- left = 1;
- return true;
- } else {
- position_t position = coord2position(coord);
- position += step;
- bool result = position < m_positionCount;
- if (result) {
- left = tileSize() -
- (position % tileSize());
- left = min(left, (m_positionCount - position));
- coord = position2coord(position);
- } else {
- coord = upper();
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement