Assuming we have array of R blocks as shown below:
------------------------------------
| R 00 | R 01 | R 02 | R 03 | R 04 |
------------------------------------
| R 10 | R 11 | R 12 | R 13 | R 14 |
------------------------------------
| R 20 | R 21 | R 22 | R 23 | R 24 |
------------------------------------
| R 30 | R 31 | R 32 | R 33 | R 34 |
------------------------------------
| R 40 | R 41 | R 42 | R 43 | R 44 |
------------------------------------
Since D blocks are overlapping, it's desired to identify them ambiguously with the least necessary information given.
Our function blockD() takes as an argument index of top-left R block and creates D block consisting of four R blocks. Meaning, for example:
------------------------------------ ------------------------------------ ------------------------------------
| | R 02 | R 03 | R 04 | | R 00 | R 01 | R 02 | R 03 | R 04 | | R 00 | R 01 | R 02 | R 03 | R 04 |
- D 00 ---------------------- ------------------------------------ ------------------------------------
| | R 12 | R 13 | R 14 | | R 10 | | R 13 | R 14 | | R 10 | R 11 | R 12 | R 13 | R 14 |
------------------------------------ -------- D 11 --------------- ------------------------------------
| R 20 | R 21 | R 22 | R 23 | R 24 | | R 20 | | R 23 | R 24 | | R 20 | R 21 | R 22 | R 23 | R 24 |
------------------------------------ ------------------------------------ ------------------------------------
| R 30 | R 31 | R 32 | R 33 | R 34 | | R 30 | R 31 | R 32 | R 33 | R 34 | | R 30 | R 31 | | R 34
------------------------------------ ------------------------------------ --------------- D 32 --------
| R 40 | R 41 | R 42 | R 43 | R 44 | | R 40 | R 41 | R 42 | R 43 | R 44 | | R 40 | R 41 | | R 44 |
------------------------------------ ------------------------------------ ------------------------------------
and so on.
That means that highest index can be (width-2,height-2)