Fixed rectangle to segment direction algorithm