title: Java - Check if a rectangle "fits" into a 2 dimensional array (2d bin packing)
body: <p>So basically I want to create a method that takes a 2d array as 1 parameter and a rectangle's width and height as the other 2 parameters. The 2d array only contains binary numbers (0 - empty cell, 1 - taken cell). The method should return true if there is still enough place in the bin to hold the rectangle.</p>
  
  <p>My main problem is that i don't know how to iterate through the 2d array while checking if there is in fact a rectHeight*rectWidth sized empty space in the array.</p>
  
  <p>Right now i'm only checking if the 4 vertices are available, but that obviously isn't always enough.</p>
  
  <pre><code>for (int j = y; j &lt; y + rowHeight - rectHeight + 1; j++){
      for (int k = 0; k &lt; bin[j].length - rectWidth + 1; k++){
          if (bin[j][k] == 0 &amp;&amp; bin[j][k + rectWidth - 1] == 0 &amp;&amp; bin[j + rectHeight - 1][k] == 0 &amp;&amp; bin[j + rectHeight - 1][k + rectWidth - 1] == 0){
              isOne = true;
              for (int l = j; l &lt; j + rectHeight; l++){
                  for (int m = k; m &lt; k + rectWidth; m++){
                      bin[l][m] = not_positioned.get(i).getId();
                  }
              }
              not_positioned.remove(i);
          }
      }
  }
  </code></pre>