title: How do I rotate a single set of coordinates around an m x n matrix?
body: <p>I have a single coordinate, say <code>{ x: 1, y: 2 }</code> and a matrix size <code>{ x: 5, y: 6 }</code>.  I would like to rotate that single coordinate around the grid by 90 degrees (clockwise).  I can rotate an entire grid by running:</p>
  <pre class="lang-js prettyprint-override"><code>function rotate90(a){
    // transpose from http://www.codesuck.com/2012/02/transpose-javascript-array-in-one-line.html
    a = Object.keys(a[0]).map(function (c) { return a.map(function (r) { return r[c]; }); });
    // row reverse
    for (i in a){
      a[i] = a[i].reverse();
    }
    return a;
  }
  </code></pre>
  <p>Which takes a grid from:</p>
  <pre><code>[1][2][3][4]
  [5][6][7][8]
  [9][0][1][2]
  [3][4][5][6]
  </code></pre>
  <p>to</p>
  <pre><code>[3][9][5][1]
  [4][0][6][2]
  [5][1][7][3]
  [6][2][8][4]
  </code></pre>
  <p>How can I do the same with a single coordinate?  Some examples on a 4 x 4 grid might be:</p>
  <pre><code>0, 0 -&gt; 0, 3
  0, 3 -&gt; 3, 3
  3, 3 -&gt; 3, 0
  3, 0 -&gt; 0, 0
  
  1, 1 -&gt; 1, 2
  1, 2 -&gt; 2, 2
  2, 2 -&gt; 2, 1
  2, 1 -&gt; 1, 1
  </code></pre>