Small refactoring of the block-splitting routines

Also implemented https://bugs.launchpad.net/oq-engine/+bug/1333246.
The tests are green: https://ci2.openquake.org/job/zdevel_oq-commonlib/50/