glass cutting algorithm