title: How do I convert a screen position into an array index?
body: <p>Suppose i have the following variables:</p>
  <ol>
  <li><code>int width;</code>: 1 - Integer.MAX_VALUE</li>
  <li><code>int size;</code>: 1 - width</li>
  <li><code>float x;</code>: 0.1f - width</li>
  <li><code>int[] cells = new int[size];</code></li>
  </ol>
  <p>Imagine that <code>width</code> is divided into equally sized cells of <code>width / size</code>.
  Now think that every index in <code>cells</code> is linked to one cell.
  My problem is that i cannot figure out what the index of the cell at <code>x</code> is.
  An Example:</p>
  <pre><code>    width = 300
       size =   3
  cell-size = 100
  
  indices:
      0:   0 - 100
      1: 100 - 200
      2: 200 - 300
  
      x = 250
  index =   2
  </code></pre>
  <pre><code>public static final int WIDTH = 900;
  public static final int  SIZE =   3;
  
  public static void main(String[] args) {
      int[] cells = new int[SIZE];
      float x = 447.0f;
      int index = getIndexAt(x);
      System.out.println(&quot;Index: &quot; + index + &quot;\nValue: &quot; + cells[index]);
  }
  
  public static int getIndexAt(float x) {
      return 0; // How do i get the index for x?
  }
  
  </code></pre>