title: 3D array (1D flat) indexing
body: <p>I am using a coordinate system x (width), y (height), z (Depth)</p>
  
  <p>Just to clear confusion if there is any x &amp; y are a flat plane and I am using Z as elevation.</p>
  
  <p>I am going to be accessing the array millions of times per second and benchmarking shows that a 1D array using index is faster and I would like to squeeze as much efficiency as possible so that other things can use that time</p>
  
  <p>For example a 2D array --> 1D array creation is just </p>
  
  <pre><code>Object[] oneDArray = new Object[width * height]
  </code></pre>
  
  <p>and to index the array I can just use the following.</p>
  
  <pre><code>Object obj = oneDArray[x + y * width]
  </code></pre>
  
  <p>I did find the following on stackoverflow but I am not entirely sure which one is correct
  <a href="https://stackoverflow.com/questions/7367770/how-to-flatten-or-index-3d-array-in-1d-array">How to &quot;flatten&quot; or &quot;index&quot; 3D-array in 1D array?</a></p>
  
  <p>The "Correct" answer says to index the array do the following</p>
  
  <pre><code>Object[] oneDArray = new Object[width * height * depth]
  Object obj = oneDArray[x + WIDTH * (y + DEPTH * z)]
  </code></pre>
  
  <p>But then another answer says that the "Correct" answer is wrong and uses the following </p>
  
  <pre><code>Object[] oneDArray = new Object[width * height * depth]
  Object obj = oneDArray[x + HEIGHT* (y + WIDTH* z)]
  </code></pre>
  
  <p>What is the correct way to read a flattened 3D array?</p>