Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficient way to manage item positions in grid after rotation/flip in iOS
    primarykey
    data
    text
    <p>I am looking for some guidance on the most efficient way to design a class to manage the position of 3 items in a 6x6 grid. The items on the grid cannot move/change their position, however, the entire grid can be rotated in 90-degree increments clockwise/counter clockwise and can be flipped horizontally/vertically based on user touch/drag manipulations of the grid in realtime on iOS devices. As a result of rotating and/or flipping the entire grid, the 3 items in the grid will be in different “absolute” positions based on a non-rotated “position reference” grid. It is these new item positions I am trying to determine in the most efficient manner after each “transform” of the grid.</p> <p>To illustrate what I am trying to accomplish, consider the following... I am numbering the positions in the grid where the upper-left corner is position 0 and numbers increment to the right then down:</p> <p>Position Reference Grid:</p> <pre><code>------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | ------------------------- | 6 | 7 | 8 | 9 | 10| 11| ------------------------- | 12| 13| 14| 15| 16| 17| ------------------------- | 18| 19| 20| 21| 22| 23| ------------------------- | 24| 25| 26| 27| 28| 29| ------------------------- | 30| 31| 32| 33| 34| 35| ------------------------- </code></pre> <p>I am planning to always refer to an item's position in the grid using this numbering regardless of any rotation/flip transform applied to the grid. So, for example, if I have items in positions A=7, B=9, C=14 </p> <p>Original:</p> <pre><code>------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | ------------------------- | 6 | A | 8 | B | 10| 11| ------------------------- | 12| 13| C | 15| 16| 17| ------------------------- | 18| 19| 20| 21| 22| 23| ------------------------- | 24| 25| 26| 27| 28| 29| ------------------------- | 30| 31| 32| 33| 34| 35| ------------------------- </code></pre> <p>and rotate the grid 90 degrees clockwise, the new item positions will be A=10, B=22, C=15. </p> <p>Rotated Clockwise 90 degrees:</p> <pre><code>------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | ------------------------- | 6 | 7 | 8 | 9 | A | 11| ------------------------- | 12| 13| 14| C | 16| 17| ------------------------- | 18| 19| 20| 21| B | 23| ------------------------- | 24| 25| 26| 27| 28| 29| ------------------------- | 30| 31| 32| 33| 34| 35| ------------------------- </code></pre> <p>There are just 8 possible orientations of the grid (0, 90, 180, 270 degrees on each side), so each item has exactly 8 known positions based on the orientation of the grid. As such, I could hard-code 8, 3-item arrays containing the absolute positions of the 3 items for each of the 8 orientations – one array per orientation. Once I know what orientation the grid is in after some transform, I can simply grab the correct 3-item array of item positions that corresponds to the grid orientation to get the new positions of the 3 items. </p> <p>Since I need to do this position retrieval for several grids at a time, since the grid transforms are in direct response to touch manipulations on iOS, and since there may be more items in the grids, I am wondering if such hard-coding is the way to go or if there is some more elaborate way to calculate or otherwise dynamically determine the position of the items in the grid once a rotation or flip of the grid has occurred.</p> <p>Any advice, comments, suggestions are greatly appreciated.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload