title: How to map 8 directions to 1D array
body: <p>I have 8 cursors for 8 directions on screen.</p>
  
  <p><img src="https://i.stack.imgur.com/NUm7p.png" alt="directions on screen"></p>
  
  <p>I want to put them into array and chose them depending on direction vector. The order does not matter, but I need to assign <code>i</code> coordinate in 1D array for every vector seen above. I spend a long time trying to invent the formula for it, but nothing would work.</p>
  
  <p>The values in vector can be <code>0,1,-1</code>. </p>
  
  <p>Pseudo code:</p>
  
  <pre><code>Cursor getCursor(int x, int y) {
      int i = TheFunctionINeed(x,y);
      return cursors[i];
  }
  </code></pre>
  
  <p><strong>Note:</strong> Because so many guys were confused by what do I want, I used <a href="https://stackoverflow.com/a/26736622/607407">the answer</a> to make following fiddle: <a href="http://jsfiddle.net/qx63d03L/1/" rel="nofollow noreferrer">Mapping vectors to array.</a></p>