- // ensure that the item is in range [0..count)
- if ( item < 0 )
- {
- // first map the item to the one in the same column but in the last row
- item += count;
-
- // now there are 2 cases: either it is the first item of the last row
- // in which case we need to wrap again and get to the last item or we
- // can just go to the previous item
- if ( item % (horz ? numCols : numRows) )
- item--;
- else
- item = count - 1;
- }
- else if ( item >= count )
- {
- // same logic as above
- item -= count;
-
- // ... except that we need to check if this is not the last item, not
- // the first one
- if ( (item + 1) % (horz ? numCols : numRows) )
- item++;
- else
- item = 0;
- }
+ // ensure that the item is in range [0..count)
+ if ( item < 0 )
+ {
+ // first map the item to the one in the same column but in the last
+ // row
+ item += count;
+
+ // now there are 2 cases: either it is the first item of the last
+ // row in which case we need to wrap again and get to the last item
+ // or we can just go to the previous item
+ if ( item % (horz ? numCols : numRows) )
+ item--;
+ else
+ item = count - 1;
+ }
+ else if ( item >= count )
+ {
+ // same logic as above
+ item -= count;
+
+ // ... except that we need to check if this is not the last item,
+ // not the first one
+ if ( (item + 1) % (horz ? numCols : numRows) )
+ item++;
+ else
+ item = 0;
+ }