Merge "Improve rectangle direction generation"