bugfix for split free rect algorithm - based on the original c++-code by Jukka Jylänki