while ( @points ) { if (($points[0][0]-$modified[-1][0])/($points[0][1]-$modified[-1][1]) > 0) { push @modified, shift @points; } else { # Retrograde! my @retro = (pop @modified, shift @points); push @retro, shift @points while ($retro[-1][0]-$points[0][0])/($retro[-1][1]-$points[0][1]) < 0; shift @points while ($retro[0][0]-$points[0][0])/($retro[0][1]-$points[0][1]) < 0; pop @modified while ($retro[-1][0]-$modified[-1][0])/($retro[-1][1]-$modified[-1][1]) < 0; push @modified, [0.5*($retro[@retro/2-.5][0] + $retro[@retro/2][0]), 0.5*($retro[@retro/2-.5][1] + $retro[@retro/2][1]), ] } }